Skip to content

Commit

Permalink
Merge pull request #1842 from rubocop/add-test2
Browse files Browse the repository at this point in the history
Add test to ensure unsafe cops are properly configured
  • Loading branch information
ydah committed Mar 29, 2024
2 parents f6314a7 + bf3f3e5 commit 85e6c8f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/project/default_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

0 comments on commit 85e6c8f

Please sign in to comment.