Skip to content

Commit

Permalink
Add new upstream files for Stylelint v13.0.0 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Jan 19, 2020
1 parent dcdad43 commit db938d1
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,6 +12,7 @@
"url": "https://github.com/kristerkari/stylelint-scss/issues"
},
"dependencies": {
"lodash.get": "^4.4.2",
"lodash.isboolean": "^3.0.3",
"lodash.isregexp": "^4.0.1",
"lodash.isstring": "^4.0.1",
Expand All @@ -35,7 +36,6 @@
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
"lint-staged": "^9.5.0",
"lodash.get": "^4.4.2",
"npmpub": "^5.0.0",
"postcss": "^7.0.26",
"postcss-scss": "^2.0.0",
Expand Down
20 changes: 20 additions & 0 deletions src/utils/__tests__/isCustomPropertySet.test.js
@@ -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);
}
19 changes: 19 additions & 0 deletions src/utils/isCustomPropertySet.js
@@ -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(":")
);
}
63 changes: 58 additions & 5 deletions src/utils/isStandardRule.js
@@ -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;
}

0 comments on commit db938d1

Please sign in to comment.