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 function-linear-gradient-no-nonstandard-direction false positives for <color-interpolation-method> #6987

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-cycles-raise.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `function-linear-gradient-no-nonstandard-direction` false positives for `<color-interpolation-method>`
Expand Up @@ -55,6 +55,12 @@ testRule({
{
code: '.foo { background: linear-gradient(black, white); }',
},
{
code: '.foo { background: linear-gradient(in srgb to top, #fff, #000); }',
},
{
code: '.foo { background: linear-gradient(to top in srgb, #fff, #000); }',
},
{
code: '.foo { background: linear-gradient(rgba(255, 255, 255, 0.5) 0%, #000); }',
},
Expand Down Expand Up @@ -196,6 +202,16 @@ testRule({
endLine: 1,
endColumn: 41,
},
{
code: '.foo { background: linear-gradient(topin, #fff, #000); }',
description:
'An incorrect direction that contains the word "in", only "in" as a word on its own is ignored by this rule.',
message: messages.rejected,
line: 1,
column: 36,
endLine: 1,
endColumn: 41,
},
{
code: '.foo { background: -webkit-linear-gradient(to bottom, #fff, #000 ); }',
message: messages.rejected,
Expand Down
Expand Up @@ -29,6 +29,7 @@ const DIRECTION_WITHOUT_TO = new RegExp(`^(${DIRECTION.source})(?: (${DIRECTION.

const DIGIT = /[\d.]/;
const ANGLE = /^[\d.]+(?:deg|grad|rad|turn)$/;
const IN_KEYWORD = /\bin\b/i;

/**
* @param {string} source
Expand Down Expand Up @@ -84,6 +85,11 @@ const rule = (primary) => {
return;
}

// Ignore gradients with modern syntax that have color space interpolation arguments
if (IN_KEYWORD.test(firstArg)) {
return;
}

// If the first character is a number, we can assume the user intends an angle
if (DIGIT.test(firstArg.charAt(0))) {
if (ANGLE.test(firstArg)) {
Expand Down