lib/scss_lint/linter/shorthand.rb in scss-lint-0.22.0 vs lib/scss_lint/linter/shorthand.rb in scss-lint-0.23.0
- old
+ new
@@ -41,25 +41,32 @@
if value.is_a?(Sass::Script::Value::String)
check_script_string(prop, value)
end
end
+ LIST_LITERAL_REGEX = %r{
+ \A
+ (\S+\s+\S+(\s+\S+){0,2}) # Two to four values separated by spaces
+ (\s+!\w+)? # Ignore `!important` priority overrides
+ \z
+ }x
+
def check_script_string(prop, script_string)
return unless script_string.type == :identifier
- if values = script_string.value.strip[/\A(\S+\s+\S+(\s+\S+){0,2})\z/, 1]
+ if values = script_string.value.strip[LIST_LITERAL_REGEX, 1]
check_shorthand(prop, script_string, values.split)
end
end
def check_shorthand(prop, node, values)
return unless (2..4).member?(values.count)
shortest_form = condensed_shorthand(*values)
return if values == shortest_form
- add_lint(node, "Shorthand form for property `#{prop}` should be " <<
- "written more concisely as `#{shortest_form.join(' ')}` " <<
+ add_lint(node, "Shorthand form for property `#{prop}` should be " \
+ "written more concisely as `#{shortest_form.join(' ')}` " \
"instead of `#{values.join(' ')}`")
end
def condensed_shorthand(top, right, bottom = nil, left = nil)
if can_condense_to_one_value(top, right, bottom, left)