Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value-keyword-case false positives for mixed case ignoreFunctions option #6517

Merged
merged 4 commits into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-hounds-exercise.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `value-keyword-case` false positives for mixed case `ignoreFunctions` option
5 changes: 4 additions & 1 deletion lib/rules/value-keyword-case/__tests__/index.js
Expand Up @@ -2274,7 +2274,7 @@ testRule({

testRule({
ruleName,
config: ['upper', { ignoreFunctions: ['t', /^(f|F)oo$/] }],
config: ['upper', { ignoreFunctions: ['t', 'camelCase', /^(f|F)oo$/] }],
fix: true,

accept: [
Expand All @@ -2293,6 +2293,9 @@ testRule({
{
code: 'a { color: Foo(--camelCase); }',
},
{
code: 'a { color: camelCase(value); }',
},
],

reject: [
Expand Down
9 changes: 4 additions & 5 deletions lib/rules/value-keyword-case/index.js
Expand Up @@ -84,7 +84,8 @@ const rule = (primary, secondaryOptions, context) => {
let needFix = false;

parsed.walk((node) => {
const valueLowerCase = node.value.toLowerCase();
const keyword = node.value;
const valueLowerCase = keyword.toLowerCase();

// Ignore system colors
if (systemColorsKeywords.has(valueLowerCase)) {
Expand All @@ -107,19 +108,17 @@ const rule = (primary, secondaryOptions, context) => {

if (
node.type === 'function' &&
optionsMatches(secondaryOptions, 'ignoreFunctions', valueLowerCase)
optionsMatches(secondaryOptions, 'ignoreFunctions', keyword)
) {
return false;
}

const keyword = node.value;

const { unit } = getDimension(node);

// Ignore css variables, and hex values, and math operators, and sass interpolation
if (
node.type !== 'word' ||
!isStandardSyntaxValue(node.value) ||
!isStandardSyntaxValue(keyword) ||
value.includes('#') ||
ignoredCharacters.has(keyword) ||
unit
Expand Down