feat(linter/plugins): implement SourceCode.getDisableDirectives method#21029
Conversation
9d9ee06 to
91545c1
Compare
91545c1 to
053bc11
Compare
053bc11 to
41e1f45
Compare
|
Sorry I'm so slow to get to this PR. As I mentioned on #21492, ideal solution would be to pass the disable comments from Rust side (as we're already doing the work of parsing comments there), but I'm not sure how easy that would be. A pure-JS solution like in this PR is a good interim solution (and who knows how long it'll be until we get to doing it "properly", so "interim" might actually mean quite a long time). All that's lacking, I think, is:
@KuSh Would you have the time and inclination to add those to this PR? |
|
Yes sure, I'll see if I find time in the next weeks! Thanks for the feedback @overlookmotel I thought of trying to pass the disable comments from Rust side, but as that part seems to be touchy and hard to optimize, and that specific function doesn't seem to be used a lot by plugins. I tought I would propose a simpler first version to have feedback ^^ |
Signed-off-by: Nicolas Le Cam <niko.lecam@gmail.com>
41e1f45 to
7e58a8c
Compare
|
@overlookmotel I've added a fixture test. I've also added a comment about what patterns match. I hope that's what you had in mind. |
|
This is the last thing missing to fully migrate to oxlint. If this PR is merged it would be much appreciated 🙏 |
SourceCode.getDisableDirectives method
This is going to be a bunch of extra work, which I don't think is currently worth it. We can address this in future
This has been implemented - I've pushed up a follow up commit added support for the
I think both of these should be done! |
|
@overlookmotel going to merge this now-ish, if you could take a retrospective look that would be appreciated! thanks! |
There was a problem hiding this comment.
Pull request overview
This PR adds SourceCode.getDisableDirectives() to the JS plugin SourceCode surface so ESLint-compatible plugins (notably unicorn helpers) can inspect inline disable/enable comments instead of crashing when the method is missing.
Changes:
- Adds a new
directives.tshelper that parseseslint-*/oxlint-*disable and enable comments into{ problems, directives }. - Exposes
getDisableDirectiveson the shared JS pluginSOURCE_CODEobject. - Adds a new CLI fixture covering plugin access to the method and snapshotting the reported directive counts.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxlint/test/fixtures/getDisableDirectives/plugin.ts | New fixture plugin that calls sourceCode.getDisableDirectives() and asserts returned counts/shape. |
| apps/oxlint/test/fixtures/getDisableDirectives/output.snap.md | Snapshot for the new fixture’s expected lint output. |
| apps/oxlint/test/fixtures/getDisableDirectives/files/test.js | Test input containing various oxlint/eslint disable and enable directives. |
| apps/oxlint/test/fixtures/getDisableDirectives/.oxlintrc.json | Enables the new fixture plugin/rule. |
| apps/oxlint/src-js/plugins/source_code.ts | Wires the new directive helper onto the public SourceCode API. |
| apps/oxlint/src-js/plugins/directives.ts | Implements directive parsing and malformed-comment problem collection. |
Used by eslint-plugin-unicorn
It crashes when trying to use it through jsPlugins (for unicorn/expiring-todo-comments)
ESLint documentation says its optional but unicorn doesn't seem to guard against its absence