Skip to content

Commit

Permalink
Disallow shorthands not in allowed_shorthands list
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Meinerz authored and sds committed Jun 9, 2016
1 parent 9016d80 commit e283d16
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ linters:

Shorthand:
enabled: true
allowed_shorthands: [1, 2, 3]
allowed_shorthands: [1, 2, 3, 4]

SingleLinePerProperty:
enabled: true
Expand Down
4 changes: 2 additions & 2 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,11 @@ margin: 1px;
```

If you don't want to allow all possible shorthands, you can limit them by
setting the `allowed_shorthands` array option to a subset of `[1, 2, 3]`.
setting the `allowed_shorthands` array option to a subset of `[1, 2, 3, 4]`.

Configuration Option | Description
---------------------|---------------------------------------------------------
`allowed_shorthands` | Array of allowed shorthand lengths (default `[1, 2, 3]`)
`allowed_shorthands` | Array of allowed shorthand lengths (default `[1, 2, 3, 4]`)

## SingleLinePerProperty

Expand Down
3 changes: 3 additions & 0 deletions lib/scss_lint/linter/shorthand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def check_script_string(prop, script_string)
# @param node [Sass::Script::Value::String]
# @param values [Array<String>]
def check_shorthand(prop, node, values)
add_lint(node, "Shorthands of length `#{values.count}` are not allowed. " \
"Value was `#{values.join(' ')}`") unless allowed?(values.count)

return unless (2..4).member?(values.count)

shortest_form = condensed_shorthand(*values)
Expand Down
11 changes: 11 additions & 0 deletions spec/scss_lint/linter/shorthand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,16 @@

it { should_not report_lint }
end

context 'is fine but length is not allowed' do
let(:allowed) { [1, 2, 3] }
let(:scss) { <<-SCSS }
p {
margin: 1px 2px 3px 4px;
}
SCSS

it { should report_lint }
end
end
end

0 comments on commit e283d16

Please sign in to comment.