Skip to content

Commit 7eef0ea

Browse files
committed
Improve rule "prefer-shorthand-css-notations"
1 parent 50fceea commit 7eef0ea

19 files changed

+357
-1427
lines changed

eslint-plugin/README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,18 @@ Add `@ecocode` to the `plugins` section of your `.eslintrc`, followed by rules c
5656
⚠️ Configurations set to warn in.\
5757
✅ Set in the `recommended` configuration.
5858

59-
| Name | Description | ⚠️ |
60-
|:-------------------------------------------------------------------------------------------------------------| :--------------------------------------------------------- | :- |
61-
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations ||
62-
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications. ||
63-
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query ||
64-
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute ||
65-
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
66-
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
67-
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once. ||
68-
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination. ||
69-
| [prefer-shorthand-css-notations-animation](docs/rules/prefer-shorthand-css-notations-animation.md) | Encourage usage of shorthand CSS notations ||
70-
| [prefer-shorthand-css-notations-content](docs/rules/prefer-shorthand-css-notations-content.md) | Encourage usage of shorthand CSS notations ||
71-
| [prefer-shorthand-css-notations-layout](docs/rules/prefer-shorthand-css-notations-layout.md) | Encourage usage of shorthand CSS notations ||
72-
| [prefer-shorthand-css-notations-margin-padding](docs/rules/prefer-shorthand-css-notations-margin-padding.md) | Encourage usage of shorthand CSS notations ||
73-
| [prefer-shorthand-css-notations-text](docs/rules/prefer-shorthand-css-notations-text.md) | Encourage usage of shorthand CSS notations ||
74-
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet ||
59+
| Name | Description | ⚠️ |
60+
| :------------------------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
61+
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations ||
62+
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications. ||
63+
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query ||
64+
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute ||
65+
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
66+
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
67+
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once. ||
68+
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination. ||
69+
| [prefer-shorthand-css-notations](docs/rules/prefer-shorthand-css-notations.md) | Encourage usage of shorthand CSS notations ||
70+
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet ||
7571

7672
<!-- end auto-generated rules list -->
7773

eslint-plugin/docs/rules/prefer-shorthand-css-notations-animation.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

eslint-plugin/docs/rules/prefer-shorthand-css-notations-content.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

eslint-plugin/docs/rules/prefer-shorthand-css-notations-layout.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

eslint-plugin/docs/rules/prefer-shorthand-css-notations-margin-padding.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

eslint-plugin/docs/rules/prefer-shorthand-css-notations-text.md

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Encourage usage of shorthand CSS notations (`@ecocode/prefer-shorthand-css-notations`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Rule Details
8+
9+
This rule aims to encourage the use of shorthand CSS notations to reduce stylesheets size.
10+
11+
## Options
12+
13+
You can disable specific properties from being scanned if it does not match your needs.
14+
To disable properties you need to modify your .eslintrc.js by adding the following rule configuration:
15+
16+
```js
17+
module.exports = {
18+
...yourConf,
19+
rules: {
20+
"prefer-shorthand-css-notations": [
21+
"warn",
22+
// disable analyze of "animation-*" properties
23+
{ disableProperties: ["animation"] },
24+
],
25+
},
26+
};
27+
```
28+
29+
## Examples
30+
31+
Examples of **non-compliant** code for this rule:
32+
33+
```js
34+
<div
35+
style={{
36+
marginTop: "1em",
37+
marginRight: 0,
38+
marginBottom: "2em",
39+
marginLeft: "0.5em",
40+
}}
41+
>
42+
{/* Your content here */}
43+
</div>
44+
```
45+
46+
```js
47+
<div
48+
style={{
49+
transitionProperty: "width",
50+
transitionDuration: "35s",
51+
transitionTimingFunction: "ease-in-out",
52+
transitionDelay: "0s",
53+
}}
54+
>
55+
{/* Your content here */}
56+
</div>
57+
```
58+
59+
Examples of **compliant** code for this rule:
60+
61+
```js
62+
<div style={{ margin: "1em 0 2em 0.5em" }}>{/* Your content here */}</div>
63+
```
64+
65+
```js
66+
<div style={{ transition: "width 35s ease-in-out 0s" }}>
67+
{/* Your content here */}
68+
</div>
69+
```
70+
71+
## Further reading
72+
73+
- [cnumr/best-practices/Use abbreviated CSS notations](https://github.com/cnumr/best-practices/blob/fc5a1f865bafb196e4775cce8835393751d40ed8/chapters/BP_026_en.md)

eslint-plugin/lib/rules/prefer-shorthand-css-notations-animation.js

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)