Skip to content

Commit

Permalink
Fix TrailingZero message with multiple trailing zeros
Browse files Browse the repository at this point in the history
We would not match as many trailing zeros as were present in some cases,
printing a message that was incorrect, e.g.

    `.600` should be written without a trailing zero as `.60`

instead of:

    `.600` should be written without a trailing zero as `.6`

Fixes sds#792
  • Loading branch information
sds committed May 16, 2016
1 parent 2c3da8f commit 213eefa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Fix `PropertySortOrder` `separate_groups` option to work for preset sort
orders
* Add `background-clip` and `clip` to `smacss` preset sort order
* Fix `TrailingZero` to report correct lint messages for values with multiple
trailing zeros

## 0.48.0

Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/trailing_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def visit_script_number(node)
FRACTIONAL_DIGIT_REGEX = /^-?(\d*\.\d+)/

def check_for_trailing_zeros(node, original_number)
return unless match = /^(\d*\.\d*)0+$/.match(original_number)
return unless match = /^(\d*\.(?:[0-9]*[1-9]|[1-9])*)0+$/.match(original_number)

fixed_number = match[1]

Expand Down
10 changes: 10 additions & 0 deletions spec/scss_lint/linter/trailing_zero_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
it { should_not report_lint }
end

context 'when a unitless fractional value with multiple trailing zero exists' do
let(:scss) { <<-SCSS }
p {
line-height: .600;
}
SCSS

it { should report_lint }
end

context 'when a negative unitless fractional value with no trailing zero exists' do
let(:scss) { <<-SCSS }
p {
Expand Down

0 comments on commit 213eefa

Please sign in to comment.