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

Style/SpecialGlobalVars auto-gen-config behaviour change #2556

Closed
madwort opened this issue Dec 30, 2015 · 13 comments
Closed

Style/SpecialGlobalVars auto-gen-config behaviour change #2556

madwort opened this issue Dec 30, 2015 · 13 comments

Comments

@madwort
Copy link
Contributor

madwort commented Dec 30, 2015

In the process of tidying up an old codebase, have fixed some instances of Style/SpecialGlobalVars offenses but have more that I want to ignore with --auto-gen-config. v0.35.1 put this in ~/.rubocop_todo.yml:

Style/SpecialGlobalVars:
  Exclude:
    - 'filename.rb' # file with offenses in

as of git version 1716abb rubocop creates this instead:

Style/SpecialGlobalVars:
  EnforcedStyle: use_perl_names

which means that when I run rubocop I get alerted to the files that I've already fixed the offense in & breaks my incremental improvement workflow.

@madwort madwort changed the title Style/SpecialGlobalVars auto-gen-config behaviour error Style/SpecialGlobalVars auto-gen-config behaviour change Dec 30, 2015
@alexdowad
Copy link
Contributor

Does it make a difference if you delete the .rubocop_todo.yml file before regenerating it?

@madwort
Copy link
Contributor Author

madwort commented Dec 30, 2015

no, deleting .rubocop_todo.yml doesn't make a difference.

Now that I test it a bit more I realise that I'm having this issue with several cops so maybe there's something else going on (my expected workflow is to run auto-gen-config to allow me to ignore all cops, then selectively enable & fix). The other cops are:

  • Style/WordArray
  • Style/GuardClause
  • Style/ConditionalAssignment

@madwort
Copy link
Contributor Author

madwort commented Dec 30, 2015

Style/WordArray may have changed its configuration in a similar way to Style/SpecialGlobalVars by adding EnforcedStyle: percent, but the other two are still only producing Exclude: filename.rb directives in the TODO file.

@alexdowad
Copy link
Contributor

All those cops have changed recently.

@alexdowad
Copy link
Contributor

Can you give a standalone file which I can run rubocop --auto-gen-config on to reproduce this?

@madwort
Copy link
Contributor Author

madwort commented Dec 30, 2015

ok, for Style/SpecialGlobalVars create this simple file:

echo $ERROR_INFO
echo $!
  • run rubocop; line 2 fails
  • run --auto-gen-config then run rubocop, line 1 fails
  • expected behaviour: run --auto-gen-config, run rubocop, file passes.

@alexdowad
Copy link
Contributor

Awesome, with repro this should be easy to debug.

@alexdowad
Copy link
Contributor

I have a fix for this. Do you have a sample showing the same problem with WordArray, etc.?

@madwort
Copy link
Contributor Author

madwort commented Dec 30, 2015

Just been trying to get a good sample for GuardClause but put in its own thread, maybe it should be here? #2557

@jonas054
Copy link
Collaborator

No, it's better to keep it in a separate issue. I've answered there and I think it's not the same problem.

@madwort
Copy link
Contributor Author

madwort commented Dec 31, 2015

Fixed for the test case, but still broken for a different test case (sorry!):

test_varnames1.rb: $!
test_varnames2.rb: $ERROR_INFO

$ bundle exec rubocop  test_varnames1.rb test_varnames2.rb --auto-gen-config ; bundle exec rubocop test_varnames1.rb test_varnames2.rb 
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.4-compliant syntax, but you are running 2.2.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Inspecting 2 files
C.

Offenses:

test_varnames1.rb:1:1: C: Prefer $ERROR_INFO from the stdlib 'English' module over $!.
$!
^^

2 files inspected, 1 offense detected
Created .rubocop_todo.yml.
Run `rubocop --config .rubocop_todo.yml`, or add `inherit_from: .rubocop_todo.yml` in a .rubocop.yml file.
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.4-compliant syntax, but you are running 2.2.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Inspecting 2 files
C.

Offenses:

test_varnames1.rb:1:1: C: Prefer $ERROR_INFO from the stdlib 'English' module over $!.
$!
^^

2 files inspected, 1 offense detected

$ cat .rubocop_todo.yml 
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-12-31 12:02:32 +0000 using RuboCop version 0.35.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
  EnforcedStyle: use_english_names

tested with bc3e40a

@alexdowad
Copy link
Contributor

I caused that bug in 5673c6f. Looking for the best way to fix it.

@alexdowad
Copy link
Contributor

My open PR has a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants