Skip to content

Commit

Permalink
[Bug fix] Catching values with dots in them (#218)
Browse files Browse the repository at this point in the history
* Catches values with dots

* Create dull-glasses-visit.md
  • Loading branch information
jonrohan authored Feb 28, 2022
1 parent 5bb2834 commit c03be7d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dull-glasses-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/stylelint-config": patch
---

[Bug fix] Catching values with dots in them
17 changes: 17 additions & 0 deletions __tests__/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ testRule({
}
],
reject: [
{
code: '.x { padding-bottom: 0.3em; }',
unfixable: true,
message:
"Please use a primer spacer variable instead of '0.3em'. Consult the primer docs for a suitable replacement. https://primer.style/css/support/spacing (primer/spacing)",
line: 1,
column: 22,
description: 'Errors on non-spacer em values.'
},
{
code: '.x { padding: 4px; }',
fixed: '.x { padding: $spacer-1; }',
Expand All @@ -46,6 +55,14 @@ testRule({
column: 15,
description: "Replaces '4px' with '$spacer-1'."
},
{
code: '.x { padding: 0.5em; }',
fixed: '.x { padding: $em-spacer-5; }',
message: `Please replace 0.5em with spacing variable '$em-spacer-5'. (primer/spacing)`,
line: 1,
column: 15,
description: "Replaces '0.5em' with '$em-spacer-5'."
},
{
code: '.x { padding: -4px; }',
fixed: '.x { padding: -$spacer-1; }',
Expand Down
2 changes: 1 addition & 1 deletion plugins/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex

const valueUnit = valueParser.unit(cleanValue)

if (valueUnit && (valueUnit.unit === '' || !/^[0-9]+$/.test(valueUnit.number))) {
if (valueUnit && (valueUnit.unit === '' || !/^[0-9.]+$/.test(valueUnit.number))) {
return
}

Expand Down

0 comments on commit c03be7d

Please sign in to comment.