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

Update to postcss-less@3 #3687

Merged
merged 8 commits into from Oct 16, 2018
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
2 changes: 0 additions & 2 deletions lib/rules/at-rule-blacklist/README.md
Expand Up @@ -8,8 +8,6 @@ Specify a blacklist of disallowed at-rules.
* At-rules like this */
```

This rule ignores `@import` in Less.

## Options

`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"`
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-blacklist/__tests__/index.js
Expand Up @@ -160,16 +160,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["import"],
syntax: "less",

accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
16 changes: 0 additions & 16 deletions lib/rules/at-rule-empty-line-before/__tests__/index.js
Expand Up @@ -1300,19 +1300,3 @@ testRule(
]
})
);

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",

accept: [
{
code: stripIndent`
@media {}
@import 'x.css';
`,
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-name-case/README.md
Expand Up @@ -8,8 +8,6 @@ Specify lowercase or uppercase for at-rules names.
* These at-rule names */
```

This rule ignores `@import` in Less.

Only lowercase at-rule names are valid in SCSS.

The `--fix` option on the [command line](../../../docs/user-guide/cli.md#autofixing-errors) can automatically fix some of the problems reported by this rule.
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-name-case/__tests__/index.js
Expand Up @@ -284,16 +284,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["upper"],
syntax: "less",

accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-name-newline-after/README.md
Expand Up @@ -9,8 +9,6 @@ Require a newline after at-rule names.
* The newline after this at-rule name */
```

This rule ignores `@import` in Less.

## Options

`string`: `"always"|"always-multi-line"`
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-name-newline-after/__tests__/index.js
Expand Up @@ -402,16 +402,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",

accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-name-space-after/README.md
Expand Up @@ -8,8 +8,6 @@ Require a single space after at-rule names.
* The space after at-rule names */
```

This rule ignores `@import` in Less.

The `--fix` option on the [command line](../../../docs/user-guide/cli.md#autofixing-errors) can automatically fix all of the problems reported by this rule.

## Options
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-name-space-after/__tests__/index.js
Expand Up @@ -469,16 +469,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",

accept: [
{
code: "@import'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-semicolon-newline-after/README.md
Expand Up @@ -9,8 +9,6 @@ Require a newline after the semicolon of at-rules.
* The newline after these semicolons */
```

This rule ignores `@import` in Less.

This rule allows an end-of-line comment followed by a newline. For example:

```css
Expand Down
12 changes: 0 additions & 12 deletions lib/rules/at-rule-semicolon-newline-after/__tests__/index.js
Expand Up @@ -125,15 +125,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",
accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-semicolon-space-before/README.md
Expand Up @@ -8,8 +8,6 @@ Require a single space or disallow whitespace before the semicolons at-rules.
* The space before this semicolon */
```

This rule ignores `@import` in Less.

## Options

`string`: `"always"|"never"`
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-semicolon-space-before/__tests__/index.js
Expand Up @@ -151,16 +151,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",

accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/at-rule-whitelist/README.md
Expand Up @@ -8,8 +8,6 @@ Specify a whitelist of allowed at-rules.
* At-rules like this */
```

This rule ignores `@import` in Less.

## Options

`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"`
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/at-rule-whitelist/__tests__/index.js
Expand Up @@ -152,16 +152,3 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["media"],
syntax: "less",

accept: [
{
code: "@import 'x.css';",
description: "ignore less @imports"
}
]
});
2 changes: 0 additions & 2 deletions lib/rules/function-url-quotes/README.md
Expand Up @@ -8,8 +8,6 @@ a { background: url("x.jpg") }
* These quotes */
```

This rule ignores `@import` in Less.

## Options

`string`: `"always"|"never"`
Expand Down
13 changes: 0 additions & 13 deletions lib/rules/function-url-quotes/__tests__/index.js
Expand Up @@ -642,19 +642,6 @@ testRule(rule, {
]
});

testRule(rule, {
ruleName,
config: ["always"],
syntax: "less",

accept: [
{
code: "@import url(foo.css);",
description: "ignore less @imports"
}
]
});

testRule(rule, {
ruleName,
config: ["always"],
Expand Down
2 changes: 0 additions & 2 deletions lib/rules/no-duplicate-at-import-rules/README.md
Expand Up @@ -9,8 +9,6 @@ Disallow duplicate `@import` rules within a stylesheet.
* These are duplicates */
```

This rule ignores `@import` in Less.

## Options

### `true`
Expand Down
9 changes: 7 additions & 2 deletions lib/rules/no-extra-semicolons/index.js
Expand Up @@ -2,6 +2,7 @@

const eachRoot = require("../../utils/eachRoot");
const isCustomPropertySet = require("../../utils/isCustomPropertySet");
const isStandardSyntaxAtRule = require("../../utils/isStandardSyntaxAtRule");
const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
Expand Down Expand Up @@ -75,6 +76,10 @@ const rule = function(actual, options, context) {
}

