eslint-markdown 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check if a line is blank.
|
|
3
|
+
* - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
|
|
3
4
|
* @param {string} str Line string.
|
|
5
|
+
* @param {number} [blockquoteDepth] The depth of blockquotes. Default is `-1`.
|
|
4
6
|
* @returns {boolean} `true` if the line is blank. `false` otherwise.
|
|
5
7
|
*/
|
|
6
|
-
export default function isBlankLine(str: string): boolean;
|
|
8
|
+
export default function isBlankLine(str: string, blockquoteDepth?: number): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-markdown",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lint your Markdown with ESLint.🛠️",
|
|
6
6
|
"exports": {
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/mdast": "^4.0.4",
|
|
82
|
+
"@types/unist": "^3.0.3",
|
|
82
83
|
"eslint": "^9.39.4"
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// --------------------------------------------------------------------------------
|
|
9
9
|
|
|
10
10
|
const whitespaceChars = new Set([' ', '\t']);
|
|
11
|
+
const blockquoteChar = '>';
|
|
11
12
|
|
|
12
13
|
// --------------------------------------------------------------------------------
|
|
13
14
|
// Export
|
|
@@ -15,15 +16,25 @@ const whitespaceChars = new Set([' ', '\t']);
|
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Check if a line is blank.
|
|
19
|
+
* - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
|
|
18
20
|
* @param {string} str Line string.
|
|
21
|
+
* @param {number} [blockquoteDepth] The depth of blockquotes. Default is `-1`.
|
|
19
22
|
* @returns {boolean} `true` if the line is blank. `false` otherwise.
|
|
20
23
|
*/
|
|
21
|
-
export default function isBlankLine(str) {
|
|
24
|
+
export default function isBlankLine(str, blockquoteDepth = -1) {
|
|
22
25
|
// `.length` is cached for performance.
|
|
23
26
|
const strLength = str.length;
|
|
27
|
+
let remainingBlockquotes = blockquoteDepth + 1;
|
|
24
28
|
|
|
25
29
|
for (let i = 0; i < strLength; i++) {
|
|
26
|
-
|
|
30
|
+
const char = str[i];
|
|
31
|
+
|
|
32
|
+
if (!whitespaceChars.has(char)) {
|
|
33
|
+
if (remainingBlockquotes > 0 && char === blockquoteChar) {
|
|
34
|
+
remainingBlockquotes--;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
return false;
|
|
28
39
|
}
|
|
29
40
|
}
|
|
@@ -132,8 +132,14 @@ export default {
|
|
|
132
132
|
|
|
133
133
|
/** @type {CodeStyle | null} */
|
|
134
134
|
let codeStyle = style === 'consistent' ? null : style;
|
|
135
|
+
let blockquoteDepth = -1; // NOTE: Depth `0` is the first blockquote level, which is the top level.
|
|
135
136
|
|
|
136
137
|
return {
|
|
138
|
+
blockquote() {
|
|
139
|
+
// When entering a `blockquote` node, increase the depth.
|
|
140
|
+
blockquoteDepth++;
|
|
141
|
+
},
|
|
142
|
+
|
|
137
143
|
code(node) {
|
|
138
144
|
// ------------------------------------------------------------------------
|
|
139
145
|
// 1. Check code style consistency.
|
|
@@ -182,7 +188,7 @@ export default {
|
|
|
182
188
|
}
|
|
183
189
|
|
|
184
190
|
// If the line is blank, continue checking the next line. If it's not blank, report the issue.
|
|
185
|
-
if (isBlankLine(line)) {
|
|
191
|
+
if (isBlankLine(line, blockquoteDepth)) {
|
|
186
192
|
continue;
|
|
187
193
|
}
|
|
188
194
|
|
|
@@ -225,7 +231,7 @@ export default {
|
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
// If the line is blank, continue checking the next line. If it's not blank, report the issue.
|
|
228
|
-
if (isBlankLine(line)) {
|
|
234
|
+
if (isBlankLine(line, blockquoteDepth)) {
|
|
229
235
|
continue;
|
|
230
236
|
}
|
|
231
237
|
|
|
@@ -244,6 +250,11 @@ export default {
|
|
|
244
250
|
}
|
|
245
251
|
}
|
|
246
252
|
},
|
|
253
|
+
|
|
254
|
+
'blockquote:exit'() {
|
|
255
|
+
// When exiting a `blockquote` node, decrease the depth.
|
|
256
|
+
blockquoteDepth--;
|
|
257
|
+
},
|
|
247
258
|
};
|
|
248
259
|
},
|
|
249
260
|
};
|
|
@@ -94,7 +94,7 @@ export default {
|
|
|
94
94
|
const unorderedListStyle = [
|
|
95
95
|
style === 'consistent' || style === 'sublist' ? null : style,
|
|
96
96
|
];
|
|
97
|
-
let listDepth = -1;
|
|
97
|
+
let listDepth = -1; // NOTE: Depth `0` is the first list level, which is the top level.
|
|
98
98
|
|
|
99
99
|
return {
|
|
100
100
|
list() {
|