You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The general problem here is that rubocop is using different configuration for a single file depending on how it's run, and that configuration is wrong. I haven't completely nailed down everything that's affected, but it's at least a fairly simple repro.
subdir/test2.rb (I'm not sure if this file is necessary in order for rubocop to process the configuration file in its directory):
# frozen_string_literal: trueputs'hi'
Expected behavior
I would expect that rubocop will find an offense of Rails/WhereEquals regardless of where it's run. I.e. rubocop, rubocop -A, rubocop -- test.rb, rubocop -A -- test.rb should find a single offense each time.
Actual behavior
If I run rubocop or rubocop -A, no offenses are found in either file (WRONG!). But if I run rubocop -- test.rb, the offense is found (RIGHT!). My supposition is that there's a bug in the inheritance mechanism that because the entire Rails department is disabled in the sub-directory that state leaks to the parent directory's copy of the configuration. But if you're running justtest.rb, the sub-directory's config is never loaded, not having a chance to corrupt the parent. I have reason to believe it's not as simple as that, though. In my full app, the only cops that seems to "regress" with this sort of configuration were all cops that are marked as pending. So it might be that Enabled is getting reset incorrectly somewhere. I'm also not sure if being a separate gem (rubocop-rails) is important at all - that just happened to be the department that I encountered this with.
The general problem here is that rubocop is using different configuration for a single file depending on how it's run, and that configuration is wrong. I haven't completely nailed down everything that's affected, but it's at least a fairly simple repro.
Given the following four files:
.rubocop.yml
:subdir/.rubocop.yml
:test.rb
:subdir/test2.rb
(I'm not sure if this file is necessary in order for rubocop to process the configuration file in its directory):Expected behavior
I would expect that rubocop will find an offense of
Rails/WhereEquals
regardless of where it's run. I.e.rubocop
,rubocop -A
,rubocop -- test.rb
,rubocop -A -- test.rb
should find a single offense each time.Actual behavior
If I run
rubocop
orrubocop -A
, no offenses are found in either file (WRONG!). But if I runrubocop -- test.rb
, the offense is found (RIGHT!). My supposition is that there's a bug in the inheritance mechanism that because the entire Rails department is disabled in the sub-directory that state leaks to the parent directory's copy of the configuration. But if you're running justtest.rb
, the sub-directory's config is never loaded, not having a chance to corrupt the parent. I have reason to believe it's not as simple as that, though. In my full app, the only cops that seems to "regress" with this sort of configuration were all cops that are marked as pending. So it might be that Enabled is getting reset incorrectly somewhere. I'm also not sure if being a separate gem (rubocop-rails) is important at all - that just happened to be the department that I encountered this with.RuboCop version
The text was updated successfully, but these errors were encountered: