From 04f51c96c8c2f8adf41b0f6c5256b7aa1a363989 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 6 Aug 2025 11:08:58 +0200 Subject: [PATCH 1/9] Ignore `eslint-disable-next-line` + `eslint-disable-line` line comments --- core/Parsers.fs | 8 ++++++++ core/Parsing.Documents.fs | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index 79e6d25..44b6a1b 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -35,6 +35,14 @@ let dartdoc : ContentParser -> ContentParser = let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx +/// 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 line -> + if isMatch (regex @"^\s*//\s*eslint-(disable|enable)") line then + finished_ line noWrapBlock + else content ctx line + let ignoreAll ctx = Parsing_Internal.ignoreAll ctx let godoc : ContentParser = fun _ctx -> diff --git a/core/Parsing.Documents.fs b/core/Parsing.Documents.fs index 6380590..76ab80b 100644 --- a/core/Parsing.Documents.fs +++ b/core/Parsing.Documents.fs @@ -46,6 +46,9 @@ let private configFile = sc [line "#"] let java : DocumentProcessor = sc [ jsDocBlock; cBlock; line' "//[/!]" jsdoc_markdown; line "//" ] +let javascript : DocumentProcessor = + sc [ jsDocBlock; cBlock; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line "//" ] + // Takes 4 args to create a Language: // 1. display name (used only in VS) // 2. string of aliases (language IDs used by the client. Not needed if they only differ @@ -129,7 +132,7 @@ let mutable languages = [ lang "INI" "" ".ini" <| sc [line "[#;]"] lang "J" "" ".ijs" <| sc [line @"NB\."] lang "Java" "" ".java" java - lang "JavaScript" "javascriptreact|js" ".js|.jsx" java + lang "JavaScript" "javascriptreact|js" ".js|.jsx" javascript lang "Julia" "" ".jl" <| sc [block ("#=", "=#"); line "#"; block (@".*?""""""", "\"\"\"")] lang "JSON" "json5|jsonc" ".json|.json5|.jsonc" java lang "LaTeX" "tex" ".bbx|.cbx|.cls|.sty|.tex" @@ -182,7 +185,7 @@ let mutable languages = [ lang "Tcl" "" ".tcl" <| configFile lang "Textile" "" ".textile" <| docOf markdown lang "TOML" "" ".toml" <| configFile - lang "TypeScript" "typescriptreact" ".ts|.tsx" java + lang "TypeScript" "typescriptreact" ".ts|.tsx" javascript lang "Verilog/SystemVerilog" "systemverilog|verilog" ".sv|.svh|.v|.vh|.vl" java lang "XAML" "" ".xaml" html From c2dc3d9546ec3805e376992f815024e3a671a49f Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 6 Aug 2025 11:19:46 +0200 Subject: [PATCH 2/9] Ignore only the line disables --- core/Parsers.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index 44b6a1b..e74fae1 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -39,7 +39,7 @@ let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx /// https://github.com/dnut/Rewrap/issues/33 let eslintConfigComments : ContentParser -> ContentParser = fun content ctx line -> - if isMatch (regex @"^\s*//\s*eslint-(disable|enable)") line then + if isMatch (regex @"^\s*//\s*eslint-(disable-next-line|disable-line)") line then finished_ line noWrapBlock else content ctx line From 38659ff22319adb781f52e3ed8a9f770b61a29a8 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 6 Aug 2025 11:34:39 +0200 Subject: [PATCH 3/9] Fix indentation --- core/Parsers.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index e74fae1..615cf24 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -39,9 +39,9 @@ let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx /// https://github.com/dnut/Rewrap/issues/33 let eslintConfigComments : ContentParser -> ContentParser = fun content ctx line -> - if isMatch (regex @"^\s*//\s*eslint-(disable-next-line|disable-line)") line then - finished_ line noWrapBlock - else content ctx line + if isMatch (regex @"^\s*//\s*eslint-(disable-next-line|disable-line)") line then + finished_ line noWrapBlock + else content ctx line let ignoreAll ctx = Parsing_Internal.ignoreAll ctx From 81edd6abba6dbcc62a4d7a695c3deeb529620fea Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 6 Aug 2025 11:47:04 +0200 Subject: [PATCH 4/9] Switch to single compilation of regex --- core/Parsers.fs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index 615cf24..5a3fa3a 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -38,10 +38,15 @@ let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx /// 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 line -> - if isMatch (regex @"^\s*//\s*eslint-(disable-next-line|disable-line)") line then + fun content ctx -> + + let rx = regex @"^\s*//\s*eslint-(disable-next-line|disable-line)" + + fun line -> + if isMatch rx line then finished_ line noWrapBlock - else content ctx line + else + content ctx line let ignoreAll ctx = Parsing_Internal.ignoreAll ctx From 3a50118bdcb499aac1011385425105f3f5245a28 Mon Sep 17 00:00:00 2001 From: Drew Nutter Date: Tue, 24 Feb 2026 20:28:27 -0700 Subject: [PATCH 5/9] fix(Parsers): redundant // in js regex --- core/Parsers.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index 5a3fa3a..90aef35 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -40,7 +40,7 @@ let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx let eslintConfigComments : ContentParser -> ContentParser = fun content ctx -> - let rx = regex @"^\s*//\s*eslint-(disable-next-line|disable-line)" + let rx = regex @"^\s*eslint-(disable-next-line|disable-line)" fun line -> if isMatch rx line then From f7800d5a0088602c65199d27e2fd50570a25d0b3 Mon Sep 17 00:00:00 2001 From: Drew Nutter Date: Tue, 24 Feb 2026 20:29:02 -0700 Subject: [PATCH 6/9] fix(Parsing.Documents): eslint only applied to special comments /// and //! not // --- core/Parsing.Documents.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Parsing.Documents.fs b/core/Parsing.Documents.fs index 76ab80b..a119113 100644 --- a/core/Parsing.Documents.fs +++ b/core/Parsing.Documents.fs @@ -47,7 +47,7 @@ let java : DocumentProcessor = sc [ jsDocBlock; cBlock; line' "//[/!]" jsdoc_markdown; line "//" ] let javascript : DocumentProcessor = - sc [ jsDocBlock; cBlock; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line "//" ] + sc [ jsDocBlock; cBlock; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line' "//" (eslintConfigComments markdown) ] // Takes 4 args to create a Language: // 1. display name (used only in VS) From c82b6dd92badef1c1c6dbfbea83e5ae2fccab937 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 25 Feb 2026 13:58:50 +0100 Subject: [PATCH 7/9] Add tests --- docs/specs/features/line-comments.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/specs/features/line-comments.md b/docs/specs/features/line-comments.md index e35cda6..e7e4170 100644 --- a/docs/specs/features/line-comments.md +++ b/docs/specs/features/line-comments.md @@ -92,3 +92,20 @@ All blank lines are trimmed at the end. (This is true of all non-wrapping lines) //·· ¦ -> // ¦ -or- // ¦ //···· ¦ // ¦ // ¦ + +## ESLint directive comments + +ESLint line directives in JavaScript/TypeScript must stay on a single line to keep their +effect. + +> language: javascript + + // eslint-disable-next-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() + nextLoad(url).source ¦ -> // eslint-disable-next-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() + nextLoad(url).source nextLoad(url).source ¦ + +> language: typescript + + // eslint-disable-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() + nextLoad(url).source ¦ -> // eslint-disable-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() + nextLoad(url).source nextLoad(url).source ¦ From 22cc3eadfdf09cdf3be412be153f878b0f8ac185 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 25 Feb 2026 14:40:08 +0100 Subject: [PATCH 8/9] Ignore eslint-disable and eslint-enable in JS/TS block comments --- core/Parsers.fs | 4 ++-- core/Parsing.Documents.fs | 8 +++++++- docs/specs/features/block-comments.md | 15 +++++++++++++++ docs/specs/features/line-comments.md | 8 ++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index 90aef35..bd1c686 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -35,12 +35,12 @@ let dartdoc : ContentParser -> ContentParser = let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx -/// ESLint configuration comments parser that prevents wrapping of eslint-disable lines +/// ESLint configuration comments parser that prevents wrapping of disable/enable 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)" + let rx = regex @"^\s*eslint-(disable(?:-(?:next-line|line))?|enable)\b" fun line -> if isMatch rx line then diff --git a/core/Parsing.Documents.fs b/core/Parsing.Documents.fs index a119113..c7e0efc 100644 --- a/core/Parsing.Documents.fs +++ b/core/Parsing.Documents.fs @@ -46,8 +46,14 @@ let private configFile = sc [line "#"] let java : DocumentProcessor = sc [ jsDocBlock; cBlock; line' "//[/!]" jsdoc_markdown; line "//" ] +let private cBlockWithEslint = + block' ("*", "") (@"/\*", @"\*/") (eslintConfigComments markdown) + +let private jsDocBlockWithEslint = + block' ("*", " * ") javadocMarkers (eslintConfigComments jsdoc_markdown) + let javascript : DocumentProcessor = - sc [ jsDocBlock; cBlock; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line' "//" (eslintConfigComments markdown) ] + sc [ jsDocBlockWithEslint; cBlockWithEslint; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line' "//" (eslintConfigComments markdown) ] // Takes 4 args to create a Language: // 1. display name (used only in VS) diff --git a/docs/specs/features/block-comments.md b/docs/specs/features/block-comments.md index 16c43c6..61bdf8a 100644 --- a/docs/specs/features/block-comments.md +++ b/docs/specs/features/block-comments.md @@ -81,3 +81,18 @@ used for created lines. ··/** Foo bar¦baz */ -> ··/** Foo bar¦ ¦ * baz */ ¦ + +## ESLint directive comments + +ESLint disable/enable directives in JavaScript/TypeScript block comments should remain +single-line when wrapping comments. + +> language: javascript + + /* eslint-disable no-console, @typescript-eslint/no-base-to-string -- temporary exception for migration script with long explanation that should stay intact on one line */ + nextLoad(url).source ¦ -> /* eslint-disable no-console, @typescript-eslint/no-base-to-string -- temporary exception for migration script with long explanation that should stay intact on one line */ + nextLoad(url).source nextLoad(url).source ¦ + + /* eslint-enable no-console, @typescript-eslint/no-base-to-string -- restore lint checks after migration script with long explanation that should stay intact on one line */ + nextLoad(url).source ¦ -> /* eslint-enable no-console, @typescript-eslint/no-base-to-string -- restore lint checks after migration script with long explanation that should stay intact on one line */ + nextLoad(url).source nextLoad(url).source ¦ diff --git a/docs/specs/features/line-comments.md b/docs/specs/features/line-comments.md index e7e4170..af000f9 100644 --- a/docs/specs/features/line-comments.md +++ b/docs/specs/features/line-comments.md @@ -109,3 +109,11 @@ effect. // eslint-disable-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() nextLoad(url).source ¦ -> // eslint-disable-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString() nextLoad(url).source nextLoad(url).source ¦ + + // eslint-disable no-console, @typescript-eslint/no-base-to-string -- temporary exception for migration script + nextLoad(url).source ¦ -> // eslint-disable no-console, @typescript-eslint/no-base-to-string -- temporary exception for migration script + nextLoad(url).source nextLoad(url).source ¦ + + // eslint-enable no-console, @typescript-eslint/no-base-to-string -- restore lint checks after migration script + nextLoad(url).source ¦ -> // eslint-enable no-console, @typescript-eslint/no-base-to-string -- restore lint checks after migration script + nextLoad(url).source nextLoad(url).source ¦ From b0083ba87e3ace2caf64e821da16dcbcb953962e Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 25 Feb 2026 15:03:36 +0100 Subject: [PATCH 9/9] Simplify legibility of regex --- core/Parsers.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Parsers.fs b/core/Parsers.fs index bd1c686..e14679a 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -40,7 +40,7 @@ let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx let eslintConfigComments : ContentParser -> ContentParser = fun content ctx -> - let rx = regex @"^\s*eslint-(disable(?:-(?:next-line|line))?|enable)\b" + let rx = regex @"^\s*(eslint-disable-next-line|eslint-disable-line|eslint-disable|eslint-enable)\b" fun line -> if isMatch rx line then