Skip to content

Commit 2ff9c3d

Browse files
committed
AG-29460 Add no-invalid-cosmetic-separator rule
1 parent 0a55758 commit 2ff9c3d

File tree

9 files changed

+623
-0
lines changed

9 files changed

+623
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
77
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
88
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
99

10+
## [Unreleazed]
11+
12+
### Added
13+
14+
- `no-invalid-cosmetic-separator` linter rule.
15+
1016
## [4.0.0-beta.5] - 2025-12-22
1117

1218
### Added

config-presets/all.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
],
2222
"no-inconsistent-hint-platforms": "error",
23+
"no-invalid-cosmetic-separator": "error",
2324
"no-invalid-css-declaration": "error",
2425
"no-invalid-domains": "error",
2526
"no-invalid-hint-params": "error",

config-presets/recommended.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"no-duplicated-hints": "error",
88
"no-duplicated-modifiers": "error",
99
"no-inconsistent-hint-platforms": "error",
10+
"no-invalid-cosmetic-separator": "error",
1011
"no-invalid-css-declaration": "error",
1112
"no-invalid-domains": "error",
1213
"no-invalid-hint-params": "error",

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| [no-duplicated-modifiers](./no-duplicated-modifiers.md) | Checks if a network rule contains multiple same modifiers || | |
1313
| [no-excluded-rules](./no-excluded-rules.md) | Checks if any rule matches an excluded pattern | | 🔧 | |
1414
| [no-inconsistent-hint-platforms](./no-inconsistent-hint-platforms.md) | Checks if a platform targeted by a PLATFORM() hint is also excluded by a NOT_PLATFORM() hint at the same time || | |
15+
| [no-invalid-cosmetic-separator](./no-invalid-cosmetic-separator.md) | Validates that rule separator matches selector/declaration capabilities || 🔧 | 💡 |
1516
| [no-invalid-css-declaration](./no-invalid-css-declaration.md) | Checks if CSS declarations are valid || | |
1617
| [no-invalid-domains](./no-invalid-domains.md) | Disallows invalid domains || | 💡 |
1718
| [no-invalid-hint-params](./no-invalid-hint-params.md) | Checks if hints are parameterized correctly || | |
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<!-- markdownlint-disable -->
2+
# `no-invalid-cosmetic-separator`
3+
4+
> ✅ Using `aglint:recommended` preset will enable this rule
5+
6+
## Description
7+
8+
Validates that rule separator matches selector/declaration capabilities
9+
10+
## Type
11+
12+
Problem. Identifies parts that causes errors or confusing behavior. High priority fix.
13+
14+
## Automatic issue fixing
15+
16+
- Some reported problems can be fixed automatically 🔧
17+
- Some reported problems can be fixed via suggestions 💡
18+
19+
## Correct examples
20+
21+
Examples of correct code:
22+
23+
### Element hiding with extended selector
24+
25+
The following code
26+
27+
```adblock
28+
#?#div:contains(a)
29+
```
30+
31+
should not be reported
32+
33+
## Incorrect examples
34+
35+
Examples of incorrect code:
36+
37+
### Extended selector with native separator
38+
39+
The following code
40+
41+
```adblock
42+
##div:contains(a)
43+
```
44+
45+
should be reported as:
46+
47+
```shell
48+
1:2 Extended CSS is used in selector, replace "##" with "#?#"
49+
```
50+
51+
and the following suggestions should be offered:
52+
53+
- Change separator to "#?#"
54+
55+
```diff
56+
===================================================================
57+
--- original
58+
+++ fixed
59+
@@ -1,1 +1,1 @@
60+
-##div:contains(a)
61+
+#?#div:contains(a)
62+
```
63+
64+
### Extended selector nested in :has() with native separator
65+
66+
The following code
67+
68+
```adblock
69+
##div:has(> table:contains(a))
70+
```
71+
72+
should be reported as:
73+
74+
```shell
75+
1:2 Extended CSS is used in selector, replace "##" with "#?#"
76+
```
77+
78+
and the following suggestions should be offered:
79+
80+
- Change separator to "#?#"
81+
82+
```diff
83+
===================================================================
84+
--- original
85+
+++ fixed
86+
@@ -1,1 +1,1 @@
87+
-##div:has(> table:contains(a))
88+
+#?#div:has(> table:contains(a))
89+
```
90+
91+
### remove:true with native CSS injection separator
92+
93+
The following code
94+
95+
```adblock
96+
#$#a[href^="/bnlink/?bnid="] { remove: true; }
97+
```
98+
99+
should be reported as:
100+
101+
```shell
102+
1:3 Declaration { remove: true; } is allowed only with "#$?#" separator
103+
```
104+
105+
and the following suggestions should be offered:
106+
107+
- Change separator to "#$?#"
108+
109+
```diff
110+
===================================================================
111+
--- original
112+
+++ fixed
113+
@@ -1,1 +1,1 @@
114+
-#$#a[href^="/bnlink/?bnid="] { remove: true; }
115+
+#$?#a[href^="/bnlink/?bnid="] { remove: true; }
116+
```
117+
118+
## Version
119+
120+
This rule was added in AGLint version 4.0.0
121+
122+
## Rule source
123+
124+
https://github.com/AdguardTeam/AGLint/blob/master/src/rules/no-invalid-cosmetic-separator.ts
125+
126+
## Test cases
127+
128+
https://github.com/AdguardTeam/AGLint/blob/master/test/rules/no-invalid-cosmetic-separator.test.ts

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
"import": "./dist/rules/no-inconsistent-hint-platforms.js",
8989
"default": "./dist/rules/no-inconsistent-hint-platforms.js"
9090
},
91+
"./rules/no-invalid-cosmetic-separator": {
92+
"types": "./dist/rules/no-invalid-cosmetic-separator.d.ts",
93+
"import": "./dist/rules/no-invalid-cosmetic-separator.js",
94+
"default": "./dist/rules/no-invalid-cosmetic-separator.js"
95+
},
9196
"./rules/no-invalid-css-declaration": {
9297
"types": "./dist/rules/no-invalid-css-declaration.d.ts",
9398
"import": "./dist/rules/no-invalid-css-declaration.js",

0 commit comments

Comments
 (0)