Skip to content

Ignore ESLint directive comments in JavaScript and TypeScript#34

Open
karlhorky wants to merge 9 commits intodnut:masterfrom
karlhorky:ignore-eslint-config-comments
Open

Ignore ESLint directive comments in JavaScript and TypeScript#34
karlhorky wants to merge 9 commits intodnut:masterfrom
karlhorky:ignore-eslint-config-comments

Conversation

@karlhorky
Copy link

@karlhorky karlhorky commented Aug 6, 2025

Closes #33

Rewrap splits // eslint-disable-next-line and // eslint-disable-line into multiple lines, which breaks behavior because ESLint no longer applies the directive to the intended line.

Other directive forms like eslint-disable and eslint-enable use 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.

@karlhorky
Copy link
Author

@dnut just circling back around - what do you think of this PR?

@karlhorky
Copy link
Author

Hey @dnut, is there anything that I can do to help get this reviewed and merged?

@karlhorky
Copy link
Author

@dnut just wanted to check in again, in case you would have time soon to help get this landed.

Copilot AI review requested due to automatic review settings February 25, 2026 03:29
@dnut
Copy link
Owner

dnut commented Feb 25, 2026

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 eslintConfigComments content parser wrapper that detects ESLint directive comments and prevents them from being wrapped
  • Created a new javascript DocumentProcessor 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
Comment on lines 38 to 49
/// 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
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@karlhorky
Copy link
Author

@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

@karlhorky karlhorky changed the title Ignore eslint-disable-next-line + eslint-disable-line line comments Ignore ESLint directive comments in JavaScript and TypeScript Feb 25, 2026
@karlhorky
Copy link
Author

In 22cc3ea, I also added support for eslint-disable and eslint-enable comments, since wrapping those can also hurt legibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-disable-next-line and eslint-disable-line line comments break when formatted

3 participants