@csstools/stylelint-no-at-nest-rule 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +56 -0
- package/index.js +54 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
MIT-0 License
|
|
2
|
+
|
|
3
|
+
Copyright 2023 Romain Menke, Antonio Laguna <antonio@laguna.es>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# [@csstools/stylelint-no-at-nest-rule](https://www.npmjs.com/package/@csstools/stylelint-no-at-nest-rule)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@csstools/stylelint-no-at-nest-rule)
|
|
4
|
+
|
|
5
|
+
Prevent usage of `@nest` in CSS.
|
|
6
|
+
|
|
7
|
+
```css
|
|
8
|
+
/* valid */
|
|
9
|
+
.element {
|
|
10
|
+
article & {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* invalid */
|
|
14
|
+
.element {
|
|
15
|
+
@nest article & {}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The CSS Nesting specification has changed and `@nest` is not longer required and has been removed from the specification.
|
|
20
|
+
Since it will never be valid CSS in browsers it is important to migrate away from it.
|
|
21
|
+
|
|
22
|
+
**Valid CSS :**
|
|
23
|
+
|
|
24
|
+
```css
|
|
25
|
+
.element {
|
|
26
|
+
article {}
|
|
27
|
+
|
|
28
|
+
article & {}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Invalid CSS :**
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
.foo {
|
|
36
|
+
@nest article {}
|
|
37
|
+
|
|
38
|
+
@nest article & {}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
`npm install --save-dev @csstools/stylelint-no-at-nest-rule`
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// stylelint.config.js
|
|
48
|
+
module.exports = {
|
|
49
|
+
plugins: [
|
|
50
|
+
"@csstools/stylelint-no-at-nest-rule",
|
|
51
|
+
],
|
|
52
|
+
rules: {
|
|
53
|
+
"@csstools/stylelint-no-at-nest-rule": true,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const postcss = require('postcss');
|
|
2
|
+
const stylelint = require('stylelint');
|
|
3
|
+
|
|
4
|
+
const ruleName = '@csstools/stylelint-no-at-nest-rule';
|
|
5
|
+
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
6
|
+
rejected: () => {
|
|
7
|
+
return '@nest is deprecated and was removed from the specification. Use a regular selector instead.';
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
url: 'https://github.com/csstools/postcss-plugins/blob/main/plugins-stylelint/no-at-nest-rule',
|
|
13
|
+
fixable: true,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
17
|
+
return (postcssRoot, postcssResult) => {
|
|
18
|
+
if (!primaryOption) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
postcssRoot.walkAtRules(/^nest$/i, (atrule) => {
|
|
23
|
+
if (context.fix) {
|
|
24
|
+
const rule = postcss.rule({
|
|
25
|
+
selector: atrule.params,
|
|
26
|
+
source: atrule.source,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
atrule.nodes.forEach((node) => {
|
|
30
|
+
rule.append(node);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
atrule.replaceWith(rule);
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stylelint.utils.report({
|
|
39
|
+
message: messages.rejected(),
|
|
40
|
+
node: atrule,
|
|
41
|
+
index: 0,
|
|
42
|
+
endIndex: 5,
|
|
43
|
+
result: postcssResult,
|
|
44
|
+
ruleName,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
ruleFunction.ruleName = ruleName;
|
|
51
|
+
ruleFunction.messages = messages;
|
|
52
|
+
ruleFunction.meta = meta;
|
|
53
|
+
|
|
54
|
+
module.exports = stylelint.createPlugin(ruleName, ruleFunction);
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@csstools/stylelint-no-at-nest-rule",
|
|
3
|
+
"description": "Do not allow @nest rules",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Antonio Laguna",
|
|
8
|
+
"email": "antonio@laguna.es",
|
|
9
|
+
"url": "https://antonio.laguna.es"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "Romain Menke",
|
|
13
|
+
"email": "romainmenke@gmail.com"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT-0",
|
|
17
|
+
"funding": [
|
|
18
|
+
{
|
|
19
|
+
"type": "github",
|
|
20
|
+
"url": "https://github.com/sponsors/csstools"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "opencollective",
|
|
24
|
+
"url": "https://opencollective.com/csstools"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^14 || ^16 || >=18"
|
|
29
|
+
},
|
|
30
|
+
"main": "index.js",
|
|
31
|
+
"files": [
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md",
|
|
34
|
+
"index.js"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"postcss": "^8.4",
|
|
38
|
+
"stylelint": "^15.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"jest": "^29.4.3",
|
|
42
|
+
"jest-preset-stylelint": "^6.1.0",
|
|
43
|
+
"postcss": "^8.4",
|
|
44
|
+
"stylelint": "^15.6.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"lint": "node ../../.github/bin/format-package-json.mjs",
|
|
48
|
+
"test": "jest"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/csstools/postcss-plugins/blob/main/plugins-stylelint/no-at-nest-rule#readme",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
54
|
+
"directory": "plugins-stylelint/no-at-nest-rule"
|
|
55
|
+
},
|
|
56
|
+
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
57
|
+
"keywords": [
|
|
58
|
+
"stylelint",
|
|
59
|
+
"stylelint-plugin"
|
|
60
|
+
],
|
|
61
|
+
"jest": {
|
|
62
|
+
"preset": "jest-preset-stylelint"
|
|
63
|
+
}
|
|
64
|
+
}
|