Skip to content

Commit

Permalink
Fix SpaceAroundOperator error messages for multiline expressions
Browse files Browse the repository at this point in the history
We should not display multiline expressions in `scss-lint`'s single line
output format. Condense messages into a single line.
  • Loading branch information
sds committed Jul 23, 2015
1 parent c44e3e5 commit c8c6a99
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/scss_lint/linter/space_around_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class Linter::SpaceAroundOperator < Linter
include LinterRegistry

def visit_script_operation(node) # rubocop:disable Metrics/AbcSize
source = source_from_range(node.source_range).chop
source = normalize_source(source_from_range(node.source_range))
left_range = node.operand1.source_range
right_range = node.operand2.source_range

# We need to #chop at the end because an operation's operand1 _always_
# includes one character past the actual operand (which is either a
# whitespace character, or the first character of the operation).
left_source = source_from_range(left_range).chop
right_source = source_from_range(right_range).chop
left_source = normalize_source(source_from_range(left_range))
right_source = normalize_source(source_from_range(right_range))
operator_source = source_between(left_range, right_range)
left_source, operator_source = adjust_left_boundary(left_source, operator_source)

Expand Down Expand Up @@ -58,6 +58,11 @@ def source_between(range1, range2)
range1.importer))
end

# Removes trailing parentheses and compacts newlines into a single space
def normalize_source(source)
source.chop.gsub(/\s*\n\s*/, ' ')
end

def adjust_left_boundary(left, operator)
# If the left operand is wrapped in parentheses, any right parens end up
# in the operator source. Here, we move them into the left operand
Expand Down

0 comments on commit c8c6a99

Please sign in to comment.