panache 2.35.0

An LSP, formatter, and linter for Pandoc markdown, Quarto, and RMarkdown
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
---
title: Linting
description: >
  This section provides instructions and examples for using the Panache linter,
  which checks for correctness issues and best practice violations in your
  Markdown documents.
---

Panache includes a built-in linter that checks for correctness issues and best
practice violations in your Markdown documents. Unlike the formatter which
handles style consistency, the linter catches semantic problems like syntax
errors, heading hierarchy issues, broken references, and citation problems.

## Philosophy

The linter focuses on semantic correctness rather than stylistic preferences,
for which the formatter is responsible (and can act as a linter via
`panache format --check`).

## CLI Usage

### Basic Linting

To lint a single file and show diagnostics, run this:

```bash
panache lint document.qmd
```

To lint multiple files at once, you can specify them one-by-one:

```bash
panache lint file1.md file2.qmd file3.Rmd
```

If you want to lint all supported files in a directory, use:

```bash
panache lint .
panache lint docs/
```

`panache lint` supports glob patterns as well:

```bash
panache lint 'src/**/*.qmd'
```

### Lint from stdin

You can also pipe content through the linter:

```bash
cat document.qmd | panache lint # or `panache lint < document.qmd`
```

Or with a here-document:

```bash
panache lint <<'EOF'
# H1
### H3
EOF
```

### Apply Automatic Fixes

Panache can automatically fix certain types of issues:

```bash
panache lint --fix document.qmd
```

::: {.callout-warning}
Auto-fix modifies files in place. Always commit your changes first or use
version control.
:::

### CI Mode

If you want to enforce linting in a CI/CD pipeline, use the `--check` flag. This
will run the linter and exit with code 1 if any violations are found:

```bash
panache lint --check .
```

This mode is ideal for enforcing linting in CI/CD pipelines:

```bash
panache lint --check . || exit 1
```

### Message format

Use `--message-format` to control diagnostic verbosity:

```bash
panache lint --message-format human document.qmd # default rich output
panache lint --message-format short document.qmd # compact one-line diagnostics
```

## Lint Rules

Panache includes several built-in lint rules that analyze document structure and
content.

### `heading-hierarchy`

Detects skipped heading levels that violate document structure best practices.

Severity
:   Warning

Auto-fix
:   Yes

Description
:   Headings should increment by at most one level (e.g., H1 → H2 → H3).
    Skipping levels (H1 → H3) makes the document structure unclear and can break
    table-of-contents generation.

**Example violation:**

```markdown
# Main Title

### Subsection
```

**Diagnostic:**

```
warning: [heading-hierarchy] Heading level skipped from h1 to h3; expected h2
 --> document.qmd:3:1
  |
3 | ### Subsection
  | ^^^^^^^^^^^^^^
```

**Auto-fix:** Changes `### Subsection` to `## Subsection`.

**Valid structure:**

```markdown
# Main Title

## Section

### Subsection
```

### `duplicate-reference-labels`

Detects duplicate reference link and footnote definitions.

Severity
:   Warning

Auto-fix
:   No

Description
:   Each reference label and footnote ID must be unique within a document.
    Duplicate definitions cause ambiguity—only the first definition is used,
    making the others ineffective.

**Example violation**

```markdown
See [link1] and [link2].

[link1]: https://example.com
[link1]: https://different.com
```

**Diagnostic:**

```
warning[duplicate-reference-labels]: Duplicate reference definition 'link1'
  --> document.qmd:4:1
note: First defined here:
  --> document.qmd:3:1
```

**Footnote example:**

```markdown
Text with footnote[^1] and another[^2].

[^1]: First footnote.
[^1]: Duplicate footnote.
```

**Resolution:** Rename or remove the duplicate definition.

### `undefined-references`

Detects reference links and footnotes that point to missing definitions.

Severity
:   Warning

Auto-fix
:   No

Description
:   Flags unresolved reference-style links (including shortcut/collapsed forms)
    and unresolved footnote references. This helps catch broken cross-references
    early in editing and CI.

**Example violation:**

```markdown
See [missing][nope] and note[^missing].

[ok]: https://example.com
```

**Diagnostic:**

```
warning[undefined-reference-label]: Reference label '[nope]' not found
  --> document.qmd:1:15
warning[undefined-footnote-id]: Footnote '[^missing]' not found
  --> document.qmd:1:31
```

### `unused-definitions`

Detects reference labels and footnote definitions that are declared but never
referenced.

Severity
:   Warning

Auto-fix
:   No

Description
:   Flags unused reference definitions (`[label]: ...`) and unused footnote
    definitions (`[^id]: ...`). This helps keep documents tidy and avoids dead
    references that can accumulate over time. When project metadata is available
    (for example in Quarto/Bookdown project lint runs), usage is resolved across
    project documents to reduce cross-file false positives.

**Example violation:**

```markdown
Text with one note[^1].

[^1]: Used note.
[^2]: Unused note.

[used]: https://example.com
[unused]: https://unused.example.com
```

**Diagnostic:**

```
warning[unused-footnote-id]: Footnote '[^2]' is never used
  --> document.qmd:4:1
warning[unused-definition-label]: Reference definition '[unused]' is never used
  --> document.qmd:7:1
```

### `citation-keys`

Validates citation keys against loaded bibliographies and detects conflicts in
inline bibliography entries.

Severity
:   Error for loading failures, Warning for undefined keys

Auto-fix
:   No

Requirements
:   Requires `extensions.citations = true` in configuration

Description
:   Checks that all cited keys (`[@key]`) exist in the configured bibliography
    files. Also validates inline bibliography entries for duplicates and
    conflicts.

**Example violation (undefined key):**

```markdown
---
bibliography: refs.bib
---

See @smith2020 and @jones2021.
```

If `jones2021` doesn't exist in `refs.bib`:

```
warning[citation-keys]: Citation key 'jones2021' not found in bibliography
  --> document.qmd:6:17
```

**Example violation (bibliography load error):**

```markdown
---
bibliography: nonexistent.bib
---
```

**Diagnostic:**

```
error[bibliography-load-error]: Failed to load bibliography nonexistent.bib: File not found
  --> document.qmd:1:1
```

**When it runs:** Only when document metadata includes bibliography
configuration and citation extension is enabled.

### `chunk-label-spaces`

Detects executable chunk labels containing whitespace (for example
`{r several words}` or `label="several words"`).

Severity
:   Warning

Auto-fix
:   No

Description
:   Labels with spaces are accepted by Quarto execution, but cross-references
    often fail to resolve reliably. Use a stable identifier such as
    `several-words` or `several_words` instead.

### `missing-chunk-labels`

Detects executable chunks that do not define a `label` (either inline or
hashpipe style).

Severity
:   Warning

Auto-fix
:   No

Description
:   Labels facilitates debugging. Add a label with either `#| label: my-chunk`
    or inline `label=my-chunk`.

### `figure-crossref-captions`

Detects figure cross-references that point to chunk labels without a figure
caption option.

Severity
:   Warning

Auto-fix
:   No

Description
:   Bookdown figure cross-references (`\@ref(fig:...)`) require a captioned
    chunk to create a resolvable figure label at render time. When the target
    chunk has a `label` but no `fig-cap`/`fig.cap`, the crossref will not
    resolve.

### `unknown-emoji-alias`

Detects `:alias:` emoji shortcodes that are not recognized.

Severity
:   Warning

Auto-fix
:   No

Requirements
:   Requires `extensions.emoji = true` in configuration

Description
:   Checks parsed emoji aliases against the emoji shortcode dataset and warns
    when an alias is unknown.

**Example violation:**

```markdown
Looks good :smile:, but this one is wrong :not-a-real-emoji:.
```

**Diagnostic:**

```
warning[unknown-emoji-alias]: Unknown emoji alias ':not-a-real-emoji:'
  --> document.qmd:1:40
```

## YAML parse diagnostics

Panache emits `yaml-parse-error` diagnostics when embedded YAML content is
invalid. This currently applies to both document frontmatter (`--- ... ---`) and
executable chunk hashpipe options (`#| ...`).

Severity
:   Warning

Auto-fix
:   No

**Example (hashpipe):**

````markdown
```{{r}}
#| echo: [
1 + 1
```
````

**Diagnostic:**

```
warning[yaml-parse-error]: YAML parse error: ...
  --> document.qmd:2:10
```

## Diagnostic Format

Diagnostics are displayed in a compiler-style format:

```
severity[rule-name]: message
  --> file:line:column
```

Components:

`severity`
:   `error`, `warning`, or `info`

`rule-name`
:   The lint rule that triggered (e.g., `heading-hierarchy`)

`message`
:   Human-readable description of the issue

`location`
:   File path, line number, and column number

**Multi-location diagnostics:**

Some rules provide additional context:

```
warning[duplicate-reference-labels]: Duplicate reference definition 'link1'
  --> document.qmd:4:1
note: First defined here:
  --> document.qmd:3:1
```

## Severity Levels

Panache uses three severity levels:

`error`
:   Critical issues that prevent correct parsing or rendering

`warning`
:   Likely mistakes or best practice violations

`info`
:   Informational messages (currently unused, reserved for future use)

## Auto-Fix Capabilities

Auto-fixes are available for select rules where the correction is unambiguous:

Currently supported:

- `heading-hierarchy`: Adjusts heading levels to fix skipped levels

Currently unsupported:

- `duplicate-reference-labels`: Multiple valid resolutions (rename, delete,
  merge)
- `citation-keys`: Requires external bibliography editing
- Parser errors: Too context-dependent

::: {.callout-note}
Auto-fixes are applied in place when using `--fix`. Always use version control
or backup files before applying automatic fixes to important documents.
:::

## External Linters

Panache can integrate with external code linters to check code blocks within
your documents.

### Configuration

Enable external linters in your configuration file:

```toml
[linters]
r = "jarl"
python = "ruff"
sh = "shellcheck"
js = "eslint"
go = "staticcheck"
rust = "clippy"
```

Available external linters:

  | Language              | Linter        | Description                         |
  | --------------------- | ------------- | ----------------------------------- |
  | R                     | `jarl`        | R linter with JSON diagnostics      |
  | Python                | `ruff`        | Python linter with JSON diagnostics |
  | Shell                 | `shellcheck`  | Shell linter with JSON diagnostics  |
  | JavaScript/TypeScript | `eslint`      | JS/TS linter with JSON diagnostics  |
  | Go                    | `staticcheck` | Go linter with JSON diagnostics     |
  | Rust                  | `clippy`      | Rust linter with JSON diagnostics   |

### How External Linters Work

External linters analyze code blocks using a stateful concatenation approach:

1. **Collection**: All code blocks of the target language are extracted
2. **Concatenation**: Blocks are joined with blank-line preservation to maintain
   line numbers
3. **Analysis**: The external linter analyzes the concatenated code
4. **Mapping**: Diagnostics are mapped back to original document positions

::: {.callout-note}
This approach correctly handles stateful code. If a variable is defined in one
code block and used in another, the linter sees the complete context and won't
report false positives.
:::

### Example

Document with multiple R code blocks:

````markdown
---
title: "Analysis"
---

```{r}
x <- 10
```

Some text between blocks.

```{r}
y <- x + 5
```
````

With `[linters] r = "jarl"` configured, `jarl` analyzes both blocks together and
correctly understands that `x` is defined before it's used. Similarly, with
`[linters] python = "ruff"`, Ruff can lint Python code blocks and map
diagnostics back to the original document.

### Behavior

Language matching
:   Case-insensitive matching of code block language to linter configuration

Error handling
:   Missing linter executables log a warning and skip gracefully

Compatibility checks
:   External linters only run for their supported languages. Unsupported
    mappings in `[linters]` (for example, `bash = "jarl"`) are skipped with a
    warning.

Timeout
:   30-second timeout per linter invocation

Line accuracy
:   Diagnostics report exact line and column positions in the original document

Auto-fixes
:   Supported for external linters that return fix edits with mappable ranges
    (currently `jarl`, `ruff`, and `eslint`)

