Class: Tailor::Rulers::AllowUnnecessaryDoubleQuotesRuler

Inherits:
Tailor::Ruler
  • Object
show all
Defined in:
lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(config, options) ⇒ AllowUnnecessaryDoubleQuotesRuler

Returns a new instance of AllowUnnecessaryDoubleQuotesRuler.



6
7
8
9
# File 'lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb', line 6

def initialize(config, options)
  super(config, options)
  add_lexer_observers :nl
end

Instance Method Details

#measure(lineno, column) ⇒ Object

Checks to see if the double_quotes are unnecessary.

Parameters:

  • lineno (Fixnum)

    Line the problem was found on.

  • column (Fixnum)

    Column the problem was found on.



24
25
26
27
28
# File 'lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb', line 24

def measure(lineno, column)
  @problems << Problem.new('unnecessary_double_quotes', lineno, column,
    "Unnecessary double quotes at column #{column}, " +
      'expected single quotes.', @options[:level])
end

#nl_update(lexed_line, lineno, _) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb', line 11

def nl_update(lexed_line, lineno, _)
  quotes(lexed_line).each do |quote|
    unless contains_embedded_expression?(quote) ||
      contains_escape_sequence?(quote)
      measure(lineno, column(quote.first))
    end
  end
end