Skip to content

Commit

Permalink
Fix at-rule pattern warnings to range only one line (#639)
Browse files Browse the repository at this point in the history
* Fix at-rule pattern warnings to range only one line

* Add warning positions to pattern tests
  • Loading branch information
nlydv committed Jul 20, 2022
1 parent 13c291d commit f045f74
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/rules/at-function-pattern/__tests__/index.js
Expand Up @@ -77,6 +77,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: sequence part. Example: symbol in between."
}
Expand Down Expand Up @@ -120,6 +123,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "String: sequence part. Example: symbol in between."
},
Expand All @@ -129,6 +135,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "String: sequence part. Example: not a full sequence."
}
Expand Down Expand Up @@ -191,6 +200,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the end."
},
Expand All @@ -200,6 +212,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the beginning."
},
Expand All @@ -209,6 +224,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: symbol in between."
},
Expand All @@ -220,6 +238,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: strict match. Example: function name divided by newlines."
Expand Down Expand Up @@ -258,6 +279,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: matches at the end."
Expand All @@ -268,6 +292,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: symbol in between."
Expand Down Expand Up @@ -296,19 +323,28 @@ testRule({
{
code: "@function boo-Foo-bar ( $p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description:
"Regexp: SUIT component. Example: starts with lowercase, two elements"
},
{
code: "@function foo-bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description: "Regexp: SUIT component. Example: starts with lowercase"
},
{
code: "@function Foo-Bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description:
"Regexp: SUIT component. Example: element starts with uppercase"
Expand Down
7 changes: 6 additions & 1 deletion src/rules/at-function-pattern/index.js
Expand Up @@ -37,11 +37,16 @@ export default function rule(pattern) {
return;
}

const funcTopLine = Object.assign({}, decl.source.start);
funcTopLine.line += 1;
funcTopLine.column = 0;

utils.report({
message: messages.expected,
node: decl,
result,
ruleName
ruleName,
end: funcTopLine
});
});
};
Expand Down
36 changes: 36 additions & 0 deletions src/rules/at-mixin-pattern/__tests__/index.js
Expand Up @@ -75,6 +75,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: sequence part. Example: symbol in between."
}
Expand Down Expand Up @@ -118,6 +121,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "String: sequence part. Example: symbol in between."
},
Expand All @@ -127,6 +133,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "String: sequence part. Example: not a full sequence."
}
Expand Down Expand Up @@ -198,6 +207,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the end."
},
Expand All @@ -207,6 +219,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the beginning."
},
Expand All @@ -216,6 +231,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description: "Regexp: strict match. Example: symbol in between."
},
Expand All @@ -227,6 +245,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: strict match. Example: mixin name divided by newlines."
Expand Down Expand Up @@ -265,6 +286,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: matches at the end."
Expand All @@ -275,6 +299,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: symbol in between."
Expand Down Expand Up @@ -303,19 +330,28 @@ testRule({
{
code: "@mixin boo-Foo-bar ( $p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description:
"Regexp: SUIT component. Example: starts with lowercase, two elements"
},
{
code: "@mixin foo-bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description: "Regexp: SUIT component. Example: starts with lowercase"
},
{
code: "@mixin Foo-Bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
message: messages.expected,
description:
"Regexp: SUIT component. Example: element starts with uppercase"
Expand Down
7 changes: 6 additions & 1 deletion src/rules/at-mixin-pattern/index.js
Expand Up @@ -37,11 +37,16 @@ export default function rule(pattern) {
return;
}

const mixinTopLine = Object.assign({}, decl.source.start);
mixinTopLine.line += 1;
mixinTopLine.column = 0;

utils.report({
message: messages.expected,
node: decl,
result,
ruleName
ruleName,
end: mixinTopLine
});
});
};
Expand Down

0 comments on commit f045f74

Please sign in to comment.