From 04f51c96c8c2f8adf41b0f6c5256b7aa1a363989 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 6 Aug 2025 11:08:58 +0200 Subject: [PATCH 1/4] 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/4] 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/4] 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/4] 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