Skip to content

D0007 code-block-language

Rule: Every code block names its language.

Code D0007 (stable, never reused)
Id code-block-language
Category reading
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small warn the language selects the highlighting and tells the reader what the block is
small-workspace warn the language selects the highlighting and tells the reader what the block is
medium warn the language selects the highlighting and tells the reader what the block is
big warn the language selects the highlighting and tells the reader what the block is
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Why

The language after the opening fence selects the syntax highlighting. Without it, a block of Rust or TOML renders as plain text, and the reader loses the colours that separate keys from values and code from comments. The language also tells the reader what they are looking at before they read it.

```toml
[docs]
reference = ["docs/lints/**"]
```

An indented code block cannot name a language at all.

How to fix

Name the language after the fence: rust, toml, sh, json. Output and other text that is not code takes text. Turn an indented block into a fenced one.

Configure

[lints.code-block-language]
level = "deny"
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(code-block-language) <reason> (waivers); the code works there too, as in [lints.D0007].