Skip to content

Commit 4e7233d

Browse files
committed
Add a project spec to detect settings that haven't set unsafe
Follow up rubocop/rubocop#11871
1 parent ac57a77 commit 4e7233d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

spec/project_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,33 @@
101101
end
102102
end
103103

104+
it 'is expected that all cops documented with `@safety` are `Safe: false` or `SafeAutoCorrect: false`' do
105+
require 'yard'
106+
107+
YARD::Registry.load!
108+
109+
unsafe_cops = YARD::Registry.all(:class).select do |example|
110+
example.tags.any? { |tag| tag.tag_name == 'safety' }
111+
end
112+
113+
unsafe_cop_names = unsafe_cops.map do |cop|
114+
department_and_cop_names = cop.path.split('::')[2..] # Drop `RuboCop::Cop` from class name.
115+
116+
department_and_cop_names.join('/')
117+
end
118+
119+
unsafe_cop_names.each do |cop_name|
120+
cop_config = config[cop_name]
121+
unsafe = cop_config['Safe'] == false || cop_config['SafeAutoCorrect'] == false
122+
123+
expect(unsafe).to(
124+
be(true),
125+
"`#{cop_name}` cop should be set `Safe: false` or `SafeAutoCorrect: false` " \
126+
'because `@safety` YARD tag exists.'
127+
)
128+
end
129+
end
130+
104131
it 'sorts cop names alphabetically' do
105132
previous_key = ''
106133
config_default = YAML.load_file('config/default.yml')

0 commit comments

Comments
 (0)