Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol Arrays with spaces are not excluded by --auto-gen-config #10135

Closed
Skipants opened this issue Sep 28, 2021 · 0 comments · Fixed by #10138
Closed

Symbol Arrays with spaces are not excluded by --auto-gen-config #10135

Skipants opened this issue Sep 28, 2021 · 0 comments · Fixed by #10138
Labels

Comments

@Skipants
Copy link

If you run rubocop --auto-gen-config against a codebase that contains a symbol array with spaces, eg.:

%w[Paris Sydney New\ York]

the offense is not added to rubocop_todo.yml . Subsequent rubocop runs will always have an offense on this array.

Expected behavior

The file containing the array should be excluded under the Style/WordArray cop in rubocop_todo.yml

Actual behavior

The file is not excluded.

Steps to reproduce the problem

This can be reproduced with this spec:

diff --git a/spec/rubocop/cli/auto_gen_config_spec.rb b/spec/rubocop/cli/auto_gen_config_spec.rb
index 0691669b4..240a0bfa2 100644
--- a/spec/rubocop/cli/auto_gen_config_spec.rb
+++ b/spec/rubocop/cli/auto_gen_config_spec.rb
@@ -300,6 +300,31 @@ RSpec.describe 'RuboCop::CLI --auto-gen-config', :isolated_environment do # rubo
       end
     end
 
+    it 'excludes the complex array when the style is mixed for Style/WordArray' do
+      create_file(
+        'example1.rb',
+        [
+          '# frozen_string_literal: true',
+          '',
+          '%w[France Australia USA] +',
+          '  %w[Paris Sydney New\ York]'
+        ]
+      )
+
+      expect(cli.run(['--auto-gen-config'])).to eq(0)
+      expect(File.readlines('.rubocop_todo.yml')[8..-1].join)
+        .to eq(<<~YAML)
+          # Offense count: 1
+          # Cop supports --auto-correct.
+          # Configuration parameters: MinSize, WordRegex.
+          # SupportedStyles: percent, brackets
+          Style/WordArray:
+            EnforcedStyle: percent
+            Exclude:
+              - example1.rb
+        YAML
+    end
+
     it 'overwrites an existing todo file' do
       create_file('example1.rb', ['# frozen_string_literal: true',
                                   '',

The spec should pass, but instead it fails with the diff showing that the following is missing:

-            Exclude:
-              - example1.rb

RuboCop version

Issue was encountered in app with the following version:

➜  finbot (dependabot/bundler/rubocop-1.21.0) ✗ be rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 2.5.7 x86_64-darwin19)

Spec was run against rubocop/master. HEAD at the time was 8b5d234.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 29, 2021
…-gen-config` when `percent` style is given but brackets are required.
bbatsov pushed a commit that referenced this issue Sep 29, 2021
…nfig` when `percent` style is given but brackets are required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants