File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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' )
You can’t perform that action at this time.
0 commit comments