Class: RuboCop::Cop::Semantics::VariableName

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/semantics/variable_name.rb

Overview

Checks for meaningless variable names. A good variable name describes its contents with nouns and adjectives.

Examples:


# bad
data = {name: 'Elijah', age: 40}

# good
customer = {name: 'Elijah', age: 40}

Constant Summary collapse

MEANINGLESS_NAMES =
%i[

  data
  info
  scope
  value

].freeze

Instance Method Summary collapse

Instance Method Details

#on_lvasgn(node) ⇒ Object



27
28
29
30
31
32
# File 'lib/rubocop/cop/semantics/variable_name.rb', line 27

def on_lvasgn(node)
  variable_name, = *node
  return unless MEANINGLESS_NAMES.include?(variable_name)

  add_offense(node.loc.name, message: "Use a more descriptive variable name.")
end