stylelint-order 3.1.0 → 5.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/README.md +26 -38
- package/index.js +1 -1
- package/package.json +75 -73
- package/rules/checkAlphabeticalOrder.js +3 -3
- package/rules/order/README.md +205 -160
- package/rules/order/checkNode.js +83 -32
- package/rules/order/checkOrder.js +35 -28
- package/rules/order/{createExpectedOrder.js → createOrderInfo.js} +30 -28
- package/rules/order/getDescription.js +6 -3
- package/rules/order/getOrderData.js +7 -7
- package/rules/order/index.js +25 -51
- package/rules/order/messages.js +6 -0
- package/rules/order/ruleName.js +3 -0
- package/rules/order/validatePrimaryOption.js +34 -26
- package/rules/properties-alphabetical-order/README.md +8 -7
- package/rules/properties-alphabetical-order/checkNode.js +61 -0
- package/rules/properties-alphabetical-order/index.js +24 -99
- package/rules/properties-order/README.md +232 -142
- package/rules/properties-order/addEmptyLineBefore.js +1 -3
- package/rules/properties-order/checkEmptyLineBefore.js +65 -57
- package/rules/properties-order/checkEmptyLineBeforeFirstProp.js +41 -0
- package/rules/properties-order/checkNodeForEmptyLines.js +68 -0
- package/rules/properties-order/checkNodeForOrder.js +92 -0
- package/rules/properties-order/checkOrder.js +25 -15
- package/rules/properties-order/createFlatOrder.js +3 -3
- package/rules/properties-order/{createExpectedOrder.js → createOrderInfo.js} +7 -7
- package/rules/properties-order/getNodeData.js +15 -15
- package/rules/properties-order/index.js +40 -50
- package/rules/properties-order/messages.js +11 -0
- package/rules/properties-order/ruleName.js +3 -0
- package/rules/properties-order/validatePrimaryOption.js +13 -13
- package/utils/__tests__/vendor.test.js +15 -0
- package/utils/getContainingNode.js +1 -1
- package/utils/index.js +1 -0
- package/utils/isCustomProperty.js +1 -1
- package/utils/isDollarVariable.js +1 -1
- package/utils/isStandardSyntaxProperty.js +2 -2
- package/utils/validateType.js +52 -0
- package/utils/vendor.js +45 -0
- package/CHANGELOG.md +0 -111
- package/rules/properties-order/checkNode.js +0 -134
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
# stylelint-order
|
|
1
|
+
# stylelint-order
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![npm version][npm-version-img]][npm] [![npm downloads last month][npm-downloads-img]][npm]
|
|
4
|
+
|
|
5
|
+
A plugin pack of order-related linting rules for [Stylelint]. Every rule supports autofixing (`stylelint --fix`).
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
1. If you haven't, install [Stylelint]:
|
|
8
10
|
|
|
9
11
|
```
|
|
10
12
|
npm install stylelint --save-dev
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
2. Install `stylelint-order`:
|
|
14
16
|
|
|
15
17
|
```
|
|
16
18
|
npm install stylelint-order --save-dev
|
|
@@ -18,29 +20,27 @@ npm install stylelint-order --save-dev
|
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
|
-
Add `stylelint-order` to your
|
|
22
|
-
|
|
23
|
-
Like so:
|
|
23
|
+
Add `stylelint-order` to your Stylelint config `plugins` array, then add rules you need to the rules list. All rules from stylelint-order need to be namespaced with `order`.
|
|
24
24
|
|
|
25
|
-
```
|
|
26
|
-
// .stylelintrc
|
|
25
|
+
```json
|
|
27
26
|
{
|
|
28
27
|
"plugins": [
|
|
29
28
|
"stylelint-order"
|
|
30
29
|
],
|
|
31
30
|
"rules": {
|
|
32
|
-
// ...
|
|
33
31
|
"order/order": [
|
|
34
32
|
"custom-properties",
|
|
35
33
|
"declarations"
|
|
36
34
|
],
|
|
37
|
-
"order/properties-
|
|
38
|
-
|
|
35
|
+
"order/properties-order": [
|
|
36
|
+
"width",
|
|
37
|
+
"height"
|
|
38
|
+
]
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Rules
|
|
44
44
|
|
|
45
45
|
* [`order`](./rules/order/README.md): Specify the order of content within declaration blocks.
|
|
46
46
|
* [`properties-order`](./rules/properties-order/README.md): Specify the order of properties within declaration blocks.
|
|
@@ -48,41 +48,29 @@ Like so:
|
|
|
48
48
|
|
|
49
49
|
## Autofixing
|
|
50
50
|
|
|
51
|
-
Every rule
|
|
51
|
+
Every rule supports autofixing with `stylelint --fix`. [postcss-sorting] is used internally for order autofixing.
|
|
52
52
|
|
|
53
|
-
Automatic
|
|
53
|
+
Automatic sorting has some limitations that are described for every rule, if any. Please, take a look at [how comments are handled](https://github.com/hudochenkov/postcss-sorting#handling-comments) by `postcss-sorting`.
|
|
54
54
|
|
|
55
|
-
CSS-in-JS styles with template interpolation [could be ignored by autofixing](https://github.com/hudochenkov/postcss-sorting#css-in-js) to avoid
|
|
55
|
+
CSS-in-JS styles with template interpolation [could be ignored by autofixing](https://github.com/hudochenkov/postcss-sorting#css-in-js) to avoid style corruption.
|
|
56
56
|
|
|
57
|
-
Autofixing
|
|
57
|
+
Autofixing in Less syntax may work but isn't officially supported.
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"order/order": [
|
|
63
|
-
[
|
|
64
|
-
"custom-properties",
|
|
65
|
-
"declarations"
|
|
66
|
-
],
|
|
67
|
-
{
|
|
68
|
-
"disableFix": true
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
```
|
|
59
|
+
## Example configs
|
|
60
|
+
|
|
61
|
+
All these configs have `properties-order` configured with logical properties groups:
|
|
74
62
|
|
|
75
|
-
|
|
63
|
+
* [`stylelint-config-idiomatic-order`](https://github.com/ream88/stylelint-config-idiomatic-order)
|
|
64
|
+
* [`stylelint-config-hudochenkov/order`](https://github.com/hudochenkov/stylelint-config-hudochenkov/blob/master/order.js)
|
|
65
|
+
* [`stylelint-config-recess-order`](https://github.com/stormwarning/stylelint-config-recess-order)
|
|
66
|
+
* [`stylelint-config-property-sort-order-smacss`](https://github.com/cahamilton/stylelint-config-property-sort-order-smacss)
|
|
76
67
|
|
|
77
68
|
## Thanks
|
|
78
69
|
|
|
79
|
-
`properties-order` and `properties-alphabetical-order` code and
|
|
70
|
+
`properties-order` and `properties-alphabetical-order` code and README were based on the `declaration-block-properties-order` rule which was a core rule prior to Stylelint 8.0.0.
|
|
80
71
|
|
|
81
|
-
[ci-img]: https://travis-ci.org/hudochenkov/stylelint-order.svg
|
|
82
|
-
[ci]: https://travis-ci.org/hudochenkov/stylelint-order
|
|
83
72
|
[npm-version-img]: https://img.shields.io/npm/v/stylelint-order.svg
|
|
84
73
|
[npm-downloads-img]: https://img.shields.io/npm/dm/stylelint-order.svg
|
|
85
74
|
[npm]: https://www.npmjs.com/package/stylelint-order
|
|
86
|
-
|
|
87
|
-
[stylelint]: https://stylelint.io/
|
|
75
|
+
[Stylelint]: https://stylelint.io/
|
|
88
76
|
[postcss-sorting]: https://github.com/hudochenkov/postcss-sorting
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const { createPlugin } = require('stylelint');
|
|
|
2
2
|
const { namespace } = require('./utils');
|
|
3
3
|
const rules = require('./rules');
|
|
4
4
|
|
|
5
|
-
const rulesPlugins = Object.keys(rules).map(ruleName => {
|
|
5
|
+
const rulesPlugins = Object.keys(rules).map((ruleName) => {
|
|
6
6
|
return createPlugin(namespace(ruleName), rules[ruleName]);
|
|
7
7
|
});
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -1,75 +1,77 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
2
|
+
"name": "stylelint-order",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "A collection of order related linting rules for Stylelint.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"stylelint-plugin",
|
|
7
|
+
"stylelint",
|
|
8
|
+
"css",
|
|
9
|
+
"lint",
|
|
10
|
+
"order"
|
|
11
|
+
],
|
|
12
|
+
"author": "Aleks Hudochenkov <aleks@hudochenkov.com>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": "hudochenkov/stylelint-order",
|
|
15
|
+
"files": [
|
|
16
|
+
"rules",
|
|
17
|
+
"utils",
|
|
18
|
+
"!**/tests",
|
|
19
|
+
"index.js",
|
|
20
|
+
"!.DS_Store"
|
|
21
|
+
],
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"postcss": "^8.3.11",
|
|
25
|
+
"postcss-sorting": "^7.0.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"stylelint": "^14.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@stylelint/postcss-css-in-js": "^0.37.2",
|
|
32
|
+
"eslint": "^7.27.0",
|
|
33
|
+
"eslint-config-hudochenkov": "^8.0.0",
|
|
34
|
+
"eslint-config-prettier": "^8.3.0",
|
|
35
|
+
"eslint-plugin-import": "^2.25.2",
|
|
36
|
+
"eslint-plugin-jest": "^24.3.6",
|
|
37
|
+
"eslint-plugin-unicorn": "^33.0.1",
|
|
38
|
+
"husky": "^7.0.2",
|
|
39
|
+
"jest": "^27.2.5",
|
|
40
|
+
"jest-preset-stylelint": "^4.1.1",
|
|
41
|
+
"jest-watch-typeahead": "^1.0.0",
|
|
42
|
+
"lint-staged": "^11.2.3",
|
|
43
|
+
"postcss-html": "^0.36.0",
|
|
44
|
+
"postcss-less": "^5.0.0",
|
|
45
|
+
"prettier": "~2.4.1",
|
|
46
|
+
"prettier-config-hudochenkov": "^0.3.0",
|
|
47
|
+
"stylelint": "^14.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"pretest": "eslint . --max-warnings=0 && prettier '**/*.js' --check",
|
|
51
|
+
"test": "jest",
|
|
52
|
+
"jest": "jest",
|
|
53
|
+
"watch": "jest --watch",
|
|
54
|
+
"coverage": "jest --coverage",
|
|
55
|
+
"fix": "eslint . --fix --max-warnings=0 && prettier '**/*.js' --write",
|
|
56
|
+
"prepare": "husky install"
|
|
57
|
+
},
|
|
58
|
+
"lint-staged": {
|
|
59
|
+
"*.js": [
|
|
60
|
+
"eslint --fix --max-warnings=0",
|
|
61
|
+
"prettier --write"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"jest": {
|
|
65
|
+
"preset": "jest-preset-stylelint",
|
|
66
|
+
"setupFiles": [
|
|
67
|
+
"./jest-setup.js"
|
|
68
|
+
],
|
|
69
|
+
"watchPlugins": [
|
|
70
|
+
"jest-watch-typeahead/filename",
|
|
71
|
+
"jest-watch-typeahead/testname"
|
|
72
|
+
],
|
|
73
|
+
"testEnvironment": "node",
|
|
74
|
+
"testRegex": ".*\\.test\\.js$|rules/.*/tests/.*\\.js$"
|
|
75
|
+
},
|
|
76
|
+
"prettier": "prettier-config-hudochenkov"
|
|
75
77
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const postcss = require('postcss');
|
|
2
1
|
const shorthandData = require('./shorthandData');
|
|
2
|
+
const { vendor } = require('../utils');
|
|
3
3
|
|
|
4
4
|
function isShorthand(a, b) {
|
|
5
5
|
const longhands = shorthandData[a] || [];
|
|
@@ -22,8 +22,8 @@ module.exports = function checkAlphabeticalOrder(firstPropData, secondPropData)
|
|
|
22
22
|
if (firstPropData.unprefixedName === secondPropData.unprefixedName) {
|
|
23
23
|
// If first property has no prefix and second property has prefix
|
|
24
24
|
if (
|
|
25
|
-
!
|
|
26
|
-
|
|
25
|
+
!vendor.prefix(firstPropData.name).length &&
|
|
26
|
+
vendor.prefix(secondPropData.name).length
|
|
27
27
|
) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|