### Where External Linters Run

CLI
:   Diagnostics appear in `panache lint` output

LSP
:   Diagnostics appear inline in your editor with live updates

## Ignore Directives

You can selectively disable linting for specific regions using HTML comment
directives:

### Ignore Linting Only

Use `panache-ignore-lint-start` and `panache-ignore-lint-end` to suppress lint
warnings:

```markdown
Normal content will be linted.

<!-- panache-ignore-lint-start -->
#### This heading skip won't trigger heading-hierarchy warning
<!-- panache-ignore-lint-end -->

Back to normal linting.
```

This is useful for:

- Intentional heading level skips for specific formatting
- Generated content with unusual structure
- Third-party content you don't control
- Documentation examples showing bad practices

#### Ignore Both Formatting and Linting

Use `panache-ignore-start` and `panache-ignore-end` to disable both:

```markdown
<!-- panache-ignore-start -->
#### Unusual   structure   here
Both formatting and linting ignored in this region
<!-- panache-ignore-end -->
```

::: {.callout-note}
**Note on Directive Behavior**: Lint rules still "see" content in ignored
regions when tracking context (e.g., for heading hierarchy), but diagnostics
from ignored regions are filtered out. This ensures rules maintain proper state
across the document.
:::

See [Formatting](formatting.qmd) for more information about formatting-specific
ignore directives.

## Configuration

Lint rules can be configured in the `[lint.rules]` section of your configuration
file. Each key is a rule name and each value is a boolean (`true`/`false`).

```toml
[lint.rules]
heading-hierarchy = true
duplicate-reference-labels = true
undefined-references = true
unused-definitions = true
citation-keys = true
chunk-label-spaces = true
missing-chunk-labels = true
figure-crossref-captions = true
unknown-emoji-alias = true
```

All rules are enabled by default when omitted. You can disable a specific rule:

```toml
[lint.rules]
undefined-references = false
```

::: {.callout-note}
Legacy `[lint] rule = true/false` is still supported for backward compatibility,
but deprecated.
:::

## LSP Integration

When using the Panache language server, lint diagnostics appear live in your
editor as you type:

- Squiggly underlines for errors and warnings
- Hover tooltips showing diagnostic messages
- Code actions for auto-fixes (e.g., fix heading hierarchy)

See the [LSP documentation](lsp.qmd) for editor configuration details.

## Examples

### Example 1: Heading Hierarchy

Before:

```markdown
# Main Title

### Skipped Level

#### Another Skip
```

Run linter:

```bash
panache lint document.qmd
```

Output:

```
warning: [heading-hierarchy] Heading level skipped from h1 to h3; expected h2
 --> document.qmd:3:1
  |
3 | ### Skipped Level
  | ^^^^^^^^^^^^^^^^^^

warning: [heading-hierarchy] Heading level skipped from h3 to h4; expected h3
 --> document.qmd:5:1
  |
5 | #### Another Skip
  | ^^^^^^^^^^^^^^^^^
```

Apply auto-fix:

```bash
panache lint --fix document.qmd
```

After:

```markdown
# Main Title

## Skipped Level

### Another Skip
```

### Example 2: Duplicate References

Before:

```markdown
See [example1] and [example2].

[example1]: https://first.com
[example1]: https://second.com
[example2]: https://other.com
```

Run linter:

```bash
panache lint document.qmd
```

Output:

```
warning[duplicate-reference-labels]: Duplicate reference definition 'example1'
  --> document.qmd:4:1
note: First defined here:
  --> document.qmd:3:1
```

Resolution (manual):

```markdown
See [example1] and [example2].

[example1]: https://first.com
[example2]: https://other.com
```

### Example 3: Citation Validation

Before (with `refs.bib` configured):

```markdown
---
bibliography: refs.bib
---

See @existingkey and @missingkey.
```

Run linter:

```bash
panache lint document.qmd
```

Output:

```
warning[citation-keys]: Citation key 'missingkey' not found in bibliography
  --> document.qmd:5:24
```

Resolution: Add the citation to `refs.bib` or remove the reference.