Skip to content

Commit

Permalink
Fix stylelint font rule (#442)
Browse files Browse the repository at this point in the history
* update rule to exclude font-feature-settings

* add test for font-feature-setting

* Add changeset
  • Loading branch information
alastair-simon authored Jan 15, 2025
1 parent ed632bf commit 4245a21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-spies-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/stylelint-plugin-meteor": patch
---

Fix stylelint font rule to exclude font-feature-settings
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ const meta = {
url: "https://github.com/shopware/meteor/blob/main/packages/stylelint-plugin-meteor/src/rules/prefer-font-token/README.md",
};

const FONT_PROPERTIES: (string | RegExp)[] = [
const FONT_PROPERTIES: string[] = [
"font",
"line-height",
"font-family",
"font-weight",
"font-size",
/^font-/,
"font-style",
"font-variant",
"font-kerning",
];

const GLOBAL_KEYWORDS = [
Expand All @@ -44,11 +47,7 @@ const ruleFunction: Rule = (primary, secondaryOptions, context) => {
if (!validOptions) return;

root.walkDecls((ruleNode) => {
const isFontProperty = FONT_PROPERTIES.some((prop) =>
typeof prop === "string"
? prop === ruleNode.prop
: prop.test(ruleNode.prop)
);
const isFontProperty = FONT_PROPERTIES.includes(ruleNode.prop);
const usesVariable = /var\(--.*\)/.test(ruleNode.value);
const isGlobalKeyword = GLOBAL_KEYWORDS.includes(ruleNode.value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ testRule({
{ code: ".a { font-size: inherit; }" },
{ code: ".a { line-height: var(--line-height-xs); }" },
{ code: ".a { line-height: inherit; }" },
{ code: ".a { font-feature-settings: normal; }" },
],

reject: [
Expand Down

0 comments on commit 4245a21

Please sign in to comment.