Skip to content

Commit

Permalink
Comment regex in PropertyUnits linter
Browse files Browse the repository at this point in the history
I wanted to make this code easier to understand, so I broke this regex
down and added some comments.
  • Loading branch information
lencioni authored and sds committed Jun 29, 2015
1 parent 11fa272 commit a49699e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/scss_lint/linter/property_units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ def visit_prop(node)
property = "#{@nested_under}-#{property}"
end

number_with_units_regex = /
(?:^|\s) # beginning of value or whitespace
(?:
\d+ # any number of digits, e.g. 123
| # or
\d*\.?\d+ # any number of digits with decimal, e.g. 1.23 or .123
)
([a-z%]+) # letters or percent sign, e.g. px or %
/ix

if node.value.respond_to?(:value) &&
units = node.value.value.to_s[/(?:^|\s)(?:\d+|\d*\.?\d+)([a-z%]+)/i, 1]
units = node.value.value.to_s[number_with_units_regex, 1]
check_units(node, property, units)
end

Expand Down

0 comments on commit a49699e

Please sign in to comment.