Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::Semicolon

This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

Constants

MSG

Public Instance Methods

investigate(processed_source) click to toggle source
# File lib/rubocop/cop/style/semicolon.rb, line 10
def investigate(processed_source)
  return unless processed_source.ast
  @processed_source = processed_source

  check_for_line_terminator
end
on_begin(node) click to toggle source
# File lib/rubocop/cop/style/semicolon.rb, line 17
def on_begin(node)
  return if cop_config['AllowAsExpressionSeparator']
  exprs = node.children

  return if exprs.size < 2

  # create a map matching lines to the number of expressions on them
  exprs_lines = exprs.map { |e| e.loc.expression.line }
  lines = exprs_lines.group_by { |i| i }

  # every line with more than 1 expression on it is an offense
  lines.each do |line, expr_on_line|
    next unless expr_on_line.size > 1
    # TODO: Find the correct position of the semicolon. We don't know
    # if the first semicolon on the line is a separator of
    # expressions. It's just a guess.
    column = @processed_source[line - 1].index(';')
    convention_on(line, column, !:last_on_line)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.