Commit Graph

5 Commits

Author SHA1 Message Date
camc314 1d22912cb4 fix(linter/plugins): parse rule-less directive justifications (#25559)
## Summary

- extract directive justifications before parsing directive labels, matching ESLint
- return an empty rule value for rule-less directives while preserving their justification
- cover block, enable, line, and next-line directives with both eslint and oxlint prefixes

Closes #25556
2026-08-12 16:44:01 +00:00
overlookmotel 99d263b123 refactor(linter/plugins): simplify getDisableDirectives (#24852)
Pure refactor, except for fixing a TS type, and correcting some comments. Runtime behavior is unaltered.

- `LABEL_PATTERN` captures the directive type as well as the label, so the multi-line check is a
single comparison, and `type` no longer comes from `label.slice(7)`.
- Numbered capture groups instead of named ones, so the match check is just `match === null`.
- `match` is no longer reused for a second, unrelated regex.
- `justification` is always set, so it's not optional - correct the type def accordingly.
- Simplify splitting off `justification`.
- Doc comment referenced `match_disable_directive` / `match_enable_directive`. The Rust function is
`match_directive` - correct the comment.
2026-07-23 16:59:45 +00:00
overlookmotel c126eebef6 refactor(linter/plugins): remove dead code in getDisableDirectives (#24851)
`LINE_DIRECTIVE_PATTERN` had a stray hyphen (`disable-(?:-next)?-line`), so it only matched
`disable--line` / `disable--next-line` - strings `LABEL_PATTERN` can never produce. Therefore it was dead code - remove it.

If the regex _was_ correctly written, the behavior would be wrong. Looks like this is a hangover from the code being taken from ESLint.
2026-07-23 16:59:44 +00:00
overlookmotel b7add00c28 perf(linter/plugins): remove check in loop in getDisableDirectives (#24833)
Small optimization to `context.sourceCode.getDisableDirectives`.

`Shebang` comment can only be the first comment in a file, so there's no need to check "is it a `Shebang`?" for every comment in a loop. Instead, just check the first comment before the loop.

Also add type annotation for the function's return type.
2026-07-23 09:10:58 +00:00
Nicolas Le Cam 1884833279 feat(linter/plugins): implement SourceCode.getDisableDirectives method (#21029)
Used by [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/0e023e3ad4dfb22ace33ef70c420513946528fa4/rules/utils/eslint-directive.js)

It crashes when trying to use it through jsPlugins (for unicorn/expiring-todo-comments)

ESLint [documentation](https://eslint.org/docs/latest/extend/languages#the-sourcecode-object) says its optional but unicorn doesn't seem to guard against its absence

---------

Signed-off-by: Nicolas Le Cam <niko.lecam@gmail.com>
Co-authored-by: Cameron <cameron.clark@hey.com>
2026-05-04 21:17:38 +01:00