root.walk(node => {
if (node.type === "atrule" && !isStandardSyntaxAtRule(node)) {
return;
}

if (
node.type === "rule" &&
!isCustomPropertySet(node) &&
Expand Down Expand Up @@ -150,9 +155,9 @@ const rule = function(actual, options, context) {
*/
if (
node.last &&
node.last.type === "rule" &&
node.last.type === "atrule" &&
!isCustomPropertySet(node.last) &&
!isStandardSyntaxRule(node.last)
!isStandardSyntaxAtRule(node.last)
) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/unit-case/__tests__/index.js
Expand Up @@ -128,6 +128,10 @@ testRule(rule, {
{
code: "@media not screen and (min-width: 100px) {}",
description: "negation @media"
},
{
code: "@import 'foo.css'",
description: "ignore non-media and non-variable at-rule"
}
],

Expand Down
10 changes: 7 additions & 3 deletions lib/rules/unit-case/index.js
Expand Up @@ -60,9 +60,13 @@ const rule = function(expectation) {
});
}

root.walkAtRules(/^media$/i, atRule =>
check(atRule, atRule.params, atRuleParamIndex)
);
root.walkAtRules(atRule => {
if (!/^media$/i.test(atRule.name) && !atRule.variable) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a bunch of tests for @variable syntax, hence this change even though it's non-standard syntax. Perhaps those tests should be updated instead?

return;
}

check(atRule, atRule.params, atRuleParamIndex);
});
root.walkDecls(decl => check(decl, decl.value, declarationValueIndex));
};
};
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/unit-no-unknown/__tests__/index.js
Expand Up @@ -204,6 +204,10 @@ testRule(rule, {
{
code: "@media screen and (min-width:0\\0) {}",
description: "ignore media query hack"
},
{
code: "@import 'foo.css'",
description: "ignore non-media and non-variable at-rule"
}
],

Expand Down
10 changes: 7 additions & 3 deletions lib/rules/unit-no-unknown/index.js
Expand Up @@ -72,9 +72,13 @@ const rule = function(actual, options) {
});
}

root.walkAtRules(/^media$/i, atRule =>
check(atRule, atRule.params, atRuleParamIndex)
);
root.walkAtRules(atRule => {
if (!/^media$/i.test(atRule.name) && !atRule.variable) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, there were a bunch of tests for @variable syntax, hence this change even though it's non-standard syntax. Perhaps those tests should be updated instead?

return;
}

check(atRule, atRule.params, atRuleParamIndex);
});
root.walkDecls(decl => check(decl, decl.value, declarationValueIndex));
};
};
Expand Down
8 changes: 8 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxAtRule.test.js
Expand Up @@ -94,6 +94,14 @@ describe("isStandardSyntaxAtRule", () => {
expect(isStandardSyntaxAtRule(atRule)).toBeFalsy();
});
});

it("ignore calling of mixins", () => {
const less = "a { .mixin(); }";

lessAtRules(less, atRule => {
expect(isStandardSyntaxAtRule(atRule)).toBeFalsy();
});
});
});

function atRules(css, cb) {
Expand Down
14 changes: 9 additions & 5 deletions lib/utils/isStandardSyntaxAtRule.js
Expand Up @@ -7,17 +7,21 @@
* @param {atRule} postcss at-rule node
* @return {boolean} If `true`, the declaration is standard
*/
module.exports = function(atRule /*: postcss$atRule*/) /*: boolean*/ {
module.exports = function(atRule /*: Object*/) /*: boolean*/ {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps someone better than me at Flow can help out with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no clue about Flow, to be honest. Maybe new properties should be added to this lines?

declare class postcss$atRule extends postcss$node {
name: string;
params: string;
raws: {
before?: string,
after?: string,
afterName?: string
};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CAYdenberg Any chance you've got a spare moment to check on this Flow issue please?

// Ignore scss `@content` inside mixins
if (!atRule.nodes && atRule.params === "") {
return false;
}

// Ignore detached ruleset `@detached-ruleset: { background: red; }; .top { @detached-ruleset(); }`
// Ignore Less mixins
if (atRule.mixin) {
return false;
}

// Ignore Less detached ruleset `@detached-ruleset: { background: red; }; .top { @detached-ruleset(); }`
if (
!atRule.nodes &&
atRule.raws.afterName === "" &&
atRule.params[0] === "("
atRule.variable ||
(!atRule.nodes && atRule.raws.afterName === "" && atRule.params[0] === "(")
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -65,7 +65,7 @@
"postcss": "^7.0.0",
"postcss-html": "^0.34.0",
"postcss-jsx": "^0.34.0",
"postcss-less": "^2.0.0",
"postcss-less": "^3.0.1",
"postcss-markdown": "^0.34.0",
"postcss-media-query-parser": "^0.2.3",
"postcss-reporter": "^6.0.0",
Expand Down