Rubocop: Support custom environment names for Rails/UnknownEnv

Created on 29 Oct 2017  路  3Comments  路  Source: rubocop-hq/rubocop

It would be great if the Rails/UnknownEnv cop allowed for configuration for custom environment names that are acceptable for the application. For example, my application supports a "performance" Rails env, thus a call to the method Rails.env.performance? should be expected.

I envision this custom configuration being a YAML array of strings.

Expected behavior

Rubocop will not fail because there was custom configuration for the Rails/UnknownEnv cop that included the environment "performance" as a supported environment name.

Actual behavior

Rubocop fails due to the Rails/UnknownEnv cop disallowing code that calls Rails.env.performance?.

Steps to reproduce the problem

Run rubocop on a file that includes the code Rails.env.performance?.

RuboCop version

0.51.0 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin16)

Most helpful comment

http://rubocop.readthedocs.io/en/latest/cops_rails/#railsunknownenv
You can configure custom environments with .rubocop.yml.
For example:

Rails/UnknownEnv:
  Environments:
    - production
    - development
    - test
    - performance

Take care the default environments are also needed.

All 3 comments

http://rubocop.readthedocs.io/en/latest/cops_rails/#railsunknownenv
You can configure custom environments with .rubocop.yml.
For example:

Rails/UnknownEnv:
  Environments:
    - production
    - development
    - test
    - performance

Take care the default environments are also needed.

This doesn't make sense! We already have a folder on config with all environments that the application has, why not use it to know what are the envs of the app?

Probably the same reason Rubocop can't look at your code and assume that that's the way you intended to write it. If you create a config/environments/wibble.rb one can argue that you still should tell Rubocop that you _meant_ to stray away from standard practice.

Was this page helpful?
0 / 5 - 0 ratings