Sha256: 03b5d1716e6348904667c780e474fda300cc0e15aad0d10f5575cbab034f5b6e

Contents?: true

Size: 1.81 KB

Versions: 39

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that memoized helper names use the configured style.
      #
      # Variables can be excluded from checking using the `AllowedPatterns`
      # option.
      #
      # @example EnforcedStyle: snake_case (default)
      #   # bad
      #   subject(:userName1) { 'Adam' }
      #   let(:userName2) { 'Adam' }
      #
      #   # good
      #   subject(:user_name_1) { 'Adam' }
      #   let(:user_name_2) { 'Adam' }
      #
      # @example EnforcedStyle: camelCase
      #   # bad
      #   subject(:user_name_1) { 'Adam' }
      #   let(:user_name_2) { 'Adam' }
      #
      #   # good
      #   subject(:userName1) { 'Adam' }
      #   let(:userName2) { 'Adam' }
      #
      # @example AllowedPatterns configuration
      #   # rubocop.yml
      #   # RSpec/VariableName:
      #   #   EnforcedStyle: snake_case
      #   #   AllowedPatterns:
      #   #     - ^userFood
      #
      # @example
      #   # okay because it matches the `^userFood` regex in `AllowedPatterns`
      #   subject(:userFood_1) { 'spaghetti' }
      #   let(:userFood_2) { 'fettuccine' }
      #
      class VariableName < Base
        include ConfigurableNaming
        include AllowedPattern
        include Variable
        include InsideExampleGroup

        MSG = 'Use %<style>s for variable names.'

        def on_send(node)
          return unless inside_example_group?(node)

          variable_definition?(node) do |variable|
            return if variable.dstr_type? || variable.dsym_type?
            return if matches_allowed_pattern?(variable.value)

            check_name(node, variable.value, variable.source_range)
          end
        end

        private

        def message(style)
          format(MSG, style: style)
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 7 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/variable_name.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/variable_name.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/variable_name.rb