Skip to content

Commit

Permalink
Don't report zero units for calc expressions
Browse files Browse the repository at this point in the history
Zeros in these expressions need to have units in order to work.

Fixes sds#843
  • Loading branch information
sds committed Sep 28, 2016
1 parent 3ba8e32 commit aa535cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/scss_lint/linter/zero_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Linter::ZeroUnit < Linter

def visit_script_string(node)
return unless node.type == :identifier
return if node.value.start_with?('calc(')

node.value.scan(ZERO_UNIT_REGEX) do |match|
next unless zero_with_length_units?(match.first)
Expand All @@ -21,6 +22,12 @@ def visit_script_number(node)
add_lint(node, MESSAGE_FORMAT % length)
end

def visit_script_funcall(node)
# Don't report errors for values within `calc` expressions, since they
# require units in order to work
yield unless node.name == 'calc'
end

private

ZERO_UNIT_REGEX = /
Expand Down
10 changes: 10 additions & 0 deletions spec/scss_lint/linter/zero_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@

it { should_not report_lint }
end

context 'when calc expression with zero value has units' do
let(:scss) { <<-SCSS }
p {
width: calc(0px + 1.5em);
}
SCSS

it { should_not report_lint }
end
end

0 comments on commit aa535cc

Please sign in to comment.