Skip to content

Commit

Permalink
Fix Shorthand to ignore !default/!important
Browse files Browse the repository at this point in the history
Fixes sds#809
  • Loading branch information
sds committed Aug 27, 2016
1 parent 4f73a6a commit 1811fe8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Fix `SpaceAfterComma` linter to report correct column number
* Fix `PrivateNamingConvention` to consider functions/mixins used inside other
functions/mixins
* Fix `Shorthand` to not report shorthanded values with `!important` as having
a shorthand length not specified in `allowed_shorthands`

## 0.49.0

Expand Down
6 changes: 6 additions & 0 deletions lib/scss_lint/linter/shorthand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def check_script_string(prop, script_string)
# @param node [Sass::Script::Value::String]
# @param values [Array<String>]
def check_shorthand(prop, node, values)
values = shorthand_values(values)

add_lint(node, "Shorthands of length `#{values.count}` are not allowed. " \
"Value was `#{values.join(' ')}`") unless allowed?(values.count)

Expand Down Expand Up @@ -138,5 +140,9 @@ def allowed?(size)
return false unless config['allowed_shorthands']
config['allowed_shorthands'].map(&:to_i).include?(size)
end

def shorthand_values(values)
values.take(4).take_while { |value| !value.to_s.start_with?('!') }
end
end
end
10 changes: 10 additions & 0 deletions spec/scss_lint/linter/shorthand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@
SCSS

it { should_not report_lint }

context 'and ends with !important' do
let(:scss) { <<-SCSS }
p {
margin: 4px 4px 4px !important;
}
SCSS

it { should_not report_lint }
end
end

context 'is fine but length is not allowed' do
Expand Down

0 comments on commit 1811fe8

Please sign in to comment.