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-rule-no-unknown
end positions
#655
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
const getTestRule = require("jest-preset-stylelint/getTestRule"); | ||
|
||
global.testRule = getTestRule({ plugins: ["./src"] }); | ||
|
||
// Inspired by https://www.npmjs.com/package/dedent-tag | ||
global.dedent = function dedent(strings) { | ||
return strings[0] | ||
.replace(/^[ \t]+/gm, "") // remove indentation | ||
.replace(/^\s*\n/gm, ""); // remove empty lines | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
"lodash" | ||
], | ||
"globals": { | ||
"dedent": true, | ||
"testRule": true | ||
}, | ||
"rules": { | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -22,7 +22,7 @@ const sassAtRules = [ | |||||||
"return", | ||||||||
"use", | ||||||||
"warn", | ||||||||
"while" | ||||||||
"while", | ||||||||
]; | ||||||||
|
||||||||
const ruleToCheckAgainst = "at-rule-no-unknown"; | ||||||||
|
@@ -34,11 +34,11 @@ export const messages = utils.ruleMessages(ruleName, { | |||||||
return rules[ruleToCheckAgainst].messages | ||||||||
.rejected(...args) | ||||||||
.replace(` (${ruleToCheckAgainst})`, ""); | ||||||||
} | ||||||||
}, | ||||||||
}); | ||||||||
|
||||||||
export const meta = { | ||||||||
url: ruleUrl(ruleName) | ||||||||
url: ruleUrl(ruleName), | ||||||||
}; | ||||||||
|
||||||||
export default function rule(primaryOption, secondaryOptions) { | ||||||||
|
@@ -47,14 +47,14 @@ export default function rule(primaryOption, secondaryOptions) { | |||||||
result, | ||||||||
ruleName, | ||||||||
{ | ||||||||
actual: primaryOption | ||||||||
actual: primaryOption, | ||||||||
}, | ||||||||
{ | ||||||||
actual: secondaryOptions, | ||||||||
possible: { | ||||||||
ignoreAtRules: [isRegExp, isString] | ||||||||
ignoreAtRules: [isRegExp, isString], | ||||||||
}, | ||||||||
optional: true | ||||||||
optional: true, | ||||||||
} | ||||||||
); | ||||||||
|
||||||||
|
@@ -65,16 +65,16 @@ export default function rule(primaryOption, secondaryOptions) { | |||||||
const optionsAtRules = secondaryOptions && secondaryOptions.ignoreAtRules; | ||||||||
const ignoreAtRules = sassAtRules.concat(optionsAtRules || []); | ||||||||
const defaultedOptions = Object.assign({}, secondaryOptions, { | ||||||||
ignoreAtRules | ||||||||
ignoreAtRules, | ||||||||
}); | ||||||||
|
||||||||
utils.checkAgainstRule( | ||||||||
{ | ||||||||
ruleName: ruleToCheckAgainst, | ||||||||
ruleSettings: [primaryOption, defaultedOptions], | ||||||||
root | ||||||||
root, | ||||||||
}, | ||||||||
warning => { | ||||||||
(warning) => { | ||||||||
const name = warning.node.name; | ||||||||
|
||||||||
if (!ignoreAtRules.includes(name)) { | ||||||||
|
@@ -83,8 +83,8 @@ export default function rule(primaryOption, secondaryOptions) { | |||||||
ruleName, | ||||||||
result, | ||||||||
node: warning.node, | ||||||||
line: warning.line, | ||||||||
column: warning.column | ||||||||
start: { line: warning.line, column: warning.column }, | ||||||||
end: { line: warning.endLine, column: warning.endColumn }, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ybiquitous is this a backwards compatible change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I tried testing the minimum version of Lines 40 to 42 in efd565d
$ npm i stylelint@14.5.1
...
$ npx jest at-rule-no-unknown --no-verbose
FAIL src/rules/at-rule-no-unknown/__tests__/index.js
● scss/at-rule-no-unknown › reject › [ true ] › '@funciton floo ($n) {}\n' › no description
expect(received).toMatchObject(expected)
- Expected - 2
+ Received + 0
Object {
"column": 1,
- "endColumn": 10,
- "endLine": 1,
"line": 1,
"text": "Unexpected unknown at-rule \"@funciton\" (scss/at-rule-no-unknown)",
}
at Object.<anonymous> (node_modules/jest-preset-stylelint/getTestRule.js:88:33) It seems that the backward compatibility keeps. 👍🏼 If possible, I think it's better to update |
||||||||
}); | ||||||||
} | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] It seems to me that one case change is enough to test end positions.