@codelaw/rules-css 0.0.0-stage → 0.1.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 +23 -0
- package/NOTICE +45 -0
- package/README.md +181 -2
- package/codelaw-pack.toml +6 -0
- package/data/css/at-rules.json +97 -0
- package/data/css/deprecated.json +178 -0
- package/data/css/descriptors.json +121 -0
- package/data/css/functions.json +49 -0
- package/data/css/keywords.json +332 -0
- package/data/css/media.json +271 -0
- package/data/css/prefixed.json +266 -0
- package/data/css/properties-groups.json +183 -0
- package/data/css/properties.json +1326 -0
- package/data/css/property-keywords.json +394 -0
- package/data/css/selectors.json +281 -0
- package/data/css/shorthands.json +351 -0
- package/data/css/type-selectors.json +447 -0
- package/data/css/units.json +123 -0
- package/package.json +14 -4
- package/presets/css/conventions.toml +4 -0
- package/presets/css/recommended.toml +44 -0
- package/presets/css/standard.toml +31 -0
- package/rules/css/alpha-value-notation.cases.md +37 -0
- package/rules/css/alpha-value-notation.md +44 -0
- package/rules/css/annotation-no-unknown.md +44 -0
- package/rules/css/at-rule-descriptor-no-unknown.md +46 -0
- package/rules/css/at-rule-descriptor-value-no-unknown.md +50 -0
- package/rules/css/at-rule-no-deprecated.cases.md +13 -0
- package/rules/css/at-rule-no-deprecated.md +47 -0
- package/rules/css/at-rule-no-unknown.cases.md +25 -0
- package/rules/css/at-rule-no-unknown.md +49 -0
- package/rules/css/at-rule-no-vendor-prefix.md +44 -0
- package/rules/css/at-rule-prelude-no-invalid.md +52 -0
- package/rules/css/block-no-redundant-nested-style-rules.md +40 -0
- package/rules/css/color-function-alias-notation.md +42 -0
- package/rules/css/color-function-notation.md +42 -0
- package/rules/css/color-hex-length.cases.md +13 -0
- package/rules/css/color-hex-length.md +41 -0
- package/rules/css/comment-no-empty.md +38 -0
- package/rules/css/container-name-pattern.md +45 -0
- package/rules/css/custom-media-pattern.md +41 -0
- package/rules/css/custom-property-no-missing-var-function.cases.md +61 -0
- package/rules/css/custom-property-no-missing-var-function.md +46 -0
- package/rules/css/custom-property-pattern.md +45 -0
- package/rules/css/declaration-block-no-duplicate-custom-properties.md +44 -0
- package/rules/css/declaration-block-no-duplicate-properties.cases.md +61 -0
- package/rules/css/declaration-block-no-duplicate-properties.md +44 -0
- package/rules/css/declaration-block-no-redundant-longhand-properties.md +49 -0
- package/rules/css/declaration-block-no-shorthand-property-overrides.md +44 -0
- package/rules/css/declaration-property-value-keyword-no-deprecated.md +40 -0
- package/rules/css/declaration-property-value-no-unknown.cases.md +16 -0
- package/rules/css/declaration-property-value-no-unknown.md +46 -0
- package/rules/css/font-family-no-duplicate-names.cases.md +31 -0
- package/rules/css/font-family-no-duplicate-names.md +37 -0
- package/rules/css/font-family-no-missing-generic-family-keyword.cases.md +62 -0
- package/rules/css/font-family-no-missing-generic-family-keyword.md +44 -0
- package/rules/css/function-calc-no-unspaced-operator.cases.md +33 -0
- package/rules/css/function-calc-no-unspaced-operator.md +42 -0
- package/rules/css/hue-degree-notation.md +41 -0
- package/rules/css/import-notation.md +37 -0
- package/rules/css/keyframe-block-no-duplicate-selectors.md +54 -0
- package/rules/css/keyframe-declaration-no-important.md +50 -0
- package/rules/css/keyframe-selector-notation.md +61 -0
- package/rules/css/keyframes-name-pattern.md +49 -0
- package/rules/css/layer-name-pattern.md +41 -0
- package/rules/css/length-zero-no-unit.cases.md +41 -0
- package/rules/css/length-zero-no-unit.md +39 -0
- package/rules/css/lightness-notation.md +41 -0
- package/rules/css/media-feature-name-no-unknown.md +48 -0
- package/rules/css/media-feature-name-no-vendor-prefix.md +50 -0
- package/rules/css/media-feature-name-value-no-unknown.md +46 -0
- package/rules/css/media-feature-range-notation.cases.md +61 -0
- package/rules/css/media-feature-range-notation.md +45 -0
- package/rules/css/media-query-no-invalid.cases.md +60 -0
- package/rules/css/media-query-no-invalid.md +48 -0
- package/rules/css/media-type-no-deprecated.md +48 -0
- package/rules/css/named-grid-areas-no-invalid.md +47 -0
- package/rules/css/nesting-selector-no-missing-scoping-root.md +44 -0
- package/rules/css/no-descending-specificity.cases.md +69 -0
- package/rules/css/no-descending-specificity.md +57 -0
- package/rules/css/no-duplicate-at-import-rules.md +35 -0
- package/rules/css/no-duplicate-selector.cases.md +67 -0
- package/rules/css/no-duplicate-selector.md +48 -0
- package/rules/css/no-empty-block.cases.md +42 -0
- package/rules/css/no-empty-block.md +42 -0
- package/rules/css/no-empty-source.md +40 -0
- package/rules/css/no-important.md +43 -0
- package/rules/css/no-invalid-double-slash-comments.md +44 -0
- package/rules/css/no-invalid-position-at-import-rule.md +48 -0
- package/rules/css/no-invalid-position-declaration.cases.md +35 -0
- package/rules/css/no-invalid-position-declaration.md +40 -0
- package/rules/css/no-irregular-whitespace.md +38 -0
- package/rules/css/no-unknown-property.cases.md +53 -0
- package/rules/css/no-unknown-property.md +45 -0
- package/rules/css/number-max-precision.md +41 -0
- package/rules/css/property-no-deprecated.md +40 -0
- package/rules/css/property-no-vendor-prefix.md +40 -0
- package/rules/css/selector-anb-no-unmatchable.md +42 -0
- package/rules/css/selector-class-pattern.md +45 -0
- package/rules/css/selector-id-pattern.md +45 -0
- package/rules/css/selector-no-vendor-prefix.md +40 -0
- package/rules/css/selector-not-notation.md +42 -0
- package/rules/css/selector-pseudo-class-no-unknown.cases.md +53 -0
- package/rules/css/selector-pseudo-class-no-unknown.md +44 -0
- package/rules/css/selector-pseudo-element-colon-notation.cases.md +13 -0
- package/rules/css/selector-pseudo-element-colon-notation.md +41 -0
- package/rules/css/selector-pseudo-element-no-unknown.md +44 -0
- package/rules/css/selector-type-no-unknown.cases.md +41 -0
- package/rules/css/selector-type-no-unknown.md +45 -0
- package/rules/css/shorthand-property-no-redundant-values.cases.md +34 -0
- package/rules/css/shorthand-property-no-redundant-values.md +37 -0
- package/rules/css/string-no-newline.cases.md +27 -0
- package/rules/css/string-no-newline.md +45 -0
- package/rules/css/syntax-string-no-invalid.md +46 -0
- package/rules/css/value-no-vendor-prefix.md +40 -0
- package/rules/graph/no-unused-css-classes.md +55 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-id-pattern
|
|
3
|
+
title: "Id selectors are kebab-case"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "renaming must update the markup and scripts that use the id"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
pattern: { type: "string", default: "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$", description: "a regular expression names must match" }
|
|
10
|
+
ported_from: [stylelint/selector-id-pattern]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Ids in selectors match a pattern, kebab-case by default.
|
|
15
|
+
|
|
16
|
+
**Why:** A consistent naming scheme makes names predictable across a codebase.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/selector-id-pattern
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Rename the id to match the pattern.
|
|
25
|
+
2. Update the markup and scripts that use it.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### CSS
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
#mainNav {
|
|
35
|
+
color: red;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Do
|
|
40
|
+
|
|
41
|
+
```css
|
|
42
|
+
#main-nav {
|
|
43
|
+
color: red;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-no-vendor-prefix
|
|
3
|
+
title: "No vendor-prefixed selectors"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "browsers that need the prefix lose the rule"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignoreSelectors: { type: "string[]", default: [], description: "selectors to accept; `/regex/` for a pattern" }
|
|
10
|
+
ported_from: [stylelint/selector-no-vendor-prefix]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Pseudo-classes and pseudo-elements a build tool prefixes, such as `::-moz-placeholder`, are written without the prefix.
|
|
15
|
+
|
|
16
|
+
**Why:** Prefixing is a build step; hand-written prefixes go stale and duplicate code.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/selector-no-vendor-prefix
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
### CSS
|
|
25
|
+
|
|
26
|
+
#### Don't
|
|
27
|
+
|
|
28
|
+
```css
|
|
29
|
+
input::-moz-placeholder {
|
|
30
|
+
color: gray;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Do
|
|
35
|
+
|
|
36
|
+
```css
|
|
37
|
+
input::placeholder {
|
|
38
|
+
color: gray;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-not-notation
|
|
3
|
+
title: "One `:not()` with a list"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "the merged form has a lower specificity, which can change which rule wins"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [stylelint/selector-not-notation]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Adjacent `:not()` pseudo-classes are written as one `:not()` with a selector list: `:not(.a, .b)`.
|
|
13
|
+
|
|
14
|
+
**Why:** Selectors level 4 takes a list in `:not()`; one call reads more simply.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: css/selector-not-notation
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Examples
|
|
21
|
+
|
|
22
|
+
### CSS
|
|
23
|
+
|
|
24
|
+
#### Don't
|
|
25
|
+
|
|
26
|
+
```css
|
|
27
|
+
a:not(.active):not(.disabled) {
|
|
28
|
+
color: gray;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Do
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
a:not(.active, .disabled) {
|
|
36
|
+
color: gray;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Differences from the source
|
|
41
|
+
|
|
42
|
+
Ported with stylelint-config-standard's setting, `complex`.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Cases: css/selector-pseudo-class-no-unknown
|
|
2
|
+
|
|
3
|
+
### case: scrollbar states after a vendor pseudo-element
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
::-webkit-scrollbar-thumb:horizontal {
|
|
7
|
+
color: red;
|
|
8
|
+
}
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```expect
|
|
12
|
+
(none)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### case: page pseudo-classes in @page
|
|
16
|
+
|
|
17
|
+
```css
|
|
18
|
+
@page :first {
|
|
19
|
+
margin: 1in;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```expect
|
|
24
|
+
(none)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### case: a pseudo-element with one colon
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
::selection {
|
|
31
|
+
color: red;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:selection {
|
|
35
|
+
color: red;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```expect
|
|
40
|
+
5:1 css/selector-pseudo-class-no-unknown
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### case: vendor-prefixed pseudo-classes are skipped
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
a:-moz-focusring {
|
|
47
|
+
color: red;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```expect
|
|
52
|
+
(none)
|
|
53
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-pseudo-class-no-unknown
|
|
3
|
+
title: "No unknown pseudo-classes"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the intended pseudo-class is the author's call"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignorePseudoClasses: { type: "string[]", default: [], description: "pseudo-classes to accept; `/regex/` for a pattern" }
|
|
10
|
+
ported_from: [stylelint/selector-pseudo-class-no-unknown]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Every pseudo-class is one the specifications define, and pseudo-elements are written with `::`. Vendor-prefixed pseudo-classes are skipped; in `@page`, only page pseudo-classes are allowed.
|
|
15
|
+
|
|
16
|
+
**Why:** A browser drops a whole rule whose selector has a pseudo-class it does not know.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/selector-pseudo-class-no-unknown
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Correct the pseudo-class name.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
### CSS
|
|
29
|
+
|
|
30
|
+
#### Don't
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
a:hovr {
|
|
34
|
+
color: red;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```css
|
|
41
|
+
a:hover {
|
|
42
|
+
color: red;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-pseudo-element-colon-notation
|
|
3
|
+
title: "Pseudo-elements with `::`"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: auto
|
|
6
|
+
stability: preview
|
|
7
|
+
ported_from: [stylelint/selector-pseudo-element-colon-notation]
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
The pseudo-elements `::before`, `::after`, `::first-line` and `::first-letter` are written with two colons.
|
|
12
|
+
|
|
13
|
+
**Why:** Two colons tell pseudo-elements from pseudo-classes; the one-colon form exists only for CSS 2 compatibility.
|
|
14
|
+
|
|
15
|
+
```codelaw
|
|
16
|
+
native: css/selector-pseudo-element-colon-notation
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
### CSS
|
|
22
|
+
|
|
23
|
+
#### Don't
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
a:before {
|
|
27
|
+
content: "";
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Do
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
a::before {
|
|
35
|
+
content: "";
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Differences from the source
|
|
40
|
+
|
|
41
|
+
Ported with stylelint-config-standard's setting, `double`.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-pseudo-element-no-unknown
|
|
3
|
+
title: "No unknown pseudo-elements"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the intended pseudo-element is the author's call"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignorePseudoElements: { type: "string[]", default: [], description: "pseudo-elements to accept; `/regex/` for a pattern" }
|
|
10
|
+
ported_from: [stylelint/selector-pseudo-element-no-unknown]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Every `::` pseudo-element is one the specifications define. Vendor-prefixed ones are skipped.
|
|
15
|
+
|
|
16
|
+
**Why:** A browser drops a whole rule whose selector has a pseudo-element it does not know.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/selector-pseudo-element-no-unknown
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Correct the pseudo-element name.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
### CSS
|
|
29
|
+
|
|
30
|
+
#### Don't
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
a::befor {
|
|
34
|
+
content: "";
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```css
|
|
41
|
+
a::before {
|
|
42
|
+
content: "";
|
|
43
|
+
}
|
|
44
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Cases: css/selector-type-no-unknown
|
|
2
|
+
|
|
3
|
+
### case: custom elements and namespaces
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
my-element,
|
|
7
|
+
svg|rect,
|
|
8
|
+
foreignObject {
|
|
9
|
+
color: red;
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```expect
|
|
14
|
+
(none)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### case: keyframe selectors are not type selectors
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
@keyframes fade {
|
|
21
|
+
from {
|
|
22
|
+
opacity: 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```expect
|
|
28
|
+
(none)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### case: inside :is()
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
:is(tabel, div) {
|
|
35
|
+
color: red;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```expect
|
|
40
|
+
1:5 css/selector-type-no-unknown
|
|
41
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/selector-type-no-unknown
|
|
3
|
+
title: "No unknown type selectors"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the intended element is the author's call"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignore: { type: "string[]", default: ["custom-elements"], description: "`custom-elements` allows hyphenated names; `default-namespace` skips un-namespaced types" }
|
|
10
|
+
ignoreTypes: { type: "string[]", default: [], description: "type selectors to accept; `/regex/` for a pattern" }
|
|
11
|
+
ported_from: [stylelint/selector-type-no-unknown]
|
|
12
|
+
since: 0.1.0
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Every type selector is an HTML, SVG or MathML element. Custom elements (a hyphenated lowercase name) are allowed by default, and namespaced selectors are skipped.
|
|
16
|
+
|
|
17
|
+
**Why:** A misspelt element name matches nothing.
|
|
18
|
+
|
|
19
|
+
```codelaw
|
|
20
|
+
native: css/selector-type-no-unknown
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. Correct the element name.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### CSS
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
tabel {
|
|
35
|
+
border-collapse: collapse;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Do
|
|
40
|
+
|
|
41
|
+
```css
|
|
42
|
+
table {
|
|
43
|
+
border-collapse: collapse;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Cases: css/shorthand-property-no-redundant-values
|
|
2
|
+
|
|
3
|
+
### case: four sides that pair up
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
a {
|
|
7
|
+
padding: 1px 2px 1px 2px;
|
|
8
|
+
border-radius: 4px 4px / 2px 2px;
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```expect
|
|
13
|
+
2:12 css/shorthand-property-no-redundant-values
|
|
14
|
+
3:18 css/shorthand-property-no-redundant-values
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```fixed
|
|
18
|
+
a {
|
|
19
|
+
padding: 1px 2px;
|
|
20
|
+
border-radius: 4px / 2px;
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### case: values with var() can expand
|
|
25
|
+
|
|
26
|
+
```css
|
|
27
|
+
a {
|
|
28
|
+
margin: var(--x) var(--x);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```expect
|
|
33
|
+
(none)
|
|
34
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/shorthand-property-no-redundant-values
|
|
3
|
+
title: "No repeated values in shorthands"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: auto
|
|
6
|
+
stability: preview
|
|
7
|
+
ported_from: [stylelint/shorthand-property-no-redundant-values]
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Box shorthands such as `margin`, `padding`, `inset`, `gap` and `border-radius` give no value the shorthand would repeat anyway: `margin: 1px`, not `margin: 1px 1px`.
|
|
12
|
+
|
|
13
|
+
**Why:** The shorter form says the same thing.
|
|
14
|
+
|
|
15
|
+
```codelaw
|
|
16
|
+
native: css/shorthand-property-no-redundant-values
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
### CSS
|
|
22
|
+
|
|
23
|
+
#### Don't
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
a {
|
|
27
|
+
margin: 1px 1px;
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Do
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
a {
|
|
35
|
+
margin: 1px;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Cases: css/string-no-newline
|
|
2
|
+
|
|
3
|
+
### case: an escaped line break
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
[title="one\
|
|
7
|
+
two"] {
|
|
8
|
+
color: red;
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```expect
|
|
13
|
+
(none)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### case: values are not checked by default
|
|
17
|
+
|
|
18
|
+
```css
|
|
19
|
+
a {
|
|
20
|
+
content: "one
|
|
21
|
+
two";
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```expect
|
|
26
|
+
(none)
|
|
27
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/string-no-newline
|
|
3
|
+
title: "No line breaks inside selector strings"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "whether the line break was meant is the author's call"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignore: { type: "string[]", default: ["at-rule-preludes", "declaration-values"], description: "contexts not to check: `at-rule-preludes`, `declaration-values`" }
|
|
10
|
+
ported_from: [stylelint/string-no-newline]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
A string in a selector does not contain an unescaped line break. With the default options, strings in at-rule preludes and declaration values are not checked.
|
|
15
|
+
|
|
16
|
+
**Why:** A raw line break ends a CSS string early, so the selector is invalid and the rule is dropped.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/string-no-newline
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Join the string onto one line, or escape the line break as `\A`.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
### CSS
|
|
29
|
+
|
|
30
|
+
#### Don't
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
[title="one
|
|
34
|
+
two"] {
|
|
35
|
+
color: red;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Do
|
|
40
|
+
|
|
41
|
+
```css
|
|
42
|
+
[title="one two"] {
|
|
43
|
+
color: red;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/syntax-string-no-invalid
|
|
3
|
+
title: "`@property` syntax strings are valid"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the intended type is the author's call"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [stylelint/syntax-string-no-invalid]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
The `syntax` of a `@property` rule is `"*"` or a `|`-separated list of supported `<type>` names and keywords, each with an optional `+` or `#`.
|
|
13
|
+
|
|
14
|
+
**Why:** A browser ignores a `@property` rule whose syntax is invalid, so the custom property is not registered.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: css/syntax-string-no-invalid
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## How to fix
|
|
21
|
+
|
|
22
|
+
1. Use a supported type name such as `<length>`, `<color>` or `<number>`.
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
### CSS
|
|
27
|
+
|
|
28
|
+
#### Don't
|
|
29
|
+
|
|
30
|
+
```css
|
|
31
|
+
@property --size {
|
|
32
|
+
syntax: "<size>";
|
|
33
|
+
inherits: false;
|
|
34
|
+
initial-value: 0px;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Do
|
|
39
|
+
|
|
40
|
+
```css
|
|
41
|
+
@property --size {
|
|
42
|
+
syntax: "<length>";
|
|
43
|
+
inherits: false;
|
|
44
|
+
initial-value: 0px;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: css/value-no-vendor-prefix
|
|
3
|
+
title: "No vendor-prefixed values"
|
|
4
|
+
languages: [css]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "browsers that need the prefix lose the value"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignoreValues: { type: "string[]", default: ["box", "inline-box"], description: "values to accept, without their prefix; `/regex/` for a pattern" }
|
|
10
|
+
ported_from: [stylelint/value-no-vendor-prefix]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Values a build tool prefixes, such as `-webkit-flex` or `-moz-calc()`, are written without the prefix. `-webkit-box` and `-webkit-inline-box` are allowed, as line clamping still needs them.
|
|
15
|
+
|
|
16
|
+
**Why:** Prefixing is a build step; hand-written prefixes go stale and duplicate code.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: css/value-no-vendor-prefix
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
### CSS
|
|
25
|
+
|
|
26
|
+
#### Don't
|
|
27
|
+
|
|
28
|
+
```css
|
|
29
|
+
a {
|
|
30
|
+
display: -webkit-flex;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Do
|
|
35
|
+
|
|
36
|
+
```css
|
|
37
|
+
a {
|
|
38
|
+
display: flex;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: graph/no-unused-css-classes
|
|
3
|
+
title: CSS classes must be used somewhere
|
|
4
|
+
languages: [css]
|
|
5
|
+
scope: project
|
|
6
|
+
severity: warn
|
|
7
|
+
fix: suggest
|
|
8
|
+
fix_reason: "A class can be built at run time or used by markup outside the repo, so removing its rule needs a human or agent to accept the diff."
|
|
9
|
+
stability: preview
|
|
10
|
+
ported_from: [purgecss/unused-selector]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Every class a stylesheet defines appears in the project's HTML, JSX, templates or strings.
|
|
15
|
+
|
|
16
|
+
**Why:** a rule for a class no markup uses is dead weight every page downloads, and it makes the stylesheet harder to change safely.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
graph:
|
|
20
|
+
class:
|
|
21
|
+
defined_in: css
|
|
22
|
+
message: "`.$CLASS` is defined in `$FILE` but nothing in the project uses it"
|
|
23
|
+
fix:
|
|
24
|
+
- else:
|
|
25
|
+
do: [remove-rule]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## How to fix
|
|
29
|
+
|
|
30
|
+
1. Search for the class: a name built at run time (`"btn-" + kind`) counts only through its static prefix.
|
|
31
|
+
2. If markup outside the repo uses it, add the file to `[graph] keep` or list it in the package's `style` or `exports`.
|
|
32
|
+
3. Otherwise delete the rule, or the class from its selector list.
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### CSS
|
|
37
|
+
|
|
38
|
+
#### Don't
|
|
39
|
+
|
|
40
|
+
```css files
|
|
41
|
+
/* src/styles.css */
|
|
42
|
+
.card { padding: 1rem; }
|
|
43
|
+
.legacy-banner { color: red; }
|
|
44
|
+
<!-- index.html -->
|
|
45
|
+
<div class="card"></div>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Do
|
|
49
|
+
|
|
50
|
+
```css files
|
|
51
|
+
/* src/styles.css */
|
|
52
|
+
.card { padding: 1rem; }
|
|
53
|
+
<!-- index.html -->
|
|
54
|
+
<div class="card"></div>
|
|
55
|
+
```
|