rumdl 0.1.88

A fast Markdown linter written in Rust (Ru(st) MarkDown Linter)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
use std::fs;
use std::process::Command;

#[test]
fn test_init_command_creates_and_loads_config() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Run init command
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["init"])
        .output()
        .unwrap();

    assert!(output.status.success(), "Init command failed");
    assert!(base_path.join(".rumdl.toml").exists(), "Config file not created");

    // Create a test file with a heading level increment issue (jumping from level 1 to level 3)
    fs::write(
        base_path.join("test.md"),
        "# Heading level 1\n### Heading level 3 (skipping level 2)\n",
    )
    .unwrap();

    // Run linter with default config (should detect MD001)
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md"])
        .output()
        .unwrap();

    let stderr = String::from_utf8_lossy(&output.stderr);
    let stdout = String::from_utf8_lossy(&output.stdout);
    let combined_output = format!("{stdout}\n{stderr}");

    // Check for specific rules that should trigger:
    // - MD022: Missing blank lines around headings
    // - MD041: First line in file should be a level 1 heading
    assert!(
        combined_output.contains("MD022") || combined_output.contains("MD041"),
        "Should detect at least one of: MD022 (blanks around headings) or MD041 (first line heading)"
    );
}

#[test]
fn test_utilities_via_complex_markdown() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Create a complex Markdown file that tests multiple utilities
    let complex_md = r#"
# Heading 1

## Heading 2

Text with *emphasis* and **strong emphasis**.

### Heading 3

- List item 1
  - Nested item 1.1
    - Deeply nested 1.1.1
  - Nested item 1.2
- List item 2
  - Nested item 2.1
    - Deeply nested 2.1.1

1. Ordered item 1
   1. Nested ordered 1.1
      1. Deeply nested 1.1.1
   2. Nested ordered 1.2
2. Ordered item 2

> Blockquote text
> multiple lines
>
> With blank line

```js
console.log('Code block');
```

Text with <span>inline HTML</span>.

![Image without alt](image.png)

[Empty link]()

This line is very long and exceeds the usual line length limits by a significant margin which should trigger line length rules.

	Indented code block instead of fenced code block that should be detected by the code block utilities.

Heading level jump coming:

# Heading 1

#### Heading 4 (skipping level 2 and 3)

___
"#;

    fs::write(base_path.join("complex.md"), complex_md).unwrap();

    // Run linter with all rules enabled
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "complex.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined_output = format!("{stdout}\n{stderr}");

    // Check for specific rules that should trigger in this complex markdown:
    // - MD001: Heading level jump from H1 to H4 (lines 94-96)
    // - MD013: Long line exceeding usual limits (line 88)
    // - MD042: Empty link with no URL (line 86)
    // - MD045: Image without alt text (line 84)
    // - MD046: Mixed code block styles (indented code block on line 90)
    assert!(
        combined_output.contains("MD001")
            || combined_output.contains("MD013")
            || combined_output.contains("MD042")
            || combined_output.contains("MD045")
            || combined_output.contains("MD046"),
        "Should detect at least one of: MD001 (heading jump), MD013 (line length), MD042 (empty link), MD045 (no alt text), or MD046 (code block style)"
    );

    // Run the fix operation
    let _fix_output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "complex.md", "--fix"])
        .output()
        .unwrap();

    // Verify file was modified in some way
    let fixed_content = fs::read_to_string(base_path.join("complex.md")).unwrap();
    assert!(complex_md != fixed_content, "File should be modified by fix operation");
}

#[test]
fn test_multiple_rule_groups() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Create a test file with various issues
    let test_content = r#"
# Heading 1
# Heading 1 Duplicate

## heading 2 (inconsistent style)

- First list item
-   Second item with extra spaces
- Third list item with trailing whitespace
- Fourth item with	hard tab

Unnecessarily long line that exceeds the default line length limit and should trigger a warning if enabled.


Multiple blank lines above this one.
"#;

    fs::write(base_path.join("test.md"), test_content).unwrap();

    // Run with default rules (should detect various issues)
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined_output = format!("{stdout}\n{stderr}");

    // Check for specific rules that should trigger:
    // - MD003: Inconsistent heading style "## heading 2" (line 143)
    // - MD009: Trailing whitespace on line 147
    // - MD010: Hard tab on line 148
    // - MD012: Multiple consecutive blank lines (lines 151-152)
    // - MD013: Long line exceeding limit (line 149)
    // - MD024: Duplicate "Heading 1" content (lines 139-140)
    // - MD030: Inconsistent spaces after list markers (line 146)
    assert!(
        combined_output.contains("MD003")
            || combined_output.contains("MD009")
            || combined_output.contains("MD010")
            || combined_output.contains("MD012")
            || combined_output.contains("MD013")
            || combined_output.contains("MD024")
            || combined_output.contains("MD030"),
        "Should detect at least one of: MD003 (heading style), MD009 (trailing spaces), MD010 (tabs), MD012 (multiple blanks), MD013 (line length), MD024 (duplicate heading), or MD030 (list marker spaces)"
    );
}

#[test]
fn test_emphasis_and_heading_rules() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Test file targeting specific low-coverage rules
    let test_content = r#"
*This is an emphasized line that should be detected as a heading by MD036*

**Another emphasized line that should be detected**

   # Indented heading (MD023)

## Missing blank line above (MD022)
Text immediately below heading (MD022)

# First Heading Level 1
### Heading Level 3 (Skipping level 2, MD001)

