Skip to content

Commit 297c26e

Browse files
committed
Add a project spec to detect settings that haven't set unsafe
Follow up rubocop/rubocop#11871
1 parent 24ff064 commit 297c26e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

spec/project_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@
103103
end
104104
end
105105

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

0 commit comments

Comments
 (0)