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

Can't ignore Rails/EnvironmentVariableAccess cop #7

Closed
knutsenm opened this issue May 24, 2023 · 12 comments
Closed

Can't ignore Rails/EnvironmentVariableAccess cop #7

knutsenm opened this issue May 24, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@knutsenm
Copy link

standardrb --generate-todo does create Rails exclusions; example:

% ack -A2 lib/log/logger.rb .standard_todo.yml
- lib/log/logger.rb:
  - Style/GlobalStdStream
  - Rails/EnvironmentVariableAccess

However, despite this:

% standardrb --format simple
[ ... ]
== lib/log/logger.rb ==
C: 15: 10: Rails/EnvironmentVariableAccess: Do not read from ENV directly post initialization.
C: 16: 36: Rails/EnvironmentVariableAccess: Do not read from ENV directly post initialization.
@searls
Copy link
Contributor

searls commented May 24, 2023

This is probably a legit bug as I've never used this feature or really understand how it's implemented

@searls searls added the bug Something isn't working label May 24, 2023
@knutsenm
Copy link
Author

OK, could @mrbiggred possibly help?

@knutsenm
Copy link
Author

Hmm, it's not a todo thing. I have the same problem even after I move the lines to .standard.yml:

+++ b/.standard.yml
@@ -2,3 +2,6 @@ plugins:
   - standard-rails
 ignore:
   - 'db/migrate/*'
+  - 'lib/log/logger.rb':
+    - Style/GlobalStdStream
+    - Rails/EnvironmentVariableAccess

@knutsenm
Copy link
Author

The Style/GlobalStdStream ignore in my .standard.yml example above does work (tested by removing it), it's only the Rails cop that's not ignored.

@knutsenm knutsenm changed the title standard-rails doesn't honor .standard_todo.yml Can't ignore Rails/EnvironmentVariableAccess cop May 24, 2023
@knutsenm
Copy link
Author

The problem is even more specific: I can't ignore the Rails/EnvironmentVariableAccess cop. Other Rails cops can be ignored from either file. I changed the subject accordingly.

@searls
Copy link
Contributor

searls commented May 24, 2023

Thanks for narrowing your report. Unfortunately I was unable to replicate your issue in this commit, which adds a test of an ignore

standardrb/standard@c741249

Note that the nested ignore here is two levels of indentation deep (one more than you might expect) so that the YAML parses it as a nested map and not a subsequent element in an array:

ignore:
  - '**/*.rb':
      - Bananas/BananaBomb

Your example was this:

- lib/log/logger.rb:
  - Style/GlobalStdStream
  - Rails/EnvironmentVariableAccess

Does this work?

- lib/log/logger.rb:
    - Style/GlobalStdStream
    - Rails/EnvironmentVariableAccess

@knutsenm
Copy link
Author

Note that the nested ignore here is two levels of indentation deep

I'm sorry to report that doesn't help in my case.

I'm baffled why this one particular cop can't be ignored. I'm trying to convert a private repo from rubocop to standard, and have removed old .rubocop.yml and .rubocop_todo.yml files. Rails/EnvironmentVariableAccess is disabled by default in rubocop-rails, and so the old config and code didn't have to ignore it.

I do note that I can successfully rubocop:disable or standard:disable it in code comments, so that's something.

@mrbiggred
Copy link

@knutsenm I'm not sure why the Rails cops aren't being ignored. I haven't used this new Standard Rails plugin. I'll play around with it and if I find anything I'll post an update.

@knutsenm do you have an example project that show cases the issue?

@knutsenm
Copy link
Author

knutsenm commented May 25, 2023

@knutsenm do you have an example project that show cases the issue?

Yes, see CruGlobal/rails-infrastructure-canary#99

The Ruby/lint Action fails the same way it does for me locally,

== lib/log/logger.rb ==
C: 15: 10: Rails/EnvironmentVariableAccess: Do not read from ENV directly post initialization.
C: 16: 36: Rails/EnvironmentVariableAccess: Do not read from ENV directly post initialization.

searls added a commit to standardrb/standard that referenced this issue May 26, 2023
@searls
Copy link
Contributor

searls commented May 26, 2023

I figured this out and it was not fun. See standardrb/standard@ed4253a for a description

Released a fix in standard@1.28.4

@mrbiggred
Copy link

Glad you figured it out @searls.

@WMahoney09
Copy link

I'm unable ignore this rule, I'm on Standard version: 1.36.0

plugins:
  - standard-rails
ignore:
  - 'Rails/EnvironmentVariableAccess'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants