Skip to content

Commit a3c68e7

Browse files
committed
AG-49411 Add no-invalid-scriptlets linter rule to validate scriptlet calls against compatibility tables
Squashed commit of the following: commit 0fe65db Merge: b0351f3 1228808 Author: scripthunter7 <d.tota@adguard.com> Date: Mon Dec 22 11:25:54 2025 +0100 Merge branch 'release/v4.0' into fix/AG-49411 commit b0351f3 Author: scripthunter7 <d.tota@adguard.com> Date: Fri Dec 19 09:48:45 2025 +0100 Add early return when offset range is unavailable in `no-invalid-scriptlets` rule fuzzy matching - Added null check for `context.getOffsetRangeForNode(node)` before processing fuzzy match suggestions - Moved range calculation before fuzzy matching logic to avoid unnecessary processing - Changed `fixer.replaceWithText` to use validated range instead of `[node.start!, node.end!]` - Prevents potential errors when node offset range cannot be determined commit 2d21efc Author: scripthunter7 <d.tota@adguard.com> Date: Fri Dec 19 09:42:30 2025 +0100 Fix off-by-one error in parameter count validation for scriptlets without parameters in `no-invalid-scriptlets` rule - Changed condition from `parameterIndex > 1` to `parameterIndex > 0` when checking for extra parameters - Ensures scriptlets with no defined parameters correctly reject any parameters beyond scriptlet name - Fixes duplicate error reporting where first parameter was incorrectly validated twice - Updated documentation example to show correct single error for missing 'property' parameter commit 52f58d3 Author: scripthunter7 <d.tota@adguard.com> Date: Fri Dec 19 09:41:18 2025 +0100 Fix off-by-one error in parameter validation loop in `no-invalid-scriptlets` rule - Moved `i += 1` before `nextParameterData = scriptletData.parameters[i]` assignment - Ensures nextParameterData correctly references the next parameter after incrementing index - Prevents accessing wrong parameter data when validating scriptlet parameters commit 28ec229 Author: scripthunter7 <d.tota@adguard.com> Date: Thu Dec 18 23:37:09 2025 +0100 Add quote preservation to fuzzy matching suggestions in `no-invalid-scriptlets` rule - Modified changeScriptlet fix to preserve original quote type from scriptlet name - Added actualQuote variable to capture quote type using QuoteUtils.getStringQuoteType - Updated fixer.replaceWithText to apply original quote type to suggested scriptlet name using QuoteUtils.setStringQuoteType - Ensures suggested scriptlet replacements maintain consistent quote style with original code commit 3ed095a Author: scripthunter7 <d.tota@adguard.com> Date: Thu Dec 18 14:42:16 2025 +0100 Add scriptlet alias support to fuzzy matching in `no-invalid-scriptlets` rule - Modified getScriptletNames to include both scriptlet names and their aliases when building name cache - Changed from simple map to flatMap to handle scriptlets with and without aliases - Ensures fuzzy matching suggestions include scriptlet aliases as valid alternatives - Maintains Set deduplication to prevent duplicate names in cache commit ab5ab6e Author: scripthunter7 <d.tota@adguard.com> Date: Thu Dec 18 13:58:03 2025 +0100 Add cache cleanup for nameCache in `no-invalid-scriptlets` rule to prevent memory leaks - Added nameCache.clear() call in FilterList:exit handler alongside existing regexCache.clear() - Ensures scriptlet name cache is properly cleared after processing each filter list - Prevents potential memory accumulation when linting multiple files commit 559e365 Author: scripthunter7 <d.tota@adguard.com> Date: Thu Dec 18 13:52:03 2025 +0100 Add fuzzy matching suggestions for unknown scriptlets in `no-invalid-scriptlets` rule - Implemented fuzzy matching using fast-fuzzy library to suggest similar scriptlet names when unknown scriptlet is detected - Added configurable `fuzzyThreshold` option (default 0.6) to control minimum similarity threshold for suggestions - Added `changeScriptlet` message ID and suggestion fixes that replace unknown scriptlet with suggested alternatives - Cached scriptlet names per platform to optimize fuzzy search commit 9054078 Author: scripthunter7 <d.tota@adguard.com> Date: Thu Dec 18 13:28:41 2025 +0100 Add `no-invalid-scriptlets` linter rule to validate scriptlet calls against compatibility tables - Created new rule that checks scriptlet validity based on scriptletsCompatibilityTable from @adguard/agtree - Validates scriptlet names exist for target platform (AdGuard/uBlock Origin/Adblock Plus) - Checks required parameters are present and validates parameter values against regex patterns when defined - Reports errors for unknown scriptlets, missing required parameters, extra parameters, and invali
1 parent 1228808 commit a3c68e7

File tree

7 files changed

+1123
-0
lines changed

7 files changed

+1123
-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+
## Unreleased
11+
12+
### Added
13+
14+
- `no-invalid-scriptlets` linter rule.
15+
1016
## [4.0.0-beta.4] - 2024-12-11
1117

1218
### Fixed

config-presets/all.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"no-invalid-domains": "error",
2525
"no-invalid-hint-params": "error",
2626
"no-invalid-modifiers": "error",
27+
"no-invalid-scriptlets": [
28+
"error",
29+
{
30+
"fuzzyThreshold": 0.6
31+
}
32+
],
2733
"no-short-rules": [
2834
"error",
2935
{

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| [no-invalid-domains](./no-invalid-domains.md) | Disallows invalid domains || | 💡 |
1717
| [no-invalid-hint-params](./no-invalid-hint-params.md) | Checks if hints are parameterized correctly || | |
1818
| [no-invalid-modifiers](./no-invalid-modifiers.md) | Checks modifiers validity for basic (network) rules || | |
19+
| [no-invalid-scriptlets](./no-invalid-scriptlets.md) | Checks if scriptlets are valid based on compatibility tables | | | 💡 |
1920
| [no-short-rules](./no-short-rules.md) | Checks if a rule is too short || | |
2021
| [no-unknown-hint-platforms](./no-unknown-hint-platforms.md) | Checks if platforms in related hints are known || | |
2122
| [no-unknown-hints](./no-unknown-hints.md) | Checks if hints are known || | |

0 commit comments

Comments
 (0)