markdownlint-rule-numbered-headings-unique 1.0.0 → 1.0.5

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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Tomas Dahlqvist
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) Tomas Dahlqvist
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,115 +1,114 @@
1
- # markdownlint-rule-numbered-headings-unique
2
-
3
- A custom [markdownlint][markdownlint] rule that checks that headings ending in
4
- a number are unique within the document.
5
-
6
- ## Overview
7
-
8
- This rule is for the [Node.js markdownlint library][markdownlint] and its
9
- associated tools. It enforces that any heading ending in a number (e.g., `## 1`,
10
- `## Test 42`) must be unique across the entire Markdown document.
11
-
12
- ### Why?
13
-
14
- The built-in markdownlint rule [MD024] can require all headings to be globally
15
- unique (which is often too strict) or only check siblings (which can be too
16
- permissive). This rule provides a middle ground: only headings ending in a
17
- number must be unique, which is useful for structured documents like release
18
- notes or test case lists.
19
-
20
- **Examples of where this is useful:**
21
-
22
- - Release notes
23
- - Test case documents
24
-
25
- **Example structure:**
26
-
27
- ```markdown
28
- ## Obsolete versions
29
-
30
- ### 1.8
31
-
32
- #### New features
33
-
34
- #### Bugs fixed
35
-
36
- ### 1.9
37
-
38
- #### New features
39
-
40
- #### Bugs fixed
41
-
42
- ## Current versions
43
-
44
- ### 2.0
45
-
46
- #### New features
47
-
48
- #### Bugs fixed
49
-
50
- ### 2.1
51
-
52
- #### New features
53
-
54
- #### Bugs fixed
55
- ```
56
-
57
- ## Installation
58
-
59
- ```sh
60
- npm install --save-dev markdownlint-rule-numbered-headings-unique
61
- ```
62
-
63
- ## Usage
64
-
65
- ### With markdownlint-cli
66
-
67
- ```sh
68
- markdownlint --rules ./numbered-headings-unique.cjs *.md
69
- ```
70
-
71
- ### With markdownlint-cli2
72
-
73
- Add to your `.markdownlint-cli2.jsonc`:
74
-
75
- ```jsonc
76
- {
77
- "customRules": [
78
- "./numbered-headings-unique.cjs"
79
- ]
80
- }
81
- ```
82
-
83
- Or to `.markdownlint-cli2.yaml`:
84
-
85
- ```yaml
86
- customRules:
87
- - ./numbered-headings-unique.cjs
88
- ```
89
-
90
- ### With VS Code
91
-
92
- If using the [`markdownlint` extension for VS Code][vscode-markdownlint], see
93
- the markdownlint-cli2 examples above or refer to the extension documentation.
94
-
95
- ## Testing
96
-
97
- To run the tests:
98
-
99
- ```sh
100
- npm test
101
- ```
102
-
103
- ## Contributing
104
-
105
- Pull requests and issues are welcome! Please ensure your code passes linting
106
- and tests before submitting.
107
-
108
- ## License
109
-
110
- MIT
111
-
112
- [markdownlint]: [https://github.com/DavidAnson/markdownlint]
113
- [vscode-markdownlint]: [https://marketplace.visualstudio.com/items?itemName=
114
- DavidAnson.vscode-markdownlint]
115
- [MD024]: [https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md]
1
+ # markdownlint-rule-numbered-headings-unique
2
+
3
+ A custom [markdownlint][markdownlint] rule that checks that headings ending in
4
+ a number are unique within the document.
5
+
6
+ ## Overview
7
+
8
+ This rule is for the [Node.js markdownlint library][markdownlint] and its
9
+ associated tools. It enforces that any heading ending in a number (e.g., `## 1`,
10
+ `## Test 42`) must be unique across the entire Markdown document.
11
+
12
+ ### Why?
13
+
14
+ The built-in markdownlint rule [MD024] can require all headings to be globally
15
+ unique (which is often too strict) or only check siblings (which can be too
16
+ permissive). This rule provides a middle ground: only headings ending in a
17
+ number must be unique, which is useful for structured documents like release
18
+ notes or test case lists.
19
+
20
+ **Examples of where this is useful:**
21
+
22
+ - Release notes
23
+ - Test case documents
24
+
25
+ **Example structure:**
26
+
27
+ ```markdown
28
+ ## Obsolete versions
29
+
30
+ ### 1.8
31
+
32
+ #### New features
33
+
34
+ #### Bugs fixed
35
+
36
+ ### 1.9
37
+
38
+ #### New features
39
+
40
+ #### Bugs fixed
41
+
42
+ ## Current versions
43
+
44
+ ### 2.0
45
+
46
+ #### New features
47
+
48
+ #### Bugs fixed
49
+
50
+ ### 2.1
51
+
52
+ #### New features
53
+
54
+ #### Bugs fixed
55
+ ```
56
+
57
+ ## Installation
58
+
59
+ ```sh
60
+ npm install --save-dev markdownlint-rule-numbered-headings-unique
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ ### With markdownlint-cli
66
+
67
+ ```sh
68
+ markdownlint --rules ./numbered-headings-unique.cjs *.md
69
+ ```
70
+
71
+ ### With markdownlint-cli2
72
+
73
+ Add to your `.markdownlint-cli2.jsonc`:
74
+
75
+ ```jsonc
76
+ {
77
+ "customRules": [
78
+ "./numbered-headings-unique.cjs"
79
+ ]
80
+ }
81
+ ```
82
+
83
+ Or to `.markdownlint-cli2.yaml`:
84
+
85
+ ```yaml
86
+ customRules:
87
+ - ./numbered-headings-unique.cjs
88
+ ```
89
+
90
+ ### With VS Code
91
+
92
+ If using the [`markdownlint` extension for VS Code][vscode-markdownlint], see
93
+ the markdownlint-cli2 examples above or refer to the extension documentation.
94
+
95
+ ## Testing
96
+
97
+ To run the tests:
98
+
99
+ ```sh
100
+ npm test
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ Pull requests and issues are welcome! Please ensure your code passes linting
106
+ and tests before submitting.
107
+
108
+ ## License
109
+
110
+ MIT
111
+
112
+ [markdownlint]: <https://github.com/DavidAnson/markdownlint>
113
+ [vscode-markdownlint]: <https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint>
114
+ [MD024]: <https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md>
@@ -1,42 +1,42 @@
1
- "use strict";
2
-
3
- /** @type import("markdownlint").Rule */
4
- module.exports = {
5
- "names": ["numbered-headings-unique"],
6
- "description": "Headings ending in a number must be unique in the document",
7
- "tags": ["headings", "headers", "numbers", "unique"],
8
- function(params, onError) {
9
-
10
- // Track seen heading numbers: text -> [lineNumbers]
11
- const seenNumbers = new Map();
12
- params.tokens.forEach((token, idx) => {
13
- if (token.type === "heading_open") {
14
- const inline = params.tokens[idx + 1];
15
- if (inline && inline.type === "inline") {
16
- const text = inline.content.trim();
17
- if (/\d+$/u.test(text)) {
18
- let lines = seenNumbers.get(text);
19
- if (lines === undefined) {
20
- lines = [token.lineNumber];
21
- seenNumbers.set(text, lines);
22
- } else {
23
- lines.push(token.lineNumber);
24
- }
25
- }
26
- }
27
- }
28
- });
29
-
30
- // Report all duplicates (all but the first occurrence)
31
- for (const [text, lines] of seenNumbers.entries()) {
32
- if (lines.length > 1) {
33
- lines.slice(1).forEach((lineNumber) => {
34
- onError({
35
- lineNumber,
36
- detail: `Heading number "${text}" is not unique in the document.`,
37
- });
38
- });
39
- }
40
- }
41
- }
42
- };
1
+ "use strict";
2
+
3
+ /** @type import("markdownlint").Rule */
4
+ module.exports = {
5
+ "names": ["numbered-headings-unique"],
6
+ "description": "Headings ending in a number must be unique in the document",
7
+ "tags": ["headings", "headers", "numbers", "unique"],
8
+ function(params, onError) {
9
+
10
+ // Track seen heading numbers: text -> [lineNumbers]
11
+ const seenNumbers = new Map();
12
+ params.tokens.forEach((token, idx) => {
13
+ if (token.type === "heading_open") {
14
+ const inline = params.tokens[idx + 1];
15
+ if (inline && inline.type === "inline") {
16
+ const text = inline.content.trim();
17
+ if (/\d+$/u.test(text)) {
18
+ let lines = seenNumbers.get(text);
19
+ if (lines === undefined) {
20
+ lines = [token.lineNumber];
21
+ seenNumbers.set(text, lines);
22
+ } else {
23
+ lines.push(token.lineNumber);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ });
29
+
30
+ // Report all duplicates (all but the first occurrence)
31
+ for (const [text, lines] of seenNumbers.entries()) {
32
+ if (lines.length > 1) {
33
+ lines.slice(1).forEach((lineNumber) => {
34
+ onError({
35
+ lineNumber,
36
+ detail: `Heading number "${text}" is not unique in the document.`,
37
+ });
38
+ });
39
+ }
40
+ }
41
+ }
42
+ };
package/package.json CHANGED
@@ -1,44 +1,42 @@
1
- {
2
- "name": "markdownlint-rule-numbered-headings-unique",
3
- "description": "A markdownlint rule that requires that headings ending in numbers are uniquely numbered",
4
- "license": "MIT",
5
- "author": "Tomas Dahlqvist",
6
- "repository": {
7
- "type": "git"
8
- },
9
- "homepage": "https://github.com/TomasDahlqvist/markdownlint-rule-numbered-headings-unique#readme",
10
- "bugs": {
11
- "url": "https://github.com/TomasDahlqvist/markdownlint-rule-numbered-headings-unique/issues"
12
- },
13
- "funding": {
14
- "url": "https://github.com/sponsors/TomasDahlqvist"
15
- },
16
- "exports": "./numbered-headings-unique.cjs",
17
- "scripts": {
18
- "lint": "markdownlint-cli2 *.md && eslint --max-warnings 0",
19
- "test": "npm run lint && node --test --experimental-test-coverage"
20
- },
21
- "files": [
22
- "package.json",
23
- "LICENSE",
24
- "README.md",
25
- "numbered-headings-unique.cjs"
26
- ],
27
- "keywords": [
28
- "markdownlint-rule",
29
- "markdownlint",
30
- "markdown",
31
- "headings",
32
- "lint"
33
- ],
34
- "devDependencies": {
35
- "@eslint/js": "9.21.0",
36
- "eslint": "9.21.0",
37
- "markdownlint-cli2": "^0.17.2"
38
- },
39
- "version": "1.0.0",
40
- "main": "index.js",
41
- "directories": {
42
- "test": "test"
43
- }
44
- }
1
+ {
2
+ "name": "markdownlint-rule-numbered-headings-unique",
3
+ "description": "A markdownlint rule that requires that headings ending in numbers are uniquely numbered",
4
+ "license": "MIT",
5
+ "author": "Tomas Dahlqvist",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/tomasdahlqvist/markdownlint-rule-numbered-headings-unique.git"
9
+ },
10
+ "homepage": "https://github.com/TomasDahlqvist/markdownlint-rule-numbered-headings-unique#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/TomasDahlqvist/markdownlint-rule-numbered-headings-unique/issues"
13
+ },
14
+ "exports": "./numbered-headings-unique.cjs",
15
+ "scripts": {
16
+ "lint": "markdownlint-cli2 *.md && eslint --max-warnings 0",
17
+ "test": "npm run lint && node --test --experimental-test-coverage"
18
+ },
19
+ "files": [
20
+ "package.json",
21
+ "LICENSE",
22
+ "README.md",
23
+ "numbered-headings-unique.cjs"
24
+ ],
25
+ "keywords": [
26
+ "markdownlint-rule",
27
+ "markdownlint",
28
+ "markdown",
29
+ "headings",
30
+ "lint"
31
+ ],
32
+ "devDependencies": {
33
+ "@eslint/js": "9.21.0",
34
+ "eslint": "^9.39.1",
35
+ "markdownlint-cli2": "^0.19.1"
36
+ },
37
+ "version": "1.0.5",
38
+ "main": "index.js",
39
+ "directories": {
40
+ "test": "test"
41
+ }
42
+ }