Skip to content

Commit

Permalink
Fix function-color-relative end positions (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Dec 13, 2023
1 parent 994c4f2 commit 1ff01a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
48 changes: 36 additions & 12 deletions src/rules/function-color-relative/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ testRule({
description: "does not accept the saturate function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 26
},
{
code: `
Expand All @@ -55,7 +57,9 @@ testRule({
description: "does not accept the desaturate function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 28
},
{
code: `
Expand All @@ -66,7 +70,9 @@ testRule({
description: "does not accept the darken function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 24
},
{
code: `
Expand All @@ -77,7 +83,9 @@ testRule({
description: "does not accept the lighten function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 25
},
{
code: `
Expand All @@ -88,7 +96,9 @@ testRule({
description: "does not accept the opacify function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 25
},
{
code: `
Expand All @@ -99,7 +109,9 @@ testRule({
description: "does not accept the fade-in function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 25
},
{
code: `
Expand All @@ -110,7 +122,9 @@ testRule({
description: "does not accept the transparentize function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 32
},
{
code: `
Expand All @@ -121,7 +135,9 @@ testRule({
description: "does not accept the fade-out function",
message: messages.rejected,
line: 3,
column: 18
column: 18,
endLine: 3,
endColumn: 26
},
{
code: `
Expand All @@ -133,7 +149,9 @@ testRule({
"does not accept color functions inside a drop-shadow filter",
message: messages.rejected,
line: 3,
column: 39
column: 39,
endLine: 3,
endColumn: 47
},
{
code: `
Expand All @@ -145,7 +163,9 @@ testRule({
"does not accept color functions inside a drop-shadow filter when multiple filters are used",
message: messages.rejected,
line: 3,
column: 54
column: 54,
endLine: 3,
endColumn: 62
},
{
code: `
Expand All @@ -157,7 +177,9 @@ testRule({
"does not accept color functions inside a drop-shadow filter when multiple filters are used",
message: messages.rejected,
line: 3,
column: 53
column: 53,
endLine: 3,
endColumn: 61
},
{
code: `
Expand All @@ -169,7 +191,9 @@ testRule({
"does not accept color functions inside a drop-shadow filter when multiple filters are used",
message: messages.rejected,
line: 3,
column: 39
column: 39,
endLine: 3,
endColumn: 47
}
]
});
10 changes: 7 additions & 3 deletions src/rules/function-color-relative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function rule(primary) {
}

root.walkDecls(decl => {
const declValueIndex = declarationValueIndex(decl);

valueParser(decl.value).walk(node => {
// Verify that we're only looking at functions.
if (node.type !== "function" || node.value === "") {
Expand All @@ -56,15 +58,17 @@ function rule(primary) {
node.nodes.some(isColorFunction);

if (isSassColorFunction || isDSFilterColorFunction) {
const nodes = isDSFilterColorFunction
const funcNodes = isDSFilterColorFunction
? node.nodes.filter(isColorFunction)
: [node];

nodes.forEach(node => {
funcNodes.forEach(funcNode => {
const index = declValueIndex + funcNode.sourceIndex;
utils.report({
message: messages.rejected,
node: decl,
index: declarationValueIndex(decl) + node.sourceIndex,
index,
endIndex: index + funcNode.value.length,
result,
ruleName
});
Expand Down

0 comments on commit 1ff01a6

Please sign in to comment.