**This is not a heading, because it's not on a line by itself**
"#;

    fs::write(base_path.join("test.md"), test_content).unwrap();

    // Run linter for all rules
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined_output = format!("{stdout}\n{stderr}");

    // Check for specific rules that should trigger:
    // - MD001: Heading level jump from H1 to H3 (lines 191-192)
    // - MD022: Missing blank lines around headings (lines 188-189)
    // - MD023: Indented heading (line 185)
    // - MD036: Emphasis used as heading (lines 182-183)
    assert!(
        combined_output.contains("MD001")
            || combined_output.contains("MD022")
            || combined_output.contains("MD023")
            || combined_output.contains("MD036"),
        "Should detect at least one of: MD001 (heading increment), MD022 (blanks around headings), MD023 (heading start left), or MD036 (emphasis as heading)"
    );

    // Test fix operation
    let fix_output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--fix", "--verbose"])
        .output()
        .unwrap();

    // Print debug output
    println!("Fix command stdout: {}", String::from_utf8_lossy(&fix_output.stdout));
    println!("Fix command stderr: {}", String::from_utf8_lossy(&fix_output.stderr));

    // Verify some issues were fixed
    let fixed_content = fs::read_to_string(base_path.join("test.md")).unwrap();
    println!("Original content:\n{test_content}");
    println!("Fixed content:\n{fixed_content}");
    assert!(
        fixed_content != test_content,
        "File should be modified by fix operation"
    );
}

#[test]
fn test_url_and_link_rules() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Create a test file with various link and URL issues
    let test_content = r#"
# Links and URLs Test

Bare URL: https://example.com

[Link with space at end](https://example.com  )

[Empty link]()

![Image without alt text](image.png)

[Undefined reference][undefined]

Visit http://example.com for more information.
"#;

    fs::write(base_path.join("test.md"), test_content).unwrap();

    // Run linter with default rules
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined_output = format!("{stdout}\n{stderr}");

    println!("Check command output:\n{combined_output}");

    // Check for specific link/URL rules that should trigger:
    // - MD034: Bare URL without angle brackets (lines 246, 256)
    // - MD039: Space inside link text (line 248)
    // - MD042: Empty link with no URL (line 250)
    // - MD045: Image without alt text (line 252)
    // - MD052: Undefined reference link (line 254)
    assert!(
        combined_output.contains("MD034")
            || combined_output.contains("MD039")
            || combined_output.contains("MD042")
            || combined_output.contains("MD045")
            || combined_output.contains("MD052"),
        "Should detect at least one of: MD034 (bare URL), MD039 (space in links), MD042 (empty link), MD045 (no alt text), or MD052 (undefined reference)"
    );

    // Test fix operation
    let fix_output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--fix", "--verbose"])
        .output()
        .unwrap();

    // Print debug output
    println!("Fix command stdout: {}", String::from_utf8_lossy(&fix_output.stdout));
    println!("Fix command stderr: {}", String::from_utf8_lossy(&fix_output.stderr));

    // Verify the file was modified
    let fixed_content = fs::read_to_string(base_path.join("test.md")).unwrap();
    println!("Original content:\n{test_content}");
    println!("Fixed content:\n{fixed_content}");
    assert!(
        fixed_content != test_content,
        "File should be modified by fix operation"
    );
}

#[test]
fn test_profiling_features() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Create a simple test file
    fs::write(base_path.join("test.md"), "# Test Heading\n\nSimple content.\n").unwrap();

    // Run with verbose output that should include rule names
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);

    // Check if verbose output contains rule names or summary
    assert!(
        stdout.contains("Rules:") || stdout.contains("MD") || stdout.contains("Success:"),
        "Should show rules or summary information"
    );
}

#[test]
fn test_low_coverage_rules() {
    let temp_dir = tempfile::tempdir().unwrap();
    let base_path = temp_dir.path();

    // Create a test file specifically for testing low-coverage rules
    let test_content = r#"
# Heading with Trailing Punctuation!

> This is a blockquote
> with multiple lines.

> This is another blockquote
>
> with a blank line.

- List item 1
-  List item 2 with extra space after marker
- List item 3

1. Ordered item 1
1. Ordered item 2 (not using incremental numbers)
1. Ordered item 3

| Column 1 | Column 2 |
|-|-|
| Row 1    | Data 1   |
| Row 2    | Data 2   |
| Row 3    | Data 3 With extra column | Extra |
"#;

    fs::write(base_path.join("test.md"), test_content).unwrap();

    // Run linter with all rules
    let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--verbose"])
        .output()
        .unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined_output = format!("{stdout}\n{stderr}");

    // Check for specific rules that should trigger:
    // - MD026: Trailing punctuation in heading (line 332)
    // - MD028: Blank line inside blockquote (lines 337-339)
    // - MD029: Ordered list not using incremental numbers (lines 345-347)
    // - MD030: Extra space after list marker (line 342)
    // - MD056: Table column count inconsistent (line 353 has extra column)
    assert!(
        combined_output.contains("MD026")
            || combined_output.contains("MD028")
            || combined_output.contains("MD029")
            || combined_output.contains("MD030")
            || combined_output.contains("MD056"),
        "Should detect at least one of: MD026 (trailing punctuation), MD028 (blank in blockquote), MD029 (ordered list prefix), MD030 (list marker space), or MD056 (table columns)"
    );

    // Test fix for these rules
    let _fix_output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
        .current_dir(base_path)
        .args(["check", "test.md", "--fix", "--verbose"])
        .output()
        .unwrap();

    // Verify that at least some issues were fixed
    let fixed_content = fs::read_to_string(base_path.join("test.md")).unwrap();
    assert!(
        fixed_content != test_content,
        "File should be modified by fix operation"
    );
}