Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new upstream files for Stylelint v13.0.0 compatibility.
- Loading branch information
Showing
5 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import isCustomPropertySet from "../isCustomPropertySet"; | ||
import postcss from "postcss"; | ||
|
||
describe("isCustomPropertySet", () => { | ||
it("accepts custom property set", () => { | ||
customPropertySet("--foo: {};", customPropertySet => { | ||
expect(isCustomPropertySet(customPropertySet)).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it("rejects custom property", () => { | ||
customPropertySet("--foo: red;", customPropertySet => { | ||
expect(isCustomPropertySet(customPropertySet)).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
|
||
function customPropertySet(css, cb) { | ||
postcss.parse(css).walk(cb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import get from "lodash.get"; | ||
import hasBlock from "./hasBlock"; | ||
|
||
/** | ||
* Check whether a Node is a custom property set | ||
* | ||
* @param {import('postcss').Rule} node | ||
* @returns {boolean} | ||
*/ | ||
export default function(node) { | ||
const selector = get(node, "raws.selector.raw", node.selector); | ||
|
||
return ( | ||
node.type === "rule" && | ||
hasBlock(node) && | ||
selector.startsWith("--") && | ||
selector.endsWith(":") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,64 @@ | ||
import isStandardSyntaxRule from "stylelint/lib/utils/isStandardSyntaxRule"; | ||
import get from "lodash.get"; | ||
import isCustomPropertySet from "./isCustomPropertySet"; | ||
import isStandardSyntaxSelector from "./isStandardSelector"; | ||
|
||
/** | ||
* Check whether a rule is standard | ||
* Check whether a Node is a standard rule | ||
* | ||
* @param {Rule} postcss rule node | ||
* @return {boolean} If `true`, the rule is standard | ||
* @param {import('postcss').Rule} rule | ||
* @returns {boolean} | ||
*/ | ||
export default function(rule) { | ||
return isStandardSyntaxRule(rule); | ||
// Get full selector | ||
const selector = get(rule, "raws.selector.raw", rule.selector); | ||
|
||
if (!isStandardSyntaxSelector(rule.selector)) { | ||
return false; | ||
} | ||
|
||
// Custom property set (e.g. --custom-property-set: {}) | ||
if (isCustomPropertySet(rule)) { | ||
return false; | ||
} | ||
|
||
// Called Less mixin (e.g. a { .mixin() }) | ||
// @ts-ignore TODO TYPES support LESS and SASS types somehow | ||
if (rule.mixin) { | ||
return false; | ||
} | ||
|
||
// Less detached rulesets | ||
if (selector.startsWith("@") && selector.endsWith(":")) { | ||
return false; | ||
} | ||
|
||
// Ignore Less &:extend rule | ||
// @ts-ignore TODO TYPES support LESS and SASS types somehow | ||
if (rule.extend) { | ||
return false; | ||
} | ||
|
||
// Ignore mixin or &:extend rule | ||
// https://github.com/shellscape/postcss-less/blob/master/lib/less-parser.js#L52 | ||
// @ts-ignore TODO TYPES support LESS and SASS types somehow | ||
if (rule.params && rule.params[0]) { | ||
return false; | ||
} | ||
|
||
// Non-outputting Less mixin definition (e.g. .mixin() {}) | ||
if (selector.endsWith(")") && !selector.includes(":")) { | ||
return false; | ||
} | ||
|
||
// Less guards | ||
if (/when\s+(not\s+)*\(/.test(selector)) { | ||
return false; | ||
} | ||
|
||
// Ignore Scss nested properties | ||
if (selector.endsWith(":")) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |