Skip to content

Commit

Permalink
Merge branch 'stylelint-scss:master' into risky-parent-selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelalozano16 committed May 2, 2024
2 parents 5e6e179 + 90caa27 commit 9c00f4d
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 68 deletions.
84 changes: 42 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -27,12 +27,12 @@
"jest": "^29.7.0",
"jest-preset-stylelint": "^7.0.0",
"lint-staged": "^14.0.1",
"np": "^10.0.2",
"np": "^10.0.5",
"postcss": "^8.4.35",
"postcss-less": "^6.0.0",
"postcss-scss": "^4.0.9",
"prettier": "^3.2.5",
"stylelint": "^16.3.1"
"stylelint": "^16.4.0"
},
"files": [
"src/**/*.js",
Expand Down
55 changes: 55 additions & 0 deletions src/rules/no-global-function-names/__tests__/index.js
Expand Up @@ -290,6 +290,26 @@ testRule({
@debug string.unique-id()
`,
description: "string.unique-id"
},
{
code: `
@use "sass:meta"
@function is-number($value) {
@return meta.type-of($value) == 'number'
}
`,
description: "Allowed non-global function in @return"
},
{
code: `
@use "sass:meta"
@mixin foo($name) {
@if meta.type-of($name) != 'string' {
@error 'name must be a string, but was ' + meta.type-of($name)
}
}
`,
description: "Allowed non-global function in @if and @error"
}
],

Expand Down Expand Up @@ -491,6 +511,41 @@ testRule({
"Expected color.adjust($color, $lightness: $amount) instead of lighten($color, $amount)"
),
description: "lighten"
},
{
code: `
@function is-number($value) {
@return type-of($value) == 'number'
}
`,
line: 3,
column: 17,
message: messages.rejected("type-of"),
description: "Global function in @return"
},
{
code: `
@mixin foo($name) {
@if type-of($name) != 'string' {
@error 'name must be a test(string), but was' + type-of($name)
}
}
`,
warnings: [
{
line: 3,
column: 13,
message: messages.rejected("type-of"),
description: "Global function in @if"
},
{
line: 4,
column: 59,
message: messages.rejected("type-of"),
description: "Global function in @error"
}
],
description: "Global function in @if and @error"
}
]
});
15 changes: 12 additions & 3 deletions src/rules/no-global-function-names/index.js
Expand Up @@ -2,6 +2,7 @@

const valueParser = require("postcss-value-parser");
const { utils } = require("stylelint");
const getAtRuleParams = require("../../utils/getAtRuleParams");
const namespace = require("../../utils/namespace");
const ruleUrl = require("../../utils/ruleUrl");

Expand Down Expand Up @@ -173,7 +174,15 @@ function rule(value) {
}

root.walkDecls(decl => {
valueParser(decl.value).walk(node => {
checkValue(decl, decl.value);
});
root.walkAtRules(atRule => {
const params = getAtRuleParams(atRule);
checkValue(atRule, params);
});

function checkValue(parentNode, value) {
valueParser(value).walk(node => {
const cleanValue = node.value.replace(interpolationPrefix, "");

// Verify that we're only looking at functions.
Expand All @@ -184,14 +193,14 @@ function rule(value) {
if (rules[cleanValue]) {
utils.report({
message: messages.rejected(cleanValue),
node: decl,
node: parentNode,
word: cleanValue,
result,
ruleName
});
}
});
});
}
};
}

Expand Down

0 comments on commit 9c00f4d

Please sign in to comment.