Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/Parsers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
13 changes: 11 additions & 2 deletions core/Parsing.Documents.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions docs/specs/features/block-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ¦
25 changes: 25 additions & 0 deletions docs/specs/features/line-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ¦