diff --git a/core/Parsers.fs b/core/Parsers.fs index 79e6d25..e14679a 100644 --- a/core/Parsers.fs +++ b/core/Parsers.fs @@ -35,6 +35,19 @@ let dartdoc : ContentParser -> ContentParser = let dartdoc_markdown ctx = dartdoc markdown_noHeader ctx +/// 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|eslint-disable-line|eslint-disable|eslint-enable)\b" + + fun line -> + if isMatch rx 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..c7e0efc 100644 --- a/core/Parsing.Documents.fs +++ b/core/Parsing.Documents.fs @@ -46,6 +46,15 @@ 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 [ jsDocBlockWithEslint; cBlockWithEslint; line' "//[/!]" (eslintConfigComments jsdoc_markdown); line' "//" (eslintConfigComments markdown) ] + // 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 +138,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 +191,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 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 e35cda6..af000f9 100644 --- a/docs/specs/features/line-comments.md +++ b/docs/specs/features/line-comments.md @@ -92,3 +92,28 @@ 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 ¦ + + // 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 ¦