|
27 | 27 | cop_names + namespaces.values
|
28 | 28 | end
|
29 | 29 |
|
| 30 | + let(:unsafe_cops) do |
| 31 | + require 'yard' |
| 32 | + YARD::Registry.load! |
| 33 | + YARD::Registry.all(:class).select do |example| |
| 34 | + example.tags.any? { |tag| tag.tag_name == 'safety' } |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + let(:unsafe_cop_names) do |
| 39 | + unsafe_cops.map do |cop| |
| 40 | + dept_and_cop_names = |
| 41 | + cop.path.split('::')[2..] # Drop `RuboCop::Cop` from class name. |
| 42 | + dept_and_cop_names.join('/') |
| 43 | + end |
| 44 | + end |
| 45 | + |
30 | 46 | def cop_configuration(config_key)
|
31 | 47 | cop_names.map do |cop_name|
|
32 | 48 | cop_config = default_config[cop_name]
|
@@ -76,4 +92,31 @@ def cop_configuration(config_key)
|
76 | 92 | expect(cop_configuration('Enabled'))
|
77 | 93 | .to all be(true).or(be(false)).or(eq('pending'))
|
78 | 94 | end
|
| 95 | + |
| 96 | + it 'does not include unnecessary `SafeAutoCorrect: false`' do |
| 97 | + cop_names.each do |cop_name| |
| 98 | + next unless default_config.dig(cop_name, 'Safe') == false |
| 99 | + |
| 100 | + safe_autocorrect = default_config.dig(cop_name, 'SafeAutoCorrect') |
| 101 | + |
| 102 | + expect(safe_autocorrect).not_to( |
| 103 | + be(false), |
| 104 | + "`#{cop_name}` has unnecessary `SafeAutoCorrect: false` config." |
| 105 | + ) |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + it 'is expected that all cops documented with `@safety` are `Safe: false`' \ |
| 110 | + ' or `SafeAutoCorrect: false`' do |
| 111 | + unsafe_cop_names.each do |cop_name| |
| 112 | + unsafe = default_config[cop_name]['Safe'] == false || |
| 113 | + default_config[cop_name]['SafeAutoCorrect'] == false |
| 114 | + expect(unsafe).to( |
| 115 | + be(true), |
| 116 | + "`#{cop_name}` cop should be set `Safe: false` or " \ |
| 117 | + '`SafeAutoCorrect: false` because `@safety` YARD tag exists.' |
| 118 | + ) |
| 119 | + YARD::Registry.clear |
| 120 | + end |
| 121 | + end |
79 | 122 | end
|
0 commit comments