Skip to content

Commit

Permalink
[Fix rubocop#10135] Fix Style/WordArray to exclude files in `--auto…
Browse files Browse the repository at this point in the history
…-gen-config` when `percent` style is given but brackets are required.
  • Loading branch information
dvandersluis committed Sep 29, 2021
1 parent 3a694f6 commit ff09a4c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -144,3 +144,7 @@ InternalAffairs/UndefinedConfig:
Exclude:
- 'lib/rubocop/cop/correctors/**/*.rb'
- 'lib/rubocop/cop/mixin/**/*.rb'

InternalAffairs/StyleDetectedApiUse:
Exclude:
- 'lib/rubocop/cop/mixin/percent_array.rb'
1 change: 1 addition & 0 deletions changelog/fix_fix_stylewordarray_to_exclude_files_in.md
@@ -0,0 +1 @@
* [#10135](https://github.com/rubocop/rubocop/issues/10135): Fix `Style/WordArray` to exclude files in `--auto-gen-config` when `percent` style is given but brackets are required. ([@dvandersluis][])
7 changes: 6 additions & 1 deletion lib/rubocop/cop/mixin/percent_array.rb
Expand Up @@ -36,7 +36,12 @@ def comments_in_array?(node)
def check_percent_array(node)
array_style_detected(:percent, node.values.size)

return unless style == :brackets || invalid_percent_array_contents?(node)
brackets_required = invalid_percent_array_contents?(node)
return unless style == :brackets || brackets_required

# If in percent style but brackets are required due to
# string content, the file should be excluded in auto-gen-config
no_acceptable_style! if brackets_required

bracketed_array = build_bracketed_array(node)
message = format(self.class::ARRAY_MSG, prefer: bracketed_array)
Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/cop/style/word_array_spec.rb
Expand Up @@ -327,6 +327,8 @@
expect_correction(<<~RUBY)
['one two', 'three four']
RUBY

expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
end

it 'does not register an offense for a %w() array containing non word characters' do
Expand Down

0 comments on commit ff09a4c

Please sign in to comment.