From bf3f3e51629acb75ecb333e11f1d3fb77868a4bf Mon Sep 17 00:00:00 2001 From: ydah Date: Tue, 26 Mar 2024 19:05:25 +0900 Subject: [PATCH] Add test to ensure unsafe cops are properly configured Follow up: https://github.com/rubocop/rubocop/commit/7cda5aedc5ccf24ce53bccdb258a9e4dbac3ec16 --- spec/project/default_config_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/project/default_config_spec.rb b/spec/project/default_config_spec.rb index 7b02deb72..93b5d128c 100644 --- a/spec/project/default_config_spec.rb +++ b/spec/project/default_config_spec.rb @@ -32,6 +32,22 @@ cop_names + namespaces.values end + let(:unsafe_cops) do + require 'yard' + YARD::Registry.load! + YARD::Registry.all(:class).select do |example| + example.tags.any? { |tag| tag.tag_name == 'safety' } + end + end + + let(:unsafe_cop_names) do + unsafe_cops.map do |cop| + dept_and_cop_names = + cop.path.split('::')[2..] # Drop `RuboCop::Cop` from class name. + dept_and_cop_names.join('/') + end + end + def cop_configuration(config_key) cop_names.map do |cop_name| cop_config = default_config[cop_name] @@ -94,4 +110,17 @@ def cop_configuration(config_key) ) end end + + it 'is expected that all cops documented with `@safety` are `Safe: false`' \ + ' or `SafeAutoCorrect: false`' do + unsafe_cop_names.each do |cop_name| + unsafe = default_config[cop_name]['Safe'] == false || + default_config[cop_name]['SafeAutoCorrect'] == false + expect(unsafe).to( + be(true), + "`#{cop_name}` cop should be set `Safe: false` or " \ + '`SafeAutoCorrect: false` because `@safety` YARD tag exists.' + ) + end + end end