Class: Rubocop::Cop::SpaceAroundEqualsInParameterDefault

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/surrounding_space.rb

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, #has_report?, inherited, #initialize

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#inspect(file, source, tokens, sexp) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rubocop/cop/surrounding_space.rb', line 127

def inspect(file, source, tokens, sexp)
  each(:params, sexp) do |s|
    (s[2] || []).each do |param, value|
      value_pos = all_positions(value).first or next
      if param[-1].lineno == value_pos.lineno
        if value_pos.column - (param[-1].column + param[1].length) <= 2
          add_offence(:convention, param[-1].lineno,
                      'Surrounding space missing in default value ' +
                      'assignment.')
        end
      end
    end
  end
end