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.
Files changed (41) hide show
  1. package/README.md +26 -38
  2. package/index.js +1 -1
  3. package/package.json +75 -73
  4. package/rules/checkAlphabeticalOrder.js +3 -3
  5. package/rules/order/README.md +205 -160
  6. package/rules/order/checkNode.js +83 -32
  7. package/rules/order/checkOrder.js +35 -28
  8. package/rules/order/{createExpectedOrder.js → createOrderInfo.js} +30 -28
  9. package/rules/order/getDescription.js +6 -3
  10. package/rules/order/getOrderData.js +7 -7
  11. package/rules/order/index.js +25 -51
  12. package/rules/order/messages.js +6 -0
  13. package/rules/order/ruleName.js +3 -0
  14. package/rules/order/validatePrimaryOption.js +34 -26
  15. package/rules/properties-alphabetical-order/README.md +8 -7
  16. package/rules/properties-alphabetical-order/checkNode.js +61 -0
  17. package/rules/properties-alphabetical-order/index.js +24 -99
  18. package/rules/properties-order/README.md +232 -142
  19. package/rules/properties-order/addEmptyLineBefore.js +1 -3
  20. package/rules/properties-order/checkEmptyLineBefore.js +65 -57
  21. package/rules/properties-order/checkEmptyLineBeforeFirstProp.js +41 -0
  22. package/rules/properties-order/checkNodeForEmptyLines.js +68 -0
  23. package/rules/properties-order/checkNodeForOrder.js +92 -0
  24. package/rules/properties-order/checkOrder.js +25 -15
  25. package/rules/properties-order/createFlatOrder.js +3 -3
  26. package/rules/properties-order/{createExpectedOrder.js → createOrderInfo.js} +7 -7
  27. package/rules/properties-order/getNodeData.js +15 -15
  28. package/rules/properties-order/index.js +40 -50
  29. package/rules/properties-order/messages.js +11 -0
  30. package/rules/properties-order/ruleName.js +3 -0
  31. package/rules/properties-order/validatePrimaryOption.js +13 -13
  32. package/utils/__tests__/vendor.test.js +15 -0
  33. package/utils/getContainingNode.js +1 -1
  34. package/utils/index.js +1 -0
  35. package/utils/isCustomProperty.js +1 -1
  36. package/utils/isDollarVariable.js +1 -1
  37. package/utils/isStandardSyntaxProperty.js +2 -2
  38. package/utils/validateType.js +52 -0
  39. package/utils/vendor.js +45 -0
  40. package/CHANGELOG.md +0 -111
  41. package/rules/properties-order/checkNode.js +0 -134
package/README.md CHANGED
@@ -1,16 +1,18 @@
1
- # stylelint-order [![Build Status][ci-img]][ci] [![npm version][npm-version-img]][npm] [![npm downloads last month][npm-downloads-img]][npm]
1
+ # stylelint-order
2
2
 
3
- A plugin pack of order related linting rules for [stylelint]. Every rule support autofixing (`stylelint --fix`).
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
- First, install [stylelint]:
9
+ 1. If you haven't, install [Stylelint]:
8
10
 
9
11
  ```
10
12
  npm install stylelint --save-dev
11
13
  ```
12
14
 
13
- Then install plugin:
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 stylelint config plugins array, then add rules you need to the rules list. All rules from stylelint-order need to be namespaced with `order`.
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
- ```js
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-alphabetical-order": true
38
- // ...
35
+ "order/properties-order": [
36
+ "width",
37
+ "height"
38
+ ]
39
39
  }
40
40
  }
41
41
  ```
42
42
 
43
- ## List of rules
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 support autofixing (`stylelint --fix`). [postcss-sorting] is using internally for order autofixing.
51
+ Every rule supports autofixing with `stylelint --fix`. [postcss-sorting] is used internally for order autofixing.
52
52
 
53
- Automatic sortings has some limitation, which 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.
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 styles corruption.
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 is enabled by default if it's enabled in stylelint configuration. Autofixing can be disabled on per rule basis using `disableFix: true` secondary option. E. g.:
57
+ Autofixing in Less syntax may work but isn't officially supported.
58
58
 
59
- ```json
60
- {
61
- "rules": {
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
- Less isn't supported. It might work, but haven't tested.
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 readme are based on `declaration-block-properties-order` rule which was a stylelint's core rule prior stylelint 8.0.0.
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
- "name": "stylelint-order",
3
- "version": "3.1.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
- "bugs": {
16
- "url": "https://github.com/hudochenkov/stylelint-order/issues"
17
- },
18
- "homepage": "https://github.com/hudochenkov/stylelint-order",
19
- "engines": {
20
- "node": ">=8.7.0"
21
- },
22
- "files": [
23
- "rules",
24
- "utils",
25
- "!**/tests",
26
- "index.js",
27
- "!.DS_Store"
28
- ],
29
- "main": "index.js",
30
- "dependencies": {
31
- "lodash": "^4.17.15",
32
- "postcss": "^7.0.17",
33
- "postcss-sorting": "^5.0.1"
34
- },
35
- "peerDependencies": {
36
- "stylelint": "^10.0.1"
37
- },
38
- "devDependencies": {
39
- "eslint": "^6.2.2",
40
- "eslint-config-hudochenkov": "^3.0.1",
41
- "eslint-config-prettier": "^6.1.0",
42
- "husky": "^3.0.4",
43
- "jest": "^24.9.0",
44
- "lint-staged": "^9.2.5",
45
- "prettier": "~1.18.2",
46
- "stylelint": "^10.1.0"
47
- },
48
- "scripts": {
49
- "pretest": "eslint .",
50
- "test": "jest",
51
- "jest": "jest",
52
- "watch": "jest --watch",
53
- "coverage": "jest --coverage",
54
- "fix": "eslint . --fix && prettier '**/*.js' --write"
55
- },
56
- "lint-staged": {
57
- "*.js": [
58
- "eslint --fix",
59
- "prettier --write",
60
- "git add"
61
- ]
62
- },
63
- "jest": {
64
- "setupFiles": [
65
- "./jest-setup.js"
66
- ],
67
- "testEnvironment": "node",
68
- "testRegex": ".*\\.test\\.js$|rules/.*/tests/.*\\.js$"
69
- },
70
- "husky": {
71
- "hooks": {
72
- "pre-commit": "lint-staged"
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
- !postcss.vendor.prefix(firstPropData.name).length &&
26
- postcss.vendor.prefix(secondPropData.name).length
25
+ !vendor.prefix(firstPropData.name).length &&
26
+ vendor.prefix(secondPropData.name).length
27
27
  ) {
28
28
  return false;
29
29
  }