Skip to content

Commit 0f498a3

Browse files
committed
AG-41163 Add support for NOT_VALIDATE hint
Squashed commit of the following: commit a682008 Author: Adam Wróblewski <adam@adguard.com> Date: Mon Mar 31 12:24:25 2025 +0200 Update changelog commit 517626b Author: Adam Wróblewski <adam@adguard.com> Date: Mon Mar 31 12:00:35 2025 +0200 Add support for NOT_VALIDATE hint
1 parent c5e1510 commit 0f498a3

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ The format is based on [Keep a Changelog][keepachangelog], and this project adhe
88
[keepachangelog]: https://keepachangelog.com/en/1.0.0/
99
[semver]: https://semver.org/spec/v2.0.0.html
1010

11+
## [2.1.4] - 2025-03-31
12+
13+
### Added
14+
15+
- Support for `!+ NOT_VALIDATE` hint [#248].
16+
17+
[2.1.4]: https://github.com/AdguardTeam/AGLint/compare/v2.1.3...v2.1.4
18+
[#248]: https://github.com/AdguardTeam/AGLint/issues/248
19+
1120
## [2.1.3] - 2024-12-19
1221

1322
## Added

src/linter/rules/unknown-hints-and-platforms.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { SEVERITY } from '../severity';
66
const NOT_OPTIMIZED = 'NOT_OPTIMIZED';
77
const PLATFORM = 'PLATFORM';
88
const NOT_PLATFORM = 'NOT_PLATFORM';
9+
const NOT_VALIDATE = 'NOT_VALIDATE';
910

1011
// https://adguard.com/kb/general/ad-filtering/create-own-filters/#hints
1112
const KNOWN_HINTS = new Set([
1213
NOT_OPTIMIZED,
1314
PLATFORM,
1415
NOT_PLATFORM,
16+
NOT_VALIDATE,
1517
]);
1618

1719
// https://adguard.com/kb/general/ad-filtering/create-own-filters/#platform-and-not_platform-hints
@@ -71,7 +73,7 @@ export const UnknownHintsAndPlatforms: LinterRule = {
7173
}
7274
}
7375
}
74-
} else if (hint.name.value === NOT_OPTIMIZED) {
76+
} else if (hint.name.value === NOT_OPTIMIZED || hint.name.value === NOT_VALIDATE) {
7577
// If the hint has any parameters, it's invalid, including "NOT_OPTIMIZED()"
7678
if (hint.params) {
7779
context.report({

test/linter/rules/unknown-hints-and-platforms.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ describe('unknown-hints-and-platforms', () => {
1414
// NOT_OPTIMIZED
1515
expect(linter.lint('!+ NOT_OPTIMIZED')).toMatchObject({ problems: [] });
1616

17+
// NOT_VALIDATE
18+
expect(linter.lint('!+ NOT_VALIDATE')).toMatchObject({ problems: [] });
19+
1720
// PLATFORM single
1821
expect(linter.lint('!+ PLATFORM(windows)')).toMatchObject({ problems: [] });
1922
expect(linter.lint('!+ PLATFORM(mac)')).toMatchObject({ problems: [] });
@@ -135,6 +138,81 @@ describe('unknown-hints-and-platforms', () => {
135138
],
136139
});
137140

141+
// syntax error
142+
expect(linter.lint('!+ NOT_VALIDATE(')).toMatchObject({
143+
problems: [
144+
{
145+
severity: 3,
146+
// eslint-disable-next-line max-len
147+
message: 'Cannot parse adblock rule due to the following error: Missing closing parenthesis for hint "NOT_VALIDATE"',
148+
position: {
149+
startColumn: 3,
150+
endColumn: 16,
151+
},
152+
},
153+
],
154+
});
155+
156+
// NOT_VALIDATE should not have parameters
157+
expect(linter.lint('!+ NOT_VALIDATE()')).toMatchObject({
158+
problems: [
159+
{
160+
rule: 'unknown-hints-and-platforms',
161+
severity: 2,
162+
message: 'Hint "NOT_VALIDATE" must not have any parameters',
163+
position: {
164+
startColumn: 3,
165+
endColumn: 17,
166+
},
167+
},
168+
],
169+
});
170+
171+
// NOT_VALIDATE should not have parameters
172+
expect(linter.lint('!+ NOT_VALIDATE(aa)')).toMatchObject({
173+
problems: [
174+
{
175+
rule: 'unknown-hints-and-platforms',
176+
severity: 2,
177+
message: 'Hint "NOT_VALIDATE" must not have any parameters',
178+
position: {
179+
startColumn: 3,
180+
endColumn: 19,
181+
},
182+
},
183+
],
184+
});
185+
186+
// NOT_VALIDATE should not have parameters
187+
expect(linter.lint('!+ NOT_VALIDATE(aa, bb)')).toMatchObject({
188+
problems: [
189+
{
190+
rule: 'unknown-hints-and-platforms',
191+
severity: 2,
192+
message: 'Hint "NOT_VALIDATE" must not have any parameters',
193+
position: {
194+
startColumn: 3,
195+
endColumn: 23,
196+
},
197+
},
198+
],
199+
});
200+
201+
// Hint name is case-sensitive
202+
expect(linter.lint('!+ not_validate')).toMatchObject({
203+
problems: [
204+
{
205+
rule: 'unknown-hints-and-platforms',
206+
severity: 2,
207+
message: 'Unknown hint name "not_validate"',
208+
position: {
209+
startColumn: 3,
210+
endColumn: 15,
211+
},
212+
},
213+
],
214+
});
215+
138216
// Syntax error
139217
expect(linter.lint('!+ PLATFORM(')).toMatchObject({
140218
problems: [

0 commit comments

Comments
 (0)