Skip to content

Commit

Permalink
Add min_properties option to PropertySortOrder
Browse files Browse the repository at this point in the history
This allows developers to specify a minimum number of properties that
must be in the rule set before sort order matters.
  • Loading branch information
sds committed Apr 26, 2015
1 parent d134072 commit 92c0c62
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
depending on scan order
* Ignore `currentColor`, `inherit`, and `transparent` values in
`VariableForProperty`
* Add `min_properties` option to `PropertySortOrder` to allow specifying a
threshold number of properties that must be present before linting occurs

## 0.37.0

Expand Down
1 change: 1 addition & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ linters:
PropertySortOrder:
enabled: true
ignore_unspecified: false
min_properties: 2
separate_groups: false

PropertySpelling:
Expand Down
1 change: 1 addition & 0 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ vendor-prefixed properties will still be ordered based on the example above
Configuration Option | Description
---------------------|---------------------------------------------------------
`ignore_unspecified` | Whether to ignore properties that are not explicitly specified in `order` (default **false**)
`min_properties` | Minimum number of sortable properties (i.e. properties which are defined by the given `order`) present in the rule set before linting takes place (default **2**)
`order` | Array of properties, or the name of a [preset order](data/property-sort-orders) (default is `nil`, resulting in alphabetical ordering)
`separate_groups` | Whether gaps between groups of properties should be enforced.

Expand Down
14 changes: 7 additions & 7 deletions lib/scss_lint/linter/property_sort_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def check_order(node)
child.is_a?(Sass::Tree::PropNode) && !ignore_property?(child)
end

sortable_prop_info = sortable_props
.map do |child|
name = child.name.join
/^(?<vendor>-\w+(-osx)?-)?(?<property>.+)/ =~ name
{ name: name, vendor: vendor, property: property, node: child }
end
if sortable_props.count >= config.fetch('min_properties', 2)
sortable_prop_info = sortable_props
.map do |child|
name = child.name.join
/^(?<vendor>-\w+(-osx)?-)?(?<property>.+)/ =~ name
{ name: name, vendor: vendor, property: property, node: child }
end

if sortable_props.any?
check_sort_order(sortable_prop_info)
check_group_separation(sortable_prop_info) if @group
end
Expand Down
27 changes: 27 additions & 0 deletions spec/scss_lint/linter/property_sort_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,31 @@
end
end
end

context 'when a minimum number of properties is required' do
let(:linter_config) { { 'min_properties' => 3 } }

context 'when fewer than the minimum number of properties are out of order' do
let(:scss) { <<-SCSS }
p {
margin: 0;
display: none;
}
SCSS

it { should_not report_lint }
end

context 'when at least the minimum number of properties are out of order' do
let(:scss) { <<-SCSS }
p {
margin: 0;
position: absolute;
display: none;
}
SCSS

it { should report_lint line: 2 }
end
end
end

0 comments on commit 92c0c62

Please sign in to comment.