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-color-relative end positions #911

Merged
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
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