@diplodoc/yfmlint 1.3.3 → 1.3.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/README.md CHANGED
@@ -1,75 +1,226 @@
1
1
  [![NPM version](https://img.shields.io/npm/v/@diplodoc/yfmlint.svg?style=flat)](https://www.npmjs.org/package/@diplodoc/yfmlint)
2
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=alert_status)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
3
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=coverage)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
4
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
5
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
6
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=security_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
2
7
 
3
8
  # YFM syntax linter
4
9
 
5
- ## Usage
10
+ YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform. Extends [markdownlint](https://github.com/DavidAnson/markdownlint) with YFM-specific validation rules.
6
11
 
7
- ```
12
+ ## Features
13
+
14
+ - **11 custom YFM rules** (YFM001-YFM011) for validating YFM-specific syntax
15
+ - **Integration with markdownlint** - all standard markdownlint rules are available
16
+ - **Plugin support** - integrates with plugins from `@diplodoc/transform` (e.g., `term` plugin)
17
+ - **Configurable rule levels** - error, warn, info, or disabled
18
+ - **Source map support** - accurate error reporting after Liquid template processing
19
+
20
+ ## Installation
21
+
22
+ ```bash
8
23
  npm install @diplodoc/yfmlint
9
24
  ```
10
25
 
26
+ ## Usage
27
+
28
+ ### Basic Example
29
+
11
30
  ```javascript
12
- import {yfmlint, log} from '@diplodoc/yfmlint';
31
+ import {yfmlint, log, LogLevels} from '@diplodoc/yfmlint';
32
+
33
+ const content = `# Title
13
34
 
14
- const errors = await yfmlint(content, path, options);
35
+ [Link to missing file](./missing.md)
36
+ `;
15
37
 
16
- if (errors) {
17
- resourcemap(errors);
18
- log(errors, logger);
38
+ const errors = await yfmlint(content, 'example.md', {
39
+ lintConfig: {
40
+ YFM003: LogLevels.ERROR, // Unreachable link
41
+ },
42
+ });
43
+
44
+ if (errors && errors.length > 0) {
45
+ log(errors, console);
19
46
  }
20
47
  ```
21
48
 
22
- ## YFM rules
49
+ ### With Plugins
50
+
51
+ ```javascript
52
+ import {yfmlint} from '@diplodoc/yfmlint';
53
+ import termPlugin from '@diplodoc/transform/plugins/term';
54
+
55
+ const errors = await yfmlint(content, path, {
56
+ plugins: [termPlugin],
57
+ pluginOptions: {
58
+ // Plugin-specific options
59
+ },
60
+ lintConfig: {
61
+ YFM007: true, // Term used without definition
62
+ YFM009: 'warn', // Term definition not at end of file
63
+ },
64
+ });
65
+ ```
66
+
67
+ ### Configuration
23
68
 
24
- [All markdownlint rules](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md)
69
+ Rules can be configured with different log levels:
70
+
71
+ ```javascript
72
+ const lintConfig = {
73
+ // Boolean: true = warn, false = disabled
74
+ YFM001: true,
75
+ YFM002: false,
76
+
77
+ // String: log level name
78
+ YFM003: 'error',
79
+ YFM004: 'warn',
80
+ YFM005: 'info',
81
+
82
+ // Object: full configuration
83
+ YFM001: {
84
+ level: 'warn',
85
+ maximum: 120, // Custom parameter
86
+ },
87
+ };
88
+ ```
89
+
90
+ ## Documentation
91
+
92
+ For detailed information about architecture, development, and contributing, see [AGENTS.md](./AGENTS.md).
93
+
94
+ ## YFM Rules
95
+
96
+ This package extends markdownlint with 11 custom rules for YFM syntax validation. All standard [markdownlint rules](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) are also available.
25
97
 
26
98
  ### YFM001 - Inline code line length
27
99
 
28
- Tags: line_length
100
+ **Tags:** `line_length`
101
+ **Aliases:** `inline-code-length`
102
+ **Parameters:** `maximum` (default: 100)
29
103
 
30
- Aliases: inline-code-length
104
+ Validates that inline code spans don't exceed the maximum length. Useful for preventing overly long inline code that breaks formatting.
31
105
 
32
- Parameters: maximum
106
+ **Example:**
33
107
 
34
- This rule is triggered when there are lines that are longer than the
35
- configured `value` (default: 100 characters).
108
+ ```markdown
109
+ `this is a very long inline code that exceeds the maximum length and will trigger YFM001`
110
+ ```
111
+
112
+ ### YFM002 - No header found for link
36
113
 
37
- ### YFM002 - No header found in the file for the link text
114
+ **Tags:** `links`
115
+ **Aliases:** `no-header-found-for-link`
38
116
 
39
- Tags: links
117
+ Validates that links to headers (anchors) reference existing headers in the target file.
40
118
 
41
- Aliases: no-header-found-for-link
119
+ **Example:**
42
120
 
43
- This rule is triggered when there are no headers in the file referenced by the link.
121
+ ```markdown
122
+ [Link to non-existent header](./file.md#nonexistent)
123
+ ```
44
124
 
45
- ### YFM003 - Link is unreachable
125
+ ### YFM003 - Unreachable link
46
126
 
47
- Tags: links
127
+ **Tags:** `links`
128
+ **Aliases:** `unreachable-link`
48
129
 
49
- Aliases: unreachable-link
130
+ Validates that linked files exist and are accessible. Checks for:
50
131
 
51
- This rule is triggered when there is no file referenced by the link.
132
+ - File not found
133
+ - File missing in table of contents
134
+ - Both conditions
52
135
 
53
- ### YFM004 - Table not closed
136
+ **Example:**
54
137
 
55
- Tags: table
138
+ ```markdown
139
+ [Link to missing file](./missing.md)
140
+ ```
141
+
142
+ ### YFM004 - Table not closed
56
143
 
57
- Aliases: table-not-closed
144
+ **Tags:** `table`
145
+ **Aliases:** `table-not-closed`
58
146
 
59
- This rule is triggered when table don't have close token.
147
+ Validates that YFM tables are properly closed. Requires the `table` plugin from `@diplodoc/transform`.
60
148
 
61
149
  ### YFM005 - Tab list not closed
62
150
 
63
- Tags: tab
151
+ **Tags:** `tab`
152
+ **Aliases:** `tab-list-not-closed`
64
153
 
65
- Aliases: tab-list-not-closed
154
+ Validates that YFM tab lists are properly closed. Requires the `tabs` plugin from `@diplodoc/transform`.
66
155
 
67
- This rule is triggered when tab list don't have close token.
156
+ ### YFM006 - Term definition duplicated
68
157
 
69
- ### YFM006 - Tab list not closed
158
+ **Tags:** `term`
159
+ **Aliases:** `term-definition-duplicated`
160
+
161
+ Validates that term definitions are not duplicated. Requires the `term` plugin from `@diplodoc/transform`.
162
+
163
+ **Example:**
164
+
165
+ ```markdown
166
+ [term]: definition
167
+
168
+ [term]: another definition <!-- Error: duplicate definition -->
169
+ ```
170
+
171
+ ### YFM007 - Term used without definition
172
+
173
+ **Tags:** `term`
174
+ **Aliases:** `term-used-without-definition`
175
+
176
+ Validates that all used terms have corresponding definitions. Requires the `term` plugin from `@diplodoc/transform`.
177
+
178
+ **Example:**
179
+
180
+ ```markdown
181
+ This uses [term] but no definition is provided.
182
+ ```
183
+
184
+ ### YFM008 - Term inside definition not allowed
185
+
186
+ **Tags:** `term`
187
+ **Aliases:** `term-inside-definition-not-allowed`
188
+
189
+ Validates that term definitions don't contain other terms. Requires the `term` plugin from `@diplodoc/transform`.
190
+
191
+ ### YFM009 - Term definition not at end of file
192
+
193
+ **Tags:** `term`
194
+ **Aliases:** `no-term-definition-in-content`
195
+
196
+ Validates that all term definitions are placed at the end of the file. Requires the `term` plugin from `@diplodoc/transform`.
197
+
198
+ **Example:**
199
+
200
+ ```markdown
201
+ [term]: definition
202
+
203
+ Some content here <!-- Error: content after term definitions -->
204
+
205
+ [another-term]: another definition
206
+ ```
207
+
208
+ ### YFM010 - Unreachable autotitle anchor
209
+
210
+ **Tags:** `titles`
211
+ **Aliases:** `unreachable-autotitle-anchor`
212
+
213
+ Validates that links to autotitle anchors reference existing titles.
214
+
215
+ **Example:**
216
+
217
+ ```markdown
218
+ [Link to non-existent title](#nonexistent-title)
219
+ ```
70
220
 
71
- Tags: term
221
+ ### YFM011 - Max SVG size
72
222
 
73
- Aliases: term-definition-duplicated
223
+ **Tags:** `image_svg`
224
+ **Aliases:** `max-svg-size`
74
225
 
75
- This rule is triggered when term definition duplicated.
226
+ Validates that SVG images don't exceed the maximum size limit. Requires image processing plugins from `@diplodoc/transform`.