Skip to content

Commit

Permalink
Add a project spec to detect settings that haven't set unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed May 14, 2023
1 parent ac57a77 commit 4e7233d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@
end
end

it 'is expected that all cops documented with `@safety` are `Safe: false` or `SafeAutoCorrect: false`' do
require 'yard'

YARD::Registry.load!

unsafe_cops = YARD::Registry.all(:class).select do |example|
example.tags.any? { |tag| tag.tag_name == 'safety' }
end

unsafe_cop_names = unsafe_cops.map do |cop|
department_and_cop_names = cop.path.split('::')[2..] # Drop `RuboCop::Cop` from class name.

department_and_cop_names.join('/')
end

unsafe_cop_names.each do |cop_name|
cop_config = config[cop_name]
unsafe = cop_config['Safe'] == false || cop_config['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

it 'sorts cop names alphabetically' do
previous_key = ''
config_default = YAML.load_file('config/default.yml')
Expand Down

0 comments on commit 4e7233d

Please sign in to comment.