Checks that application code doesn't rely on env variables or env name.
Application code should not know about the magical environment and should rely on the explicit configuration instead.
- Copy
lint_env.rb
tolib/rubocop/cop/lint_env.rb
- (optionally) Copy
lint_env_spec.rb
tospec/lib/rubocop/cop/lint_env_spec.rb
(if you want to make and test changes) - Add the following to your
.rubocop.yml
:
require:
- ./lib/rubocop/cop/lint_env
Lint/Env:
Enabled: true
Include:
- '**/*.rb'
Exclude:
- '**/config/environments/**/*'
- '**/config/application.rb'
- '**/config/environment.rb'
- '**/config/puma.rb'
- '**/config/boot.rb'
- '**/spec/*_helper.rb'
- '**/spec/**/support/**/*'
- 'lib/generators/**/*'
- Run RuboCop.
You can allow some ENV
keys (or all of them) by configuring AllowEnv
option:
Lint/Env:
# ...
# allow specified keys
AllowedEnv:
- DEBUG
# or allow all ENV calls
AllowedEnv: all