Skip to content

Commit 7c04e5d

Browse files
authored
Fix missing check on one-line code-blocks
Closes GH-230. Closes GH-233. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent 316c8c6 commit 7c04e5d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

packages/remark-lint-no-shell-dollars/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*
1111
* @example {"name": "ok.md"}
1212
*
13+
* ```bash
14+
* echo a
15+
* ```
16+
*
1317
* ```sh
1418
* echo a
1519
* echo a > file
@@ -34,14 +38,19 @@
3438
*
3539
* @example {"name": "not-ok.md", "label": "input"}
3640
*
41+
* ```sh
42+
* $ echo a
43+
* ```
44+
*
3745
* ```bash
3846
* $ echo a
3947
* $ echo a > file
4048
* ```
4149
*
4250
* @example {"name": "not-ok.md", "label": "output"}
4351
*
44-
* 1:1-4:4: Do not use dollar signs before shell commands
52+
* 1:1-3:4: Do not use dollar signs before shell commands
53+
* 5:1-8:4: Do not use dollar signs before shell commands
4554
*/
4655

4756
'use strict'
@@ -81,11 +90,13 @@ function noShellDollars(tree, file) {
8190

8291
// Check both known shell code and unknown code.
8392
if (!generated(node) && node.lang && flags.indexOf(node.lang) !== -1) {
84-
lines = node.value.split('\n')
93+
lines = node.value.split('\n').filter(function (line) {
94+
return line
95+
})
8596
length = lines.length
8697
index = -1
8798

88-
if (length <= 1) {
99+
if (length === 0) {
89100
return
90101
}
91102

packages/remark-lint-no-shell-dollars/readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ This rule is included in the following presets:
2929
###### In
3030

3131
````markdown
32+
```bash
33+
echo a
34+
```
35+
3236
```sh
3337
echo a
3438
echo a > file
@@ -61,6 +65,10 @@ No messages.
6165
###### In
6266

6367
````markdown
68+
```sh
69+
$ echo a
70+
```
71+
6472
```bash
6573
$ echo a
6674
$ echo a > file
@@ -70,7 +78,8 @@ $ echo a > file
7078
###### Out
7179

7280
```text
73-
1:1-4:4: Do not use dollar signs before shell commands
81+
1:1-3:4: Do not use dollar signs before shell commands
82+
5:1-8:4: Do not use dollar signs before shell commands
7483
```
7584

7685
## Install

0 commit comments

Comments
 (0)