Sha256: 4ead4da570718a19e6d8cdd12ca25fd04b7429b16c94e37060991b166438ab5d
Contents?: true
Size: 1.26 KB
Versions: 14
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Rails # Checks for usage of `Rails.env.development? || Rails.env.test?` which # can be replaced with `Rails.env.local?`, introduced in Rails 7.1. # # @example # # # bad # Rails.env.development? || Rails.env.test? # # # good # Rails.env.local? # class EnvLocal < Base extend AutoCorrector extend TargetRailsVersion MSG = 'Use `Rails.env.local?` instead.' LOCAL_ENVIRONMENTS = %i[development? test?].to_set.freeze minimum_target_rails_version 7.1 # @!method rails_env_local_candidate?(node) def_node_matcher :rails_env_local_candidate?, <<~PATTERN (or (send (send (const {cbase nil? } :Rails) :env) $%LOCAL_ENVIRONMENTS) (send (send (const {cbase nil? } :Rails) :env) $%LOCAL_ENVIRONMENTS) ) PATTERN def on_or(node) rails_env_local_candidate?(node) do |*environments| next unless environments.to_set == LOCAL_ENVIRONMENTS add_offense(node) do |corrector| corrector.replace(node, 'Rails.env.local?') end end end end end end end
Version data entries
14 entries across 14 versions & 4 rubygems