codelaw-rules-data 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codelaw_rules_data/LICENSE +23 -0
- codelaw_rules_data/NOTICE +31 -0
- codelaw_rules_data/README.md +130 -0
- codelaw_rules_data/codelaw-pack.toml +6 -0
- codelaw_rules_data/corpus.toml +41 -0
- codelaw_rules_data/data/schemas/github-action.json +1 -0
- codelaw_rules_data/data/schemas/github-workflow.json +1 -0
- codelaw_rules_data/data/schemas/package.json +1 -0
- codelaw_rules_data/data/schemas/pyproject.json +1 -0
- codelaw_rules_data/data/schemas/tsconfig.json +1 -0
- codelaw_rules_data/licenses/SchemaStore-Apache-2.0.txt +202 -0
- codelaw_rules_data/presets/data/conventions.toml +5 -0
- codelaw_rules_data/presets/data/github-actions.toml +6 -0
- codelaw_rules_data/presets/data/package-json.toml +7 -0
- codelaw_rules_data/presets/data/pyproject.toml +6 -0
- codelaw_rules_data/presets/data/recommended.toml +9 -0
- codelaw_rules_data/presets/data/tsconfig.toml +5 -0
- codelaw_rules_data/presets/md/recommended.toml +20 -0
- codelaw_rules_data/rules/json/no-duplicate-keys.cases.md +27 -0
- codelaw_rules_data/rules/json/no-duplicate-keys.md +45 -0
- codelaw_rules_data/rules/json/package-deps-sorted.cases.md +90 -0
- codelaw_rules_data/rules/json/package-deps-sorted.md +54 -0
- codelaw_rules_data/rules/json/package-engines.cases.md +24 -0
- codelaw_rules_data/rules/json/package-engines.md +45 -0
- codelaw_rules_data/rules/json/package-json-schema.md +57 -0
- codelaw_rules_data/rules/json/package-scripts-sorted.cases.md +45 -0
- codelaw_rules_data/rules/json/package-scripts-sorted.md +53 -0
- codelaw_rules_data/rules/json/tsconfig-schema.md +59 -0
- codelaw_rules_data/rules/json/tsconfig-strict.cases.md +57 -0
- codelaw_rules_data/rules/json/tsconfig-strict.md +45 -0
- codelaw_rules_data/rules/md/commands-show-output.cases.md +14 -0
- codelaw_rules_data/rules/md/commands-show-output.md +39 -0
- codelaw_rules_data/rules/md/descriptive-link-text.md +41 -0
- codelaw_rules_data/rules/md/fence-language.md +47 -0
- codelaw_rules_data/rules/md/first-line-heading.cases.md +28 -0
- codelaw_rules_data/rules/md/first-line-heading.md +46 -0
- codelaw_rules_data/rules/md/heading-increment.cases.md +61 -0
- codelaw_rules_data/rules/md/heading-increment.md +46 -0
- codelaw_rules_data/rules/md/link-fragments.cases.md +57 -0
- codelaw_rules_data/rules/md/link-fragments.md +49 -0
- codelaw_rules_data/rules/md/link-image-reference-definitions.cases.md +51 -0
- codelaw_rules_data/rules/md/link-image-reference-definitions.md +40 -0
- codelaw_rules_data/rules/md/no-alt-text.md +47 -0
- codelaw_rules_data/rules/md/no-bare-urls.cases.md +37 -0
- codelaw_rules_data/rules/md/no-bare-urls.md +37 -0
- codelaw_rules_data/rules/md/no-duplicate-heading.cases.md +19 -0
- codelaw_rules_data/rules/md/no-duplicate-heading.md +61 -0
- codelaw_rules_data/rules/md/no-emphasis-as-heading.cases.md +23 -0
- codelaw_rules_data/rules/md/no-emphasis-as-heading.md +49 -0
- codelaw_rules_data/rules/md/no-empty-links.md +50 -0
- codelaw_rules_data/rules/md/no-inline-html.cases.md +13 -0
- codelaw_rules_data/rules/md/no-inline-html.md +45 -0
- codelaw_rules_data/rules/md/no-reversed-links.md +33 -0
- codelaw_rules_data/rules/md/reference-links-images.cases.md +40 -0
- codelaw_rules_data/rules/md/reference-links-images.md +44 -0
- codelaw_rules_data/rules/md/relative-links.md +46 -0
- codelaw_rules_data/rules/md/single-h1.cases.md +29 -0
- codelaw_rules_data/rules/md/single-h1.md +57 -0
- codelaw_rules_data/rules/md/table-column-count.md +43 -0
- codelaw_rules_data/rules/toml/deps-sorted.cases.md +28 -0
- codelaw_rules_data/rules/toml/deps-sorted.md +49 -0
- codelaw_rules_data/rules/toml/no-duplicate-keys.cases.md +43 -0
- codelaw_rules_data/rules/toml/no-duplicate-keys.md +43 -0
- codelaw_rules_data/rules/toml/pyproject-requires-python.cases.md +24 -0
- codelaw_rules_data/rules/toml/pyproject-requires-python.md +41 -0
- codelaw_rules_data/rules/toml/pyproject-schema.md +55 -0
- codelaw_rules_data/rules/yaml/document-start.cases.md +31 -0
- codelaw_rules_data/rules/yaml/document-start.md +36 -0
- codelaw_rules_data/rules/yaml/gha-action-schema.md +59 -0
- codelaw_rules_data/rules/yaml/gha-pin-sha.cases.md +25 -0
- codelaw_rules_data/rules/yaml/gha-pin-sha.md +57 -0
- codelaw_rules_data/rules/yaml/gha-workflow-schema.md +57 -0
- codelaw_rules_data/rules/yaml/no-ambiguous-booleans.cases.md +29 -0
- codelaw_rules_data/rules/yaml/no-ambiguous-booleans.md +43 -0
- codelaw_rules_data/rules/yaml/no-ambiguous-numbers.cases.md +24 -0
- codelaw_rules_data/rules/yaml/no-ambiguous-numbers.md +46 -0
- codelaw_rules_data/rules/yaml/no-duplicate-keys.cases.md +35 -0
- codelaw_rules_data/rules/yaml/no-duplicate-keys.md +43 -0
- codelaw_rules_data/rules/yaml/no-undeclared-alias.cases.md +13 -0
- codelaw_rules_data/rules/yaml/no-undeclared-alias.md +46 -0
- codelaw_rules_data-0.2.0.dist-info/METADATA +140 -0
- codelaw_rules_data-0.2.0.dist-info/RECORD +84 -0
- codelaw_rules_data-0.2.0.dist-info/WHEEL +4 -0
- codelaw_rules_data-0.2.0.dist-info/licenses/LICENSE +23 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: json/package-scripts-sorted
|
|
3
|
+
title: "package.json scripts are sorted by name"
|
|
4
|
+
languages: [json]
|
|
5
|
+
files: ["**/package.json"]
|
|
6
|
+
fix: auto
|
|
7
|
+
stability: preview
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
The `scripts` of a `package.json` are in name order. A `pre<name>` or `post<name>` script sorts next to the `<name>` script it hooks into.
|
|
12
|
+
|
|
13
|
+
**Why:** A sorted list is quicker to scan and gives smaller diffs when scripts are added; npm runs scripts by name, so their order means nothing to it.
|
|
14
|
+
|
|
15
|
+
```codelaw
|
|
16
|
+
native: json/package-scripts-sorted
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
### JSON
|
|
22
|
+
|
|
23
|
+
#### Don't
|
|
24
|
+
|
|
25
|
+
```json path=package.json
|
|
26
|
+
{
|
|
27
|
+
"name": "app",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"pretest": "npm run build",
|
|
32
|
+
"lint": "codelaw check"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Do
|
|
38
|
+
|
|
39
|
+
```json path=package.json
|
|
40
|
+
{
|
|
41
|
+
"name": "app",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"lint": "codelaw check",
|
|
45
|
+
"pretest": "npm run build",
|
|
46
|
+
"test": "vitest"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Notes
|
|
52
|
+
|
|
53
|
+
Names compare by Unicode code point. A `scripts` object that uses `npm-run-all`, `run-s` or `run-p` is left alone: those runners expand patterns such as `build:*` in the order the scripts are written, so sorting would change what runs. A `scripts` object with comments in it is reported without a fix, because the comments would stay behind while the scripts move.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: json/tsconfig-schema
|
|
3
|
+
title: "tsconfig.json matches its schema"
|
|
4
|
+
languages: [json]
|
|
5
|
+
files: ["**/tsconfig.json", "**/tsconfig.*.json"]
|
|
6
|
+
fix: manual
|
|
7
|
+
fix_reason: "a misspelt or misshapen option has several possible meanings; the author picks the one they intended"
|
|
8
|
+
stability: preview
|
|
9
|
+
ported_from: [schemastore/tsconfig.json]
|
|
10
|
+
since: 0.1.0
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
A `tsconfig.json` matches SchemaStore's schema for it: every compiler option is one TypeScript knows, with a value of the type it takes.
|
|
14
|
+
|
|
15
|
+
**Why:** `tsc` reports an unknown option only when it runs, and many editors and bundlers that read `tsconfig.json` skip it silently, so a misspelt `"stirct": true` leaves the project less strict than it looks.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
target: $
|
|
19
|
+
assert: { schema: schemas/tsconfig }
|
|
20
|
+
message: "$ERROR"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. Read the message: it names the option and what the schema expects, and suggests the option meant when the name is misspelt.
|
|
26
|
+
2. Correct the name or the value; remove an option TypeScript no longer has.
|
|
27
|
+
3. Run `codelaw check` on the file again until it is clean.
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
### JSON
|
|
32
|
+
|
|
33
|
+
#### Don't
|
|
34
|
+
|
|
35
|
+
```json path=tsconfig.json
|
|
36
|
+
{
|
|
37
|
+
"compilerOptions": {
|
|
38
|
+
"target": "es2022",
|
|
39
|
+
"stirct": true,
|
|
40
|
+
"noEmit": "true"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Do
|
|
46
|
+
|
|
47
|
+
```json path=tsconfig.json
|
|
48
|
+
{
|
|
49
|
+
"compilerOptions": {
|
|
50
|
+
"target": "es2022",
|
|
51
|
+
"strict": true,
|
|
52
|
+
"noEmit": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Notes
|
|
58
|
+
|
|
59
|
+
The schema is SchemaStore's `tsconfig.json` schema, shipped with the pack in `data/schemas/tsconfig.json` with its descriptions removed; nothing is fetched. Comments and trailing commas are allowed, as `tsc` allows them. `oneOf` is read as `anyOf`.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# json/tsconfig-strict — edge cases
|
|
2
|
+
|
|
3
|
+
### case: extends a base config
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"extends": "@tsconfig/node22/tsconfig.json",
|
|
8
|
+
"compilerOptions": { "outDir": "dist" }
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```expect
|
|
13
|
+
(none)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### case: strict turned off
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"compilerOptions": {
|
|
21
|
+
"strict": false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```expect
|
|
27
|
+
3:15 json/tsconfig-strict
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```fixed
|
|
31
|
+
{
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
"strict": true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### case: no compilerOptions
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"include": ["src"]
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```expect
|
|
47
|
+
1:1 json/tsconfig-strict
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```fixed
|
|
51
|
+
{
|
|
52
|
+
"compilerOptions": {
|
|
53
|
+
"strict": true
|
|
54
|
+
},
|
|
55
|
+
"include": ["src"]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: json/tsconfig-strict
|
|
3
|
+
title: "tsconfig.json turns on strict mode"
|
|
4
|
+
languages: [json]
|
|
5
|
+
files: ["**/tsconfig.json", "**/tsconfig.*.json"]
|
|
6
|
+
fix: suggest
|
|
7
|
+
fix_reason: "turning on strict mode can surface type errors the code then has to fix"
|
|
8
|
+
stability: preview
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A `tsconfig.json` sets `"strict": true` in `compilerOptions`. A config that `extends` another and doesn't set `strict` itself is left alone, since it may inherit it.
|
|
13
|
+
|
|
14
|
+
**Why:** Strict mode turns on the checks that catch `null` and `undefined` mistakes and implicit `any`; without it the compiler lets most of those bugs through.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: json/tsconfig-strict
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Examples
|
|
21
|
+
|
|
22
|
+
### JSON
|
|
23
|
+
|
|
24
|
+
#### Don't
|
|
25
|
+
|
|
26
|
+
```json path=tsconfig.json
|
|
27
|
+
{
|
|
28
|
+
"compilerOptions": {
|
|
29
|
+
"target": "es2022",
|
|
30
|
+
"module": "nodenext"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Do
|
|
36
|
+
|
|
37
|
+
```json path=tsconfig.json
|
|
38
|
+
{
|
|
39
|
+
"compilerOptions": {
|
|
40
|
+
"strict": true,
|
|
41
|
+
"target": "es2022",
|
|
42
|
+
"module": "nodenext"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/commands-show-output
|
|
3
|
+
title: "No $ before shell commands that show no output"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: auto
|
|
6
|
+
stability: preview
|
|
7
|
+
ported_from: [markdownlint/MD014]
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
A code block in which every line is a command starting with `$` drops the `$`. A block that also shows output keeps it, since the `$` then tells commands from output.
|
|
12
|
+
|
|
13
|
+
**Why:** Readers copy commands straight from the block, and a pasted `$` makes every one of them fail.
|
|
14
|
+
|
|
15
|
+
```codelaw
|
|
16
|
+
native: md/commands-show-output
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
### Markdown
|
|
22
|
+
|
|
23
|
+
#### Don't
|
|
24
|
+
|
|
25
|
+
````md
|
|
26
|
+
```sh
|
|
27
|
+
$ npm install
|
|
28
|
+
$ npm test
|
|
29
|
+
```
|
|
30
|
+
````
|
|
31
|
+
|
|
32
|
+
#### Do
|
|
33
|
+
|
|
34
|
+
````md
|
|
35
|
+
```sh
|
|
36
|
+
npm install
|
|
37
|
+
npm test
|
|
38
|
+
```
|
|
39
|
+
````
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/descriptive-link-text
|
|
3
|
+
title: "Link text says where the link goes"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "describing the target needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
prohibited_texts: { type: "string[]", default: ["click here", "here", "link", "more"], description: "link texts that say nothing about the target, compared ignoring case and punctuation" }
|
|
10
|
+
ported_from: [markdownlint/MD059]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
A link's text is not a generic phrase such as "click here", "here", "link" or "more".
|
|
15
|
+
|
|
16
|
+
**Why:** Screen-reader users often jump from link to link, hearing only the link text; "here" tells them nothing.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: md/descriptive-link-text
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Say in a few words what the link leads to.
|
|
25
|
+
2. Make those words the link text.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### Markdown
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
````md
|
|
34
|
+
For details, click [here](docs/setup.md).
|
|
35
|
+
````
|
|
36
|
+
|
|
37
|
+
#### Do
|
|
38
|
+
|
|
39
|
+
````md
|
|
40
|
+
For details, see [the setup guide](docs/setup.md).
|
|
41
|
+
````
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/fence-language
|
|
3
|
+
title: "Fenced code blocks name their language"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which language the code is in can't always be told from the code"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [markdownlint/MD040]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A fenced code block names its language after the opening fence: ` ```ts `, ` ```sh `, or ` ```text ` for plain output.
|
|
13
|
+
|
|
14
|
+
**Why:** The language drives syntax highlighting, and lets tools — codelaw's `lint_code_blocks` among them — check the code inside.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
match:
|
|
18
|
+
kind: fenced_code_block
|
|
19
|
+
not:
|
|
20
|
+
has: { kind: info_string }
|
|
21
|
+
message: "Name the code's language after the opening fence, or `text` for plain output"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
|
|
26
|
+
1. Work out what the block holds.
|
|
27
|
+
2. Add its language after the opening fence, or `text` when it is plain output.
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
### Markdown
|
|
32
|
+
|
|
33
|
+
#### Don't
|
|
34
|
+
|
|
35
|
+
````md
|
|
36
|
+
```
|
|
37
|
+
npm install codelaw
|
|
38
|
+
```
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
#### Do
|
|
42
|
+
|
|
43
|
+
````md
|
|
44
|
+
```sh
|
|
45
|
+
npm install codelaw
|
|
46
|
+
```
|
|
47
|
+
````
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# md/first-line-heading — edge cases
|
|
2
|
+
|
|
3
|
+
### case: HTML title and leading comment
|
|
4
|
+
|
|
5
|
+
````md
|
|
6
|
+
<!-- generated -->
|
|
7
|
+
<h1 align="center">Tool</h1>
|
|
8
|
+
|
|
9
|
+
Text.
|
|
10
|
+
````
|
|
11
|
+
|
|
12
|
+
```expect
|
|
13
|
+
(none)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### case: front matter title
|
|
17
|
+
|
|
18
|
+
````md
|
|
19
|
+
---
|
|
20
|
+
title: Tool
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Text.
|
|
24
|
+
````
|
|
25
|
+
|
|
26
|
+
```expect
|
|
27
|
+
(none)
|
|
28
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/first-line-heading
|
|
3
|
+
title: "A document starts with its title heading"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the title text needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
level: { type: "integer", default: 1, description: "the level of the title heading" }
|
|
10
|
+
allow_preamble: { type: "boolean", default: false, description: "allow text before the title heading" }
|
|
11
|
+
ported_from: [markdownlint/MD041]
|
|
12
|
+
since: 0.1.0
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
The first block of a document, after any front matter and HTML comments, is a level-1 heading — Markdown, or an HTML `<h1>`. A front matter `title:` counts as the heading.
|
|
16
|
+
|
|
17
|
+
**Why:** The first heading names the document for readers, search results and tools that build navigation from it.
|
|
18
|
+
|
|
19
|
+
```codelaw
|
|
20
|
+
native: md/first-line-heading
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
1. Write a heading that names the document.
|
|
26
|
+
2. Put it first, above any introduction.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### Markdown
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
````md
|
|
35
|
+
This tool formats code.
|
|
36
|
+
|
|
37
|
+
# Formatter
|
|
38
|
+
````
|
|
39
|
+
|
|
40
|
+
#### Do
|
|
41
|
+
|
|
42
|
+
````md
|
|
43
|
+
# Formatter
|
|
44
|
+
|
|
45
|
+
This tool formats code.
|
|
46
|
+
````
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# md/heading-increment — edge cases
|
|
2
|
+
|
|
3
|
+
### case: front matter title
|
|
4
|
+
|
|
5
|
+
````md
|
|
6
|
+
---
|
|
7
|
+
title: Guide
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
### Setup
|
|
11
|
+
````
|
|
12
|
+
|
|
13
|
+
```expect
|
|
14
|
+
5:1 md/heading-increment
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
````fixed
|
|
18
|
+
---
|
|
19
|
+
title: Guide
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
### case: subsections move with the fixed heading
|
|
26
|
+
|
|
27
|
+
````md
|
|
28
|
+
# A
|
|
29
|
+
|
|
30
|
+
### B
|
|
31
|
+
|
|
32
|
+
#### C
|
|
33
|
+
|
|
34
|
+
## D
|
|
35
|
+
````
|
|
36
|
+
|
|
37
|
+
```expect
|
|
38
|
+
3:1 md/heading-increment
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
````fixed
|
|
42
|
+
# A
|
|
43
|
+
|
|
44
|
+
## B
|
|
45
|
+
|
|
46
|
+
### C
|
|
47
|
+
|
|
48
|
+
## D
|
|
49
|
+
````
|
|
50
|
+
|
|
51
|
+
### case: first heading may start deep
|
|
52
|
+
|
|
53
|
+
````md
|
|
54
|
+
## A
|
|
55
|
+
|
|
56
|
+
### B
|
|
57
|
+
````
|
|
58
|
+
|
|
59
|
+
```expect
|
|
60
|
+
(none)
|
|
61
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/heading-increment
|
|
3
|
+
title: "Heading levels go down one at a time"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "the fix raises the skipped heading and its subsections, which changes the outline readers and tools see"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [markdownlint/MD001]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
A heading is at most one level deeper than the heading before it: `#` can be followed by `##`, not by `###`. When the front matter has a `title:`, it counts as the level-1 heading.
|
|
13
|
+
|
|
14
|
+
**Why:** Headings are the document's outline; a skipped level leaves a section with no parent, which confuses screen readers and tables of contents.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: md/heading-increment
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Examples
|
|
21
|
+
|
|
22
|
+
### Markdown
|
|
23
|
+
|
|
24
|
+
#### Don't
|
|
25
|
+
|
|
26
|
+
````md
|
|
27
|
+
# Install
|
|
28
|
+
|
|
29
|
+
### From npm
|
|
30
|
+
|
|
31
|
+
Run the installer.
|
|
32
|
+
````
|
|
33
|
+
|
|
34
|
+
#### Do
|
|
35
|
+
|
|
36
|
+
````md
|
|
37
|
+
# Install
|
|
38
|
+
|
|
39
|
+
## From npm
|
|
40
|
+
|
|
41
|
+
Run the installer.
|
|
42
|
+
````
|
|
43
|
+
|
|
44
|
+
## Differences from the source
|
|
45
|
+
|
|
46
|
+
The fix renumbers the whole outline at once: a raised heading's subsections move up with it.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# md/link-fragments — edge cases
|
|
2
|
+
|
|
3
|
+
### case: repeated headings, HTML anchor, line anchor
|
|
4
|
+
|
|
5
|
+
````md
|
|
6
|
+
# Notes
|
|
7
|
+
|
|
8
|
+
## Usage: `x`
|
|
9
|
+
|
|
10
|
+
## Usage: `x`
|
|
11
|
+
|
|
12
|
+
<a id="custom"></a>
|
|
13
|
+
|
|
14
|
+
[a](#usage-x-1) [b](#custom) [c](#L10) [d](#top)
|
|
15
|
+
````
|
|
16
|
+
|
|
17
|
+
```expect
|
|
18
|
+
(none)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### case: wrong case
|
|
22
|
+
|
|
23
|
+
````md
|
|
24
|
+
# My Title
|
|
25
|
+
|
|
26
|
+
[a](#My-Title)
|
|
27
|
+
````
|
|
28
|
+
|
|
29
|
+
```expect
|
|
30
|
+
3:1 md/link-fragments
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### case: reference definition
|
|
34
|
+
|
|
35
|
+
````md
|
|
36
|
+
# Title
|
|
37
|
+
|
|
38
|
+
[a][x]
|
|
39
|
+
|
|
40
|
+
[x]: #nowhere
|
|
41
|
+
````
|
|
42
|
+
|
|
43
|
+
```expect
|
|
44
|
+
5:1 md/link-fragments
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### case: percent before a multi-byte character
|
|
48
|
+
|
|
49
|
+
````md
|
|
50
|
+
# Title
|
|
51
|
+
|
|
52
|
+
[a](#%aé) [b](#%74itle)
|
|
53
|
+
````
|
|
54
|
+
|
|
55
|
+
```expect
|
|
56
|
+
3:1 md/link-fragments
|
|
57
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: md/link-fragments
|
|
3
|
+
title: "In-page links point at a heading or anchor that exists"
|
|
4
|
+
languages: [markdown]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "which section the link meant needs the author"
|
|
7
|
+
stability: preview
|
|
8
|
+
options:
|
|
9
|
+
ignore_case: { type: "boolean", default: false, description: "compare fragments with anchors ignoring case" }
|
|
10
|
+
ported_from: [markdownlint/MD051]
|
|
11
|
+
since: 0.1.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
A link to `#fragment` in the same document matches an anchor: a heading's GitHub-style id (lower case, punctuation dropped, spaces as dashes, `-1`, `-2` … for repeats), a `{#id}` after a heading, or an HTML `id` or `name`. `#top` and GitHub line anchors such as `#L20` are always valid.
|
|
15
|
+
|
|
16
|
+
**Why:** A fragment that matches nothing scrolls nowhere; it is usually a heading that was renamed after the link was written.
|
|
17
|
+
|
|
18
|
+
```codelaw
|
|
19
|
+
native: md/link-fragments
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
|
|
24
|
+
1. Find the section the link meant.
|
|
25
|
+
2. Change the fragment to that heading's id, or add an anchor where the link should land.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### Markdown
|
|
30
|
+
|
|
31
|
+
#### Don't
|
|
32
|
+
|
|
33
|
+
````md
|
|
34
|
+
# Guide
|
|
35
|
+
|
|
36
|
+
## Getting started
|
|
37
|
+
|
|
38
|
+
See [the first steps](#getting-startd).
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
#### Do
|
|
42
|
+
|
|
43
|
+
````md
|
|
44
|
+
# Guide
|
|
45
|
+
|
|
46
|
+
## Getting started
|
|
47
|
+
|
|
48
|
+
See [the first steps](#getting-started).
|
|
49
|
+
````
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# md/link-image-reference-definitions — edge cases
|
|
2
|
+
|
|
3
|
+
### case: comment idiom and shortcut use
|
|
4
|
+
|
|
5
|
+
````md
|
|
6
|
+
[//]: # (a comment)
|
|
7
|
+
|
|
8
|
+
See [docs].
|
|
9
|
+
|
|
10
|
+
[docs]: https://example.com
|
|
11
|
+
````
|
|
12
|
+
|
|
13
|
+
```expect
|
|
14
|
+
(none)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### case: unused definition of a fragment
|
|
18
|
+
|
|
19
|
+
````md
|
|
20
|
+
Text.
|
|
21
|
+
|
|
22
|
+
[end]: #end
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
```expect
|
|
26
|
+
3:1 md/link-image-reference-definitions
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
````fixed
|
|
30
|
+
Text.
|
|
31
|
+
|
|
32
|
+
````
|
|
33
|
+
|
|
34
|
+
### case: defined twice
|
|
35
|
+
|
|
36
|
+
````md
|
|
37
|
+
See [a].
|
|
38
|
+
|
|
39
|
+
[a]: https://one.example
|
|
40
|
+
[a]: https://two.example
|
|
41
|
+
````
|
|
42
|
+
|
|
43
|
+
```expect
|
|
44
|
+
4:1 md/link-image-reference-definitions
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
````fixed
|
|
48
|
+
See [a].
|
|
49
|
+
|
|
50
|
+
[a]: https://one.example
|
|
51
|
+
````
|