Skip to content

Commit

Permalink
Merge branch 'main' into fix-hue-degree-notation-false-negatives-for-…
Browse files Browse the repository at this point in the history
…oklch
  • Loading branch information
romainmenke committed Jun 30, 2023
2 parents 8c17bdc + ef7e77e commit 0fa3d91
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-suits-reflect.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `function-name-case` performance
5 changes: 5 additions & 0 deletions .changeset/empty-starfishes-leave.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `hue-degree-notation` performance
5 changes: 5 additions & 0 deletions .changeset/hot-doors-jump.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `custom-property-pattern` performance
5 changes: 5 additions & 0 deletions .changeset/silly-eagles-grow.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `selector-id-pattern` performance
5 changes: 5 additions & 0 deletions .changeset/tender-apes-count.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `function-url-quotes` performance
24 changes: 14 additions & 10 deletions lib/rules/custom-property-pattern/index.js
Expand Up @@ -20,6 +20,8 @@ const meta = {
url: 'https://stylelint.io/user-guide/rules/custom-property-pattern',
};

const VAR_FUNC_REGEX = /var\(/i;

/** @type {import('stylelint').Rule} */
const rule = (primary) => {
return (root, result) => {
Expand All @@ -40,30 +42,32 @@ const rule = (primary) => {
*/
function check(property) {
return (
!isStandardSyntaxProperty(property) ||
!isCustomProperty(property) ||
!isStandardSyntaxProperty(property) ||
regexpPattern.test(property.slice(2))
);
}

root.walkDecls((decl) => {
const { prop, value } = decl;

const parsedValue = valueParser(value);
if (VAR_FUNC_REGEX.test(value)) {
const parsedValue = valueParser(value);

parsedValue.walk((node) => {
if (!isValueFunction(node)) return;
parsedValue.walk((node) => {
if (!isValueFunction(node)) return;

if (node.value.toLowerCase() !== 'var') return;
if (node.value.toLowerCase() !== 'var') return;

const { nodes } = node;
const { nodes } = node;

const firstNode = nodes[0];
const firstNode = nodes[0];

if (!firstNode || check(firstNode.value)) return;
if (!firstNode || check(firstNode.value)) return;

complain(declarationValueIndex(decl) + firstNode.sourceIndex, firstNode.value, decl);
});
complain(declarationValueIndex(decl) + firstNode.sourceIndex, firstNode.value, decl);
});
}

if (check(prop)) return;

Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-name-case/index.js
Expand Up @@ -54,6 +54,8 @@ const rule = (primary, secondaryOptions, context) => {
}

root.walkDecls((decl) => {
if (!decl.value.includes('(')) return;

if (!isStandardSyntaxValue(decl.value)) return;

let needFix = false;
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/function-url-quotes/index.js
Expand Up @@ -24,6 +24,8 @@ const meta = {
fixable: true,
};

const URL_FUNC_REGEX = /url\(/i;

/** @type {import('stylelint').Rule} */
const rule = (primary, secondaryOptions, context) => {
return (root, result) => {
Expand Down Expand Up @@ -57,6 +59,8 @@ const rule = (primary, secondaryOptions, context) => {
* @param {import('postcss').Declaration} decl
*/
function checkDeclParams(decl) {
if (!URL_FUNC_REGEX.test(decl.value)) return;

if (!isStandardSyntaxDeclaration(decl)) return;

const value = getDeclarationValue(decl);
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/hue-degree-notation/index.js
Expand Up @@ -24,6 +24,7 @@ const meta = {
const HUE_FIRST_ARG_FUNCS = ['hsl', 'hsla', 'hwb'];
const HUE_THIRD_ARG_FUNCS = ['lch', 'oklch'];
const HUE_FUNCS = new Set([...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS]);
const HAS_HUE_COLOR_FUNC = new RegExp(`\\b(?:${[...HUE_FUNCS].join('|')})\\(`, 'i');

/** @type {import('stylelint').Rule} */
const rule = (primary, _secondaryOptions, context) => {
Expand All @@ -36,6 +37,8 @@ const rule = (primary, _secondaryOptions, context) => {
if (!validOptions) return;

root.walkDecls((decl) => {
if (!HAS_HUE_COLOR_FUNC.test(decl.value)) return;

let needsFix = false;
const parsedValue = valueParser(getDeclarationValue(decl));

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/selector-id-pattern/index.js
Expand Up @@ -31,7 +31,7 @@ const rule = (primary) => {

const normalizedPattern = isString(primary) ? new RegExp(primary) : primary;

root.walkRules((ruleNode) => {
root.walkRules(/#/, (ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}
Expand Down

0 comments on commit 0fa3d91

Please sign in to comment.