Sha256: c038f3694f4f9532746cff42a9e841578dc766b333e263eaded708d469a9bba7

Contents?: true

Size: 1.31 KB

Versions: 30

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Ezcater
      # Use the `Rails.configuration.x` namespace for configuration backed by
      # environment variables, rather than inspecting `ENV` directly.
      #
      # Restricting environment variables references to be within application
      # configuration makes it more obvious which env vars an application relies
      # upon. See https://ezcater.atlassian.net/wiki/x/ZIChNg.
      #
      # @example
      #
      #   # good
      #   enforce_foo! if Rails.configuration.x.foo_enforced
      #
      #   # bad
      #   enforce_foo! if ENV["FOO_ENFORCED"] == "true"
      #
      class DirectEnvCheck < Cop
        MSG = <<~END_MESSAGE.split("\n").join(" ")
          Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `ENV`. Restricting
          environment variables references to be within application configuration makes it more obvious which env vars
          an application relies upon. https://ezcater.atlassian.net/wiki/x/ZIChNg
        END_MESSAGE

        def_node_matcher "env_ref", <<-PATTERN
          (const _ :ENV)
        PATTERN

        def on_const(node)
          env_ref(node) do
            add_offense(node, location: :expression, message: MSG)
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ezcater_rubocop-7.0.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.1.1 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.1.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.0.3 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.0.2 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.0.1 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-6.0.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-5.2.1 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-5.2.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-2.5.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-5.1.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-5.0.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-4.0.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-3.0.2 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-3.0.1 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-3.0.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-2.4.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-2.3.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-2.2.0 lib/rubocop/cop/ezcater/direct_env_check.rb
ezcater_rubocop-2.1.0 lib/rubocop/cop/ezcater/direct_env_check.rb