Sha256: b34c851a217b38284fa55ec6a6f089dd1fe52ac155241c6b4a54cf57770cd139
Contents?: true
Size: 1.37 KB
Versions: 6
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Checks that memoized helpers names are symbols or strings. # # @example EnforcedStyle: symbols (default) # # bad # subject('user') { create_user } # let('user_name') { 'Adam' } # # # good # subject(:user) { create_user } # let(:user_name) { 'Adam' } # # @example EnforcedStyle: strings # # bad # subject(:user) { create_user } # let(:user_name) { 'Adam' } # # # good # subject('user') { create_user } # let('user_name') { 'Adam' } class VariableDefinition < Base include ConfigurableEnforcedStyle include RuboCop::RSpec::Variable MSG = 'Use %<style>s for variable names.' def on_send(node) variable_definition?(node) do |variable| if style_violation?(variable) add_offense(variable, message: format(MSG, style: style)) end end end private def style_violation?(variable) style == :symbols && string?(variable) || style == :strings && symbol?(variable) end def string?(node) node.str_type? end def symbol?(node) node.sym_type? || node.dsym_type? end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems