Skip to content

Latest commit

 

History

History

lint_env

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Lint/Env cop

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.

Usage

  • Copy lint_env.rb to lib/rubocop/cop/lint_env.rb
  • (optionally) Copy lint_env_spec.rb to spec/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.

Configuration

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