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 at-mixin-parentheses-space-before end positions #929

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
10 changes: 8 additions & 2 deletions src/rules/at-mixin-parentheses-space-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ testRule({
foo ($n) {
}
`,
line: 2,
line: 4,
column: 7,
endLine: 4,
endColumn: 8,
message: messages.expectedBefore(),
description: "Newline after mixin name"
},
Expand Down Expand Up @@ -190,7 +193,10 @@ testRule({
foo($n) {
}
`,
line: 2,
line: 4,
column: 7,
endLine: 4,
endColumn: 8,
message: messages.rejectedBefore(),
description: "Newline after mixin name"
},
Expand Down
21 changes: 16 additions & 5 deletions src/rules/at-mixin-parentheses-space-before/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const { utils } = require("stylelint");
const atRuleParamIndex = require("../../utils/atRuleParamIndex");
const whitespaceChecker = require("../../utils/whitespaceChecker");
const namespace = require("../../utils/namespace");
const ruleUrl = require("../../utils/ruleUrl");
Expand Down Expand Up @@ -34,17 +35,27 @@ function rule(value, _, context) {

const checker = whitespaceChecker("space", value, messages).before;

root.walkAtRules("mixin", decl => {
root.walkAtRules("mixin", atRule => {
if (context.fix) {
decl.params = decl.params.replace(match, replacement);
atRule.params = atRule.params.replace(match, replacement);

return;
}

const parenIndex = atRule.params.indexOf("(");
const baseIndex = atRuleParamIndex(atRule);

checker({
source: decl.params,
index: decl.params.indexOf("("),
err: message => utils.report({ message, node: decl, result, ruleName })
source: atRule.params,
index: parenIndex,
err: message =>
utils.report({
message,
node: atRule,
result,
ruleName,
index: baseIndex + parenIndex
})
});
});
};
Expand Down