Skip to content

Commit

Permalink
Fix length-zero-no-unit autofix for .0 values (#6098)
Browse files Browse the repository at this point in the history
Fix bug with '.0rem' -> ''
  • Loading branch information
playhardgopro committed May 19, 2022
1 parent 4af3c81 commit e401d87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/rules/length-zero-no-unit/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ testRule({
endLine: 1,
endColumn: 27,
},
{
code: 'a { right: .0rem; }',
fixed: 'a { right: 0; }',
message: messages.rejected,
line: 1,
column: 14,
endLine: 1,
endColumn: 17,
},
{
code: stripIndent`
a {
Expand Down
8 changes: 7 additions & 1 deletion lib/rules/length-zero-no-unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ const rule = (primary, secondaryOptions, context) => {
if (!isZero(number)) return;

if (context.fix) {
valueNode.value = number;
let regularNumber = number;

if (regularNumber.startsWith('.')) {
regularNumber = number.slice(1);
}

valueNode.value = regularNumber;
needsFix = true;

return;
Expand Down

0 comments on commit e401d87

Please sign in to comment.