mkdlint 0.11.9

A style checker and lint tool for Markdown/CommonMark files, written in Rust.
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
name: Test mkdlint Action

on:
  push:
    paths:
      - '.github/actions/mkdlint/**'
      - '.github/workflows/test-action.yml'
  pull_request:
    paths:
      - '.github/actions/mkdlint/**'
      - '.github/workflows/test-action.yml'
  workflow_dispatch:

permissions:
  contents: read
  security-events: write

jobs:
  # Test binary download and caching on all platforms
  test-binary-download:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        version: [latest, '0.11.0']
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      
      - name: Test binary download
        id: test
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          version: ${{ matrix.version }}
          use-binary: true
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify outputs
        shell: bash
        run: |
          echo "Exit code: ${{ steps.test.outputs.exit-code }}"
          echo "Error count: ${{ steps.test.outputs.error-count }}"
          echo "File count: ${{ steps.test.outputs.file-count }}"
          echo "Binary path: ${{ steps.test.outputs.binary-path }}"
          echo "Cache hit: ${{ steps.test.outputs.cache-hit }}"
          
          if [ ! -f "${{ steps.test.outputs.binary-path }}" ]; then
            echo "Error: Binary not found at ${{ steps.test.outputs.binary-path }}"
            exit 1
          fi
      
      - name: Test cache hit on second run
        id: test2
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          version: ${{ matrix.version }}
          use-binary: true
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify cache was used
        shell: bash
        run: |
          echo "Cache hit on second run: ${{ steps.test2.outputs.cache-hit }}"
          # First run might not have cache, but second run should
          # (unless it's a fresh runner or different version)

  # Test cargo build fallback
  test-cargo-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      
      - name: Test cargo build
        id: test
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          use-binary: false
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify binary was built
        run: |
          if [ ! -f "${{ steps.test.outputs.binary-path }}" ]; then
            echo "Error: Binary not found after cargo build"
            exit 1
          fi
          
          ${{ steps.test.outputs.binary-path }} --version

  # Test SARIF generation and upload
  test-sarif-upload:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create test markdown with issues
        run: |
          mkdir -p test-docs
          cat > test-docs/test.md << 'MDEOF'
          # Test Document
          
          This is a test.
          
          
          Multiple blank lines above.
          
          ## Setup
          
          Content here.
          
          ## Setup
          
          Duplicate heading.
          MDEOF
      
      - name: Run with SARIF output
        id: sarif
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-docs/'
          output-format: sarif
          sarif-file: results.sarif
          upload-sarif: true
          fail-on-error: false
      
      - name: Verify SARIF file exists
        run: |
          if [ ! -f "results.sarif" ]; then
            echo "Error: SARIF file not created"
            exit 1
          fi
          
          # Verify it's valid JSON
          jq . results.sarif > /dev/null
          
          # Show SARIF structure
          echo "SARIF file created successfully:"
          jq '.runs[0].results | length' results.sarif
      
      - name: Upload SARIF as artifact
        uses: actions/upload-artifact@v4
        with:
          name: sarif-results
          path: results.sarif

  # Test auto-fix workflow
  test-auto-fix:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create test file with fixable issues
        run: |
          mkdir -p test-fix
          cat > test-fix/fixable.md << 'MDEOF'
          #No space after hash
          
          Trailing spaces here:    
          
          Multiple trailing spaces:        
          
          - Item 1
          -  Item 2 (extra space)
          - Item 3
          MDEOF
      
      - name: Run with auto-fix
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-fix/'
          fix: true
          fail-on-error: false
          upload-sarif: false
      
      - name: Verify fixes were applied
        run: |
          cat test-fix/fixable.md
          
          # Check that heading now has space
          if ! grep -q "^# No space" test-fix/fixable.md; then
            echo "Error: Heading not fixed"
            exit 1
          fi
          
          echo "Auto-fix succeeded!"

  # Test custom configuration
  test-custom-config:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create custom config
        run: |
          mkdir -p test-config
          cat > test-config/.markdownlint.json << 'JSONEOF'
          {
            "default": true,
            "MD013": false,
            "MD033": false
          }
          JSONEOF
          
          cat > test-config/test.md << 'MDEOF'
          # Test
          
          This line is very long and would normally fail MD013 line-length rule but we disabled it in config.
          
          <div>HTML is normally not allowed but MD033 is disabled</div>
          MDEOF
      
      - name: Run with custom config
        id: config
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-config/test.md'
          config: 'test-config/.markdownlint.json'
          upload-sarif: false
          fail-on-error: true
      
      - name: Verify no errors with custom config
        run: |
          if [ "${{ steps.config.outputs.error-count }}" != "0" ]; then
            echo "Error: Custom config not respected"
            exit 1
          fi

  # Test rule disable flags
  test-disable-rules:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create test file
        run: |
          mkdir -p test-disable
          cat > test-disable/test.md << 'MDEOF'
          # Test
          
          This line is very long and exceeds the default line length limit of 80 characters which should trigger MD013.
          
          <div>This HTML should trigger MD033</div>
          MDEOF
      
      - name: Run with disabled rules
        id: disable
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-disable/'
          disable: 'MD013,MD033'
          upload-sarif: false
          fail-on-error: true
      
      - name: Verify rules were disabled
        run: |
          if [ "${{ steps.disable.outputs.error-count }}" != "0" ]; then
            echo "Error: Rules not disabled correctly"
            exit 1
          fi

  # Test ignore patterns
  test-ignore-patterns:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create test structure
        run: |
          mkdir -p test-ignore/node_modules test-ignore/src
          echo "#Bad heading" > test-ignore/node_modules/test.md
          echo "# Good heading" > test-ignore/src/test.md
      
      - name: Run with ignore patterns
        id: ignore
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-ignore/'
          ignore: '**/node_modules/**'
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify ignored files were skipped
        run: |
          echo "Errors found: ${{ steps.ignore.outputs.error-count }}"
          # node_modules/test.md should be ignored, only src/test.md should be checked

  # Test failure modes
  test-fail-on-error:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create file with errors
        run: |
          mkdir -p test-fail
          echo "#No space" > test-fail/bad.md
      
      - name: Test fail-on-error true (should fail)
        id: fail_true
        continue-on-error: true
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-fail/'
          fail-on-error: true
          upload-sarif: false
      
      - name: Verify it failed
        run: |
          if [ "${{ steps.fail_true.outcome }}" != "failure" ]; then
            echo "Error: Should have failed with fail-on-error: true"
            exit 1
          fi
      
      - name: Test fail-on-error false (should succeed)
        id: fail_false
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-fail/'
          fail-on-error: false
          upload-sarif: false
      
      - name: Verify it succeeded
        run: |
          if [ "${{ steps.fail_false.outcome }}" != "success" ]; then
            echo "Error: Should have succeeded with fail-on-error: false"
            exit 1
          fi

  # Test output formats
  test-output-formats:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create test file
        run: |
          mkdir -p test-output
          echo "#Bad" > test-output/test.md
      
      - name: Test text format
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-output/'
          output-format: text
          upload-sarif: false
          fail-on-error: false
      
      - name: Test JSON format
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-output/'
          output-format: json
          upload-sarif: false
          fail-on-error: false
      
      - name: Test SARIF format
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-output/'
          output-format: sarif
          sarif-file: test-output.sarif
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify SARIF was created
        run: |
          if [ ! -f "test-output.sarif" ]; then
            echo "Error: SARIF file not created"
            exit 1
          fi

  # Test verbose and quiet modes
  test-verbosity:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Test verbose mode
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          verbose: true
          upload-sarif: false
          fail-on-error: false
      
      - name: Test quiet mode
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          quiet: true
          upload-sarif: false
          fail-on-error: false

  # Integration test - full workflow
  integration-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create comprehensive test suite
        run: |
          mkdir -p integration-test/docs integration-test/vendor
          
          # Good markdown
          cat > integration-test/docs/good.md << 'MDEOF'
          # Good Document
          
          This is properly formatted.
          
          ## Section 1
          
          Content here.
          
          ## Section 2
          
          More content.
          MDEOF
          
          # Bad markdown (fixable)
          cat > integration-test/docs/fixable.md << 'MDEOF'
          #Bad heading
          
          Trailing spaces:    
          
          -  Extra space in list
          - Normal item
          MDEOF
          
          # Vendor (should be ignored)
          echo "#Bad" > integration-test/vendor/ignored.md
      
      - name: Create config
        run: |
          cat > integration-test/.markdownlint.json << 'JSONEOF'
          {
            "default": true,
            "MD013": { "line_length": 120 }
          }
          JSONEOF
      
      - name: Run full workflow
        id: full
        uses: ./.github/actions/mkdlint
        with:
          files: 'integration-test/'
          config: 'integration-test/.markdownlint.json'
          ignore: '**/vendor/**'
          output-format: sarif
          sarif-file: integration.sarif
          fix: true
          upload-sarif: false
          fail-on-error: false
      
      - name: Verify results
        run: |
          echo "Exit code: ${{ steps.full.outputs.exit-code }}"
          echo "Errors: ${{ steps.full.outputs.error-count }}"
          echo "Files: ${{ steps.full.outputs.file-count }}"
          
          # Verify fixes were applied
          cat integration-test/docs/fixable.md
          
          # Verify SARIF was created
          if [ ! -f "integration.sarif" ]; then
            echo "Error: SARIF not created"
            exit 1
          fi
          
          # Verify vendor was ignored
          jq '.runs[0].results[].locations[].physicalLocation.artifactLocation.uri' integration.sarif | \
            grep -q vendor && echo "Error: Vendor files not ignored" && exit 1 || true
          
          echo "Integration test passed!"

  # Test working directory parameter
  test-working-directory:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create subdirectory structure
        run: |
          mkdir -p subdir/docs
          echo "# Test" > subdir/docs/test.md
      
      - name: Run from subdirectory
        uses: ./.github/actions/mkdlint
        with:
          files: 'docs/'
          working-directory: 'subdir'
          upload-sarif: false
          fail-on-error: false

  # Test job summary output
  test-job-summary:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Create test file with errors
        run: |
          mkdir -p test-summary
          cat > test-summary/errors.md << 'TESTEOF'
          #Bad heading
          Some text here

          ## heading

          ## heading
          TESTEOF

      - name: Run with job summary enabled
        id: summary-test
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-summary/'
          upload-sarif: false
          fail-on-error: false
          job-summary: true
          output-format: sarif

      - name: Verify new outputs exist
        run: |
          echo "Warning count: ${{ steps.summary-test.outputs.warning-count }}"
          echo "Duration ms: ${{ steps.summary-test.outputs.duration-ms }}"

          # Duration should be a number > 0
          if [ -z "${{ steps.summary-test.outputs.duration-ms }}" ]; then
            echo "Error: duration-ms output is empty"
            exit 1
          fi

          # warning-count should be set (can be 0)
          if [ -z "${{ steps.summary-test.outputs.warning-count }}" ]; then
            echo "Error: warning-count output is empty"
            exit 1
          fi

      - name: Run with job summary disabled
        uses: ./.github/actions/mkdlint
        with:
          files: 'test-summary/'
          upload-sarif: false
          fail-on-error: false
          job-summary: false

  # Test incremental linting (changed-only mode)
  test-changed-only:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Test changed-only on push (should lint all files)
        id: push-test
        uses: ./.github/actions/mkdlint
        with:
          files: 'README.md'
          changed-only: true
          upload-sarif: false
          fail-on-error: false

      - name: Verify push event lints normally
        run: |
          # On push events, changed-only should still lint the specified files
          echo "Exit code: ${{ steps.push-test.outputs.exit-code }}"

  # Summary job
  test-summary:
    runs-on: ubuntu-latest
    needs:
      - test-binary-download
      - test-cargo-build
      - test-sarif-upload
      - test-auto-fix
      - test-custom-config
      - test-disable-rules
      - test-ignore-patterns
      - test-fail-on-error
      - test-output-formats
      - test-verbosity
      - integration-test
      - test-working-directory
      - test-job-summary
      - test-changed-only
    if: always()
    steps:
      - name: Check all tests passed
        run: |
          if [ "${{ needs.test-binary-download.result }}" != "success" ] || \
             [ "${{ needs.test-cargo-build.result }}" != "success" ] || \
             [ "${{ needs.test-sarif-upload.result }}" != "success" ] || \
             [ "${{ needs.test-auto-fix.result }}" != "success" ] || \
             [ "${{ needs.test-custom-config.result }}" != "success" ] || \
             [ "${{ needs.test-disable-rules.result }}" != "success" ] || \
             [ "${{ needs.test-ignore-patterns.result }}" != "success" ] || \
             [ "${{ needs.test-fail-on-error.result }}" != "success" ] || \
             [ "${{ needs.test-output-formats.result }}" != "success" ] || \
             [ "${{ needs.test-verbosity.result }}" != "success" ] || \
             [ "${{ needs.integration-test.result }}" != "success" ] || \
             [ "${{ needs.test-working-directory.result }}" != "success" ] || \
             [ "${{ needs.test-job-summary.result }}" != "success" ] || \
             [ "${{ needs.test-changed-only.result }}" != "success" ]; then
            echo "❌ Some tests failed"
            exit 1
          else
            echo "✅ All tests passed!"
          fi