Skip to content

Commit 37c31f5

Browse files
committed
fix: review comments
1 parent 618649e commit 37c31f5

File tree

3 files changed

+159
-25
lines changed

3 files changed

+159
-25
lines changed

docs/rules/no-missing-atx-heading-space.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You might want to turn this rule off if you're working with a Markdown variant t
4141

4242
## Prior Art
4343

44-
[MD018 - No space after hash on atx style heading](https://github.com/DavidAnson/markdownlint/blob/main/doc/md018.md)
44+
- [MD018 - No space after hash on atx style heading](https://github.com/DavidAnson/markdownlint/blob/main/doc/md018.md)
4545

4646
## Further Reading
4747

src/rules/no-missing-atx-heading-space.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,35 @@
99

1010
/**
1111
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
12-
* NoMissingAtxHeaderSpaceRuleDefinition
12+
* NoMissingAtxHeadingSpaceRuleDefinition
1313
*/
1414

1515
//-----------------------------------------------------------------------------
1616
// Rule Definition
1717
//-----------------------------------------------------------------------------
1818

19-
/** @type {NoMissingAtxHeaderSpaceRuleDefinition} */
19+
const HEADING_PATTERN = /^(#{1,6})([^#\s])/u;
20+
21+
/** @type {NoMissingAtxHeadingSpaceRuleDefinition} */
2022
export default {
2123
meta: {
2224
type: "problem",
25+
2326
docs: {
2427
description:
2528
"Disallow headings without a space after the hash characters",
2629
recommended: true,
2730
url: "https://github.com/eslint/markdown/blob/main/docs/rules/no-missing-atx-heading-space.md",
2831
},
32+
2933
fixable: "whitespace",
30-
schema: [],
34+
3135
messages: {
3236
missingSpace: "Missing space after hash(es) on ATX style heading.",
3337
},
3438
},
3539

3640
create(context) {
37-
const headingPattern = /^(#{1,6})([^#\s])/u;
38-
3941
return {
4042
paragraph(node) {
4143
if (node.children && node.children.length > 0) {
@@ -53,7 +55,7 @@ export default {
5355
const lineNum =
5456
firstTextChild.position.start.line + idx;
5557

56-
const match = headingPattern.exec(line);
58+
const match = HEADING_PATTERN.exec(line);
5759
if (!match) {
5860
return;
5961
}

tests/rules/no-missing-atx-heading-space.test.js

Lines changed: 150 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const validHeadings = [
4646
// 3. Variations on spacing
4747
"# Heading with extra space",
4848

49-
// 4. Standalone hash (not a heading)
49+
// 4. Standalone hash
5050
"#",
5151

5252
// 5. Alternative heading styles (not covered by this rule)
@@ -107,32 +107,80 @@ const invalidTests = [
107107
{
108108
code: "#Heading 1",
109109
output: "# Heading 1",
110-
errors: [{ messageId: "missingSpace", column: 1 }],
110+
errors: [
111+
{
112+
messageId: "missingSpace",
113+
column: 1,
114+
line: 1,
115+
endLine: 1,
116+
endColumn: 10,
117+
},
118+
],
111119
},
112120
{
113121
code: "##Heading 2",
114122
output: "## Heading 2",
115-
errors: [{ messageId: "missingSpace", column: 2 }],
123+
errors: [
124+
{
125+
messageId: "missingSpace",
126+
column: 2,
127+
line: 1,
128+
endLine: 1,
129+
endColumn: 11,
130+
},
131+
],
116132
},
117133
{
118134
code: "###Heading 3",
119135
output: "### Heading 3",
120-
errors: [{ messageId: "missingSpace", column: 3 }],
136+
errors: [
137+
{
138+
messageId: "missingSpace",
139+
column: 3,
140+
line: 1,
141+
endLine: 1,
142+
endColumn: 12,
143+
},
144+
],
121145
},
122146
{
123147
code: "####Heading 4",
124148
output: "#### Heading 4",
125-
errors: [{ messageId: "missingSpace", column: 4 }],
149+
errors: [
150+
{
151+
messageId: "missingSpace",
152+
column: 4,
153+
line: 1,
154+
endLine: 1,
155+
endColumn: 13,
156+
},
157+
],
126158
},
127159
{
128160
code: "#####Heading 5",
129161
output: "##### Heading 5",
130-
errors: [{ messageId: "missingSpace", column: 5 }],
162+
errors: [
163+
{
164+
messageId: "missingSpace",
165+
column: 5,
166+
line: 1,
167+
endLine: 1,
168+
endColumn: 14,
169+
},
170+
],
131171
},
132172
{
133173
code: "######Heading 6",
134174
output: "###### Heading 6",
135-
errors: [{ messageId: "missingSpace", column: 6 }],
175+
errors: [
176+
{
177+
messageId: "missingSpace",
178+
column: 6,
179+
line: 1,
180+
endLine: 1,
181+
endColumn: 15,
182+
},
183+
],
136184
},
137185

138186
// 2. Mixed valid and invalid headings in one document
@@ -152,6 +200,8 @@ const invalidTests = [
152200
messageId: "missingSpace",
153201
line: 3,
154202
column: 2,
203+
endLine: 3,
204+
endColumn: 11,
155205
},
156206
],
157207
},
@@ -160,38 +210,86 @@ const invalidTests = [
160210
{
161211
code: "#Text",
162212
output: "# Text",
163-
errors: [{ messageId: "missingSpace", column: 1 }],
213+
errors: [
214+
{
215+
messageId: "missingSpace",
216+
column: 1,
217+
line: 1,
218+
endLine: 1,
219+
endColumn: 5,
220+
},
221+
],
164222
},
165223
{
166224
code: "#Heading with trailing space ",
167225
output: "# Heading with trailing space ",
168-
errors: [{ messageId: "missingSpace", column: 1 }],
226+
errors: [
227+
{
228+
messageId: "missingSpace",
229+
column: 1,
230+
line: 1,
231+
endLine: 1,
232+
endColumn: 28,
233+
},
234+
],
169235
},
170236

171237
// 4. Headings containing code-like syntax
172238
// 4.1 With fenced code markers
173239
{
174240
code: "#Something with ``` backticks",
175241
output: "# Something with ``` backticks",
176-
errors: [{ messageId: "missingSpace", column: 1 }],
242+
errors: [
243+
{
244+
messageId: "missingSpace",
245+
column: 1,
246+
line: 1,
247+
endLine: 1,
248+
endColumn: 29,
249+
},
250+
],
177251
},
178252
// 4.2 With backticks mid-heading
179253
{
180254
code: "#Heading with ``` in the middle and more text after",
181255
output: "# Heading with ``` in the middle and more text after",
182-
errors: [{ messageId: "missingSpace", column: 1 }],
256+
errors: [
257+
{
258+
messageId: "missingSpace",
259+
column: 1,
260+
line: 1,
261+
endLine: 1,
262+
endColumn: 51,
263+
},
264+
],
183265
},
184266
// 4.3 With inline code
185267
{
186268
code: "#Heading with `inline code`",
187269
output: "# Heading with `inline code`",
188-
errors: [{ messageId: "missingSpace", column: 1 }],
270+
errors: [
271+
{
272+
messageId: "missingSpace",
273+
column: 1,
274+
line: 1,
275+
endLine: 1,
276+
endColumn: 14,
277+
},
278+
],
189279
},
190280
// 4.4 With tilde markers
191281
{
192282
code: "#Title with ~~~ tildes in it",
193283
output: "# Title with ~~~ tildes in it",
194-
errors: [{ messageId: "missingSpace", column: 1 }],
284+
errors: [
285+
{
286+
messageId: "missingSpace",
287+
column: 1,
288+
line: 1,
289+
endLine: 1,
290+
endColumn: 28,
291+
},
292+
],
195293
},
196294

197295
// 5. Multi-line documents
@@ -203,7 +301,15 @@ Text after`,
203301
output: dedent`Text before
204302
# Heading with \`\`\` code markers
205303
Text after`,
206-
errors: [{ messageId: "missingSpace", line: 2, column: 1 }],
304+
errors: [
305+
{
306+
messageId: "missingSpace",
307+
line: 2,
308+
column: 1,
309+
endLine: 2,
310+
endColumn: 30,
311+
},
312+
],
207313
},
208314
// 5.2 Multiple incorrect headings in one file
209315
{
@@ -222,9 +328,27 @@ Text after`,
222328
223329
### Third heading`,
224330
errors: [
225-
{ messageId: "missingSpace", line: 1, column: 1 },
226-
{ messageId: "missingSpace", line: 5, column: 2 },
227-
{ messageId: "missingSpace", line: 7, column: 3 },
331+
{
332+
messageId: "missingSpace",
333+
line: 1,
334+
column: 1,
335+
endLine: 1,
336+
endColumn: 14,
337+
},
338+
{
339+
messageId: "missingSpace",
340+
line: 5,
341+
column: 2,
342+
endLine: 5,
343+
endColumn: 16,
344+
},
345+
{
346+
messageId: "missingSpace",
347+
line: 7,
348+
column: 3,
349+
endLine: 7,
350+
endColumn: 16,
351+
},
228352
],
229353
},
230354

@@ -239,7 +363,15 @@ Text after`,
239363
240364
# Not a heading in indented code block
241365
console.log("#still in code block");`,
242-
errors: [{ messageId: "missingSpace", line: 3, column: 1 }],
366+
errors: [
367+
{
368+
messageId: "missingSpace",
369+
line: 3,
370+
column: 1,
371+
endLine: 3,
372+
endColumn: 37,
373+
},
374+
],
243375
},
244376
];
245377

0 commit comments

Comments
 (0)