1 | # stylelint-order [![Build Status][ci-img]][ci] [![npm version][npm-version-img]][npm] [![npm downloads last month][npm-downloads-img]][npm]
|
2 |
|
3 | A plugin pack of order related linting rules for [stylelint]. Every rule support autofixing (`stylelint --fix`).
|
4 |
|
5 | ## Installation
|
6 |
|
7 | First, install [stylelint]:
|
8 |
|
9 | ```
|
10 | npm install stylelint --save-dev
|
11 | ```
|
12 |
|
13 | Then install plugin:
|
14 |
|
15 | ```
|
16 | npm install stylelint-order --save-dev
|
17 | ```
|
18 |
|
19 | ## Usage
|
20 |
|
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:
|
24 |
|
25 | ```js
|
26 | // .stylelintrc
|
27 | {
|
28 | "plugins": [
|
29 | "stylelint-order"
|
30 | ],
|
31 | "rules": {
|
32 | // ...
|
33 | "order/order": [
|
34 | "custom-properties",
|
35 | "declarations"
|
36 | ],
|
37 | "order/properties-alphabetical-order": true
|
38 | // ...
|
39 | }
|
40 | }
|
41 | ```
|
42 |
|
43 | ## List of rules
|
44 |
|
45 | * [`order`](./rules/order/README.md): Specify the order of content within declaration blocks.
|
46 | * [`properties-order`](./rules/properties-order/README.md): Specify the order of properties within declaration blocks.
|
47 | * [`properties-alphabetical-order`](./rules/properties-alphabetical-order/README.md): Specify the alphabetical order of properties within declaration blocks.
|
48 |
|
49 | ## Autofixing
|
50 |
|
51 | Every rule support autofixing (`stylelint --fix`). [postcss-sorting] is using internally for order autofixing.
|
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.
|
54 |
|
55 | 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.:
|
56 |
|
57 | ```json
|
58 | {
|
59 | "rules": {
|
60 | "order/order": [
|
61 | [
|
62 | "custom-properties",
|
63 | "declarations"
|
64 | ],
|
65 | {
|
66 | "disableFix": true
|
67 | }
|
68 | ]
|
69 | }
|
70 | }
|
71 | ```
|
72 |
|
73 | Less isn't supported. It might work, but haven't tested.
|
74 |
|
75 | ## Thanks
|
76 |
|
77 | `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.
|
78 |
|
79 | [ci-img]: https://travis-ci.org/hudochenkov/stylelint-order.svg
|
80 | [ci]: https://travis-ci.org/hudochenkov/stylelint-order
|
81 | [npm-version-img]: https://img.shields.io/npm/v/stylelint-order.svg
|
82 | [npm-downloads-img]: https://img.shields.io/npm/dm/stylelint-order.svg
|
83 | [npm]: https://www.npmjs.com/package/stylelint-order
|
84 |
|
85 | [stylelint]: https://stylelint.io/
|
86 | [postcss-sorting]: https://github.com/hudochenkov/postcss-sorting
|