Class: Tailor::Rulers::AllowConditionalParenthesesRuler
- Inherits:
-
Tailor::Ruler
- Object
- Tailor::Ruler
- Tailor::Rulers::AllowConditionalParenthesesRuler
- Defined in:
- lib/tailor/rulers/allow_conditional_parentheses.rb
Instance Attribute Summary
Attributes inherited from Tailor::Ruler
Instance Method Summary collapse
-
#initialize(style, options) ⇒ AllowConditionalParenthesesRuler
constructor
A new instance of AllowConditionalParenthesesRuler.
-
#measure(line, lineno) ⇒ Object
Checks to see if a conditional is unnecessarily wrapped in parentheses.
- #nl_update(current_lexed_line, lineno, _) ⇒ Object
Methods inherited from Tailor::Ruler
#add_child_ruler, #problem_type, #problems
Methods included from Logger::Mixin
Constructor Details
#initialize(style, options) ⇒ AllowConditionalParenthesesRuler
Returns a new instance of AllowConditionalParenthesesRuler.
6 7 8 9 |
# File 'lib/tailor/rulers/allow_conditional_parentheses.rb', line 6 def initialize(style, ) super(style, ) add_lexer_observers :nl end |
Instance Method Details
#measure(line, lineno) ⇒ Object
Checks to see if a conditional is unnecessarily wrapped in parentheses.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tailor/rulers/allow_conditional_parentheses.rb', line 19 def measure(line, lineno) return if @config return unless line.any? { |t| conditional?(t) } if tokens_before_lparen?(line) and ! tokens_after_rparen?(line) column = lparen_column(line) @problems << Problem.new('conditional_parentheses', lineno, column, "Parentheses around conditional expression at column #{column}.", @options[:level]) end end |
#nl_update(current_lexed_line, lineno, _) ⇒ Object
11 12 13 |
# File 'lib/tailor/rulers/allow_conditional_parentheses.rb', line 11 def nl_update(current_lexed_line, lineno, _) measure(current_lexed_line, lineno) end |