Skip to content

Commit

Permalink
Fix missing check on one-line code-blocks
Browse files Browse the repository at this point in the history
Closes GH-230.
Closes GH-233.

Reviewed-by: Christian Murphy <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>
  • Loading branch information
AlexWayfer authored May 26, 2020
1 parent 316c8c6 commit 7c04e5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/remark-lint-no-shell-dollars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*
* @example {"name": "ok.md"}
*
* ```bash
* echo a
* ```
*
* ```sh
* echo a
* echo a > file
Expand All @@ -34,14 +38,19 @@
*
* @example {"name": "not-ok.md", "label": "input"}
*
* ```sh
* $ echo a
* ```
*
* ```bash
* $ echo a
* $ echo a > file
* ```
*
* @example {"name": "not-ok.md", "label": "output"}
*
* 1:1-4:4: Do not use dollar signs before shell commands
* 1:1-3:4: Do not use dollar signs before shell commands
* 5:1-8:4: Do not use dollar signs before shell commands
*/

'use strict'
Expand Down Expand Up @@ -81,11 +90,13 @@ function noShellDollars(tree, file) {

// Check both known shell code and unknown code.
if (!generated(node) && node.lang && flags.indexOf(node.lang) !== -1) {
lines = node.value.split('\n')
lines = node.value.split('\n').filter(function (line) {
return line
})
length = lines.length
index = -1

if (length <= 1) {
if (length === 0) {
return
}

Expand Down
11 changes: 10 additions & 1 deletion packages/remark-lint-no-shell-dollars/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ This rule is included in the following presets:
###### In

````markdown
```bash
echo a
```

```sh
echo a
echo a > file
Expand Down Expand Up @@ -61,6 +65,10 @@ No messages.
###### In

````markdown
```sh
$ echo a
```

```bash
$ echo a
$ echo a > file
Expand All @@ -70,7 +78,8 @@ $ echo a > file
###### Out

```text
1:1-4:4: Do not use dollar signs before shell commands
1:1-3:4: Do not use dollar signs before shell commands
5:1-8:4: Do not use dollar signs before shell commands
```

## Install
Expand Down

0 comments on commit 7c04e5d

Please sign in to comment.