Sha256: 5e65764a08bb634daee1e1a344bfd59888900532f6924f7356407ead9a47e2a5

Contents?: true

Size: 1.73 KB

Versions: 14

Compression:

Stored size: 1.73 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

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

        def on_send(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.loc.expression)
          end
        end

        private

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

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/variable_name.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.18.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.18.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.17.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.17.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.16.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.15.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.14.2 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.14.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.14.0 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.13.2 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.13.1 lib/rubocop/cop/rspec/variable_name.rb
rubocop-rspec-2.13.0 lib/rubocop/cop/rspec/variable_name.rb