Ignore ESLint directive comments in JavaScript and TypeScript#34
Ignore ESLint directive comments in JavaScript and TypeScript#34karlhorky wants to merge 9 commits intodnut:masterfrom
Conversation
|
@dnut just circling back around - what do you think of this PR? |
|
Hey @dnut, is there anything that I can do to help get this reviewed and merged? |
|
@dnut just wanted to check in again, in case you would have time soon to help get this landed. |
|
I think there were a few problems with this implementation. Did you test it? I committed a couple fixes that made it work for me. Let me know what you think. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for preventing rewrapping of ESLint configuration comment directives (eslint-disable-next-line and eslint-disable-line) in JavaScript and TypeScript files. These single-line directives must remain on one line to function properly, as breaking them across multiple lines causes ESLint to fail to recognize them.
Changes:
- Added a new
eslintConfigCommentscontent parser wrapper that detects ESLint directive comments and prevents them from being wrapped - Created a new
javascriptDocumentProcessor that integrates the ESLint parser with existing JavaScript/TypeScript comment handling - Updated JavaScript and TypeScript language definitions to use the new processor
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/Parsers.fs | Added eslintConfigComments parser that detects and prevents wrapping of eslint-disable-next-line and eslint-disable-line directives |
| core/Parsing.Documents.fs | Created javascript DocumentProcessor and updated JavaScript/TypeScript language configs to use it |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/Parsers.fs
Outdated
| /// ESLint configuration comments parser that prevents wrapping of eslint-disable lines | ||
| /// https://github.com/dnut/Rewrap/issues/33 | ||
| let eslintConfigComments : ContentParser -> ContentParser = | ||
| fun content ctx -> | ||
|
|
||
| let rx = regex @"^\s*eslint-(disable-next-line|disable-line)" | ||
|
|
||
| fun line -> | ||
| if isMatch rx line then | ||
| finished_ line noWrapBlock | ||
| else | ||
| content ctx line |
There was a problem hiding this comment.
The new eslintConfigComments parser lacks test coverage. Consider adding tests in a file like docs/specs/content-types/javascript.md to verify that lines with eslint-disable-next-line and eslint-disable-line are not wrapped, while normal comments continue to wrap correctly.
|
@dnut oh thanks! Sorry - I was trying to do that by hand, without much knowledge of F# Upon review, your two comments seem to make sense: As per the comment from Copilot, I also added tests: AI disclosure: I used gpt-5.3-codex and reviewed the output as best I could |
eslint-disable-next-line + eslint-disable-line line comments|
In 22cc3ea, I also added support for |
Closes #33
Rewrap splits
// eslint-disable-next-lineand// eslint-disable-lineinto multiple lines, which breaks behavior because ESLint no longer applies the directive to the intended line.Other directive forms like
eslint-disableandeslint-enableuse multi-line comments, - still valid after wrapping - but they become harder to read and review.Ignore both forms of ESLint directive comments during wrapping in JavaScript and TypeScript and adds specs for these cases.