@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 +184 -33
- package/build/index.js +564 -603
- package/build/index.js.map +4 -4
- package/build/rules/helpers.d.ts +49 -0
- package/build/typings.d.ts +3 -1
- package/build/utils.d.ts +22 -0
- package/package.json +7 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MarkdownItToken, RuleOnError, RuleParams } from 'markdownlint';
|
|
2
|
+
import type { TokenWithAttrs } from '../typings';
|
|
3
|
+
/**
|
|
4
|
+
* Validates and adjusts lineNumber to prevent markdownlint exception.
|
|
5
|
+
* When include files are used, lineNumber might exceed the original file's line count.
|
|
6
|
+
* Also returns the file path from markdown-it env if available.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateLineNumberAndGetFilePath(params: RuleParams, rawLineNumber: number | undefined): {
|
|
9
|
+
lineNumber: number;
|
|
10
|
+
filePath: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates error context with optional file path information.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createContextWithFileInfo(baseContext: string, filePath: string, paramsName: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Finds all inline tokens containing links and calls handler for each link.
|
|
18
|
+
* Used by rules that validate links (YFM002, YFM003, YFM010).
|
|
19
|
+
*
|
|
20
|
+
* @param params - Rule parameters from markdownlint
|
|
21
|
+
* @param ruleName - Name of the rule (e.g., 'YFM002') to check in link attributes
|
|
22
|
+
* @param onError - Error callback function
|
|
23
|
+
* @param handler - Optional custom handler for each link token
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
export declare function findLinksInInlineTokens(params: RuleParams, ruleName: string, onError: RuleOnError, handler?: (link: TokenWithAttrs, inline: MarkdownItToken) => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Finds all inline tokens containing images and calls handler for each image.
|
|
29
|
+
* Used by rules that validate images (YFM011).
|
|
30
|
+
*
|
|
31
|
+
* @param params - Rule parameters from markdownlint
|
|
32
|
+
* @param ruleName - Name of the rule (e.g., 'YFM011') to check in image attributes
|
|
33
|
+
* @param onError - Error callback function
|
|
34
|
+
* @param handler - Optional custom handler for each image token
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
37
|
+
export declare function findImagesInInlineTokens(params: RuleParams, ruleName: string, onError: RuleOnError, handler?: (image: TokenWithAttrs, inline: MarkdownItToken) => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Finds all __yfm_lint tokens and calls handler for each.
|
|
40
|
+
* Used by rules that validate YFM-specific constructs (YFM004-YFM008).
|
|
41
|
+
* These tokens are created by plugins from @diplodoc/transform when isLintRun = true.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Rule parameters from markdownlint
|
|
44
|
+
* @param ruleName - Name of the rule (e.g., 'YFM004') to check in token attributes
|
|
45
|
+
* @param onError - Error callback function
|
|
46
|
+
* @param handler - Optional custom handler for each token
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
export declare function findYfmLintTokens(params: RuleParams, ruleName: string, onError: RuleOnError, handler?: (token: TokenWithAttrs) => void): void;
|
package/build/typings.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { LintError as BaseLintError, MarkdownItToken } from 'markdownlint';
|
|
2
2
|
import type { LogLevels } from './utils';
|
|
3
|
+
export type { BaseLintError };
|
|
4
|
+
export type MarkdownItPlugin = any;
|
|
3
5
|
export type RawLintConfig = {
|
|
4
6
|
default?: boolean;
|
|
5
7
|
} & {
|
|
@@ -16,7 +18,7 @@ export type LintConfig = {
|
|
|
16
18
|
[x: string]: false | RuleConfig;
|
|
17
19
|
};
|
|
18
20
|
export interface Options {
|
|
19
|
-
plugins?:
|
|
21
|
+
plugins?: MarkdownItPlugin[];
|
|
20
22
|
pluginOptions?: Record<string, unknown>;
|
|
21
23
|
lintConfig?: RawLintConfig;
|
|
22
24
|
frontMatter?: RegExp | null;
|
package/build/utils.d.ts
CHANGED
|
@@ -5,6 +5,28 @@ export declare enum LogLevels {
|
|
|
5
5
|
ERROR = "error",
|
|
6
6
|
DISABLED = "disabled"
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes and merges multiple lint configurations.
|
|
10
|
+
*
|
|
11
|
+
* Accepts various input formats and converts them to a unified LintConfig:
|
|
12
|
+
* - boolean: true -> {loglevel: 'warn'}, false -> {loglevel: 'disabled'}
|
|
13
|
+
* - string: log level name -> {loglevel: '...'}
|
|
14
|
+
* - object: {level: '...', ...} -> {loglevel: '...', ...}
|
|
15
|
+
*
|
|
16
|
+
* After merging, simplifies config by converting {loglevel: 'disabled'} to false.
|
|
17
|
+
*
|
|
18
|
+
* @param {...RawLintConfig} parts - One or more configuration objects to normalize and merge
|
|
19
|
+
* @returns {LintConfig} Normalized and merged configuration
|
|
20
|
+
*/
|
|
8
21
|
export declare function normalizeConfig(...parts: RawLintConfig[]): LintConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Gets log level for a rule based on its names.
|
|
24
|
+
* Rules can have multiple names (e.g., ['YFM001', 'inline-code-length']).
|
|
25
|
+
* Returns the log level for the first matching rule name, or default if none found.
|
|
26
|
+
*
|
|
27
|
+
* @param {LintConfig} logLevels - Configuration object mapping rule names to log levels
|
|
28
|
+
* @param {string[]} ruleNames - Array of rule names (e.g., ['YFM001', 'inline-code-length'])
|
|
29
|
+
* @returns {LogLevels} Log level for the rule, or default if not configured
|
|
30
|
+
*/
|
|
9
31
|
export declare function getLogLevel(logLevels: LintConfig, ruleNames: string[]): LogLevels;
|
|
10
32
|
export declare function log(errors: LintError[], logger: Logger): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/yfmlint",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.5",
|
|
4
|
+
"description": "YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
7
7
|
"yfm",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
41
41
|
"test": "vitest --run",
|
|
42
42
|
"test:watch": "vitest",
|
|
43
|
+
"test:coverage": "vitest --run --coverage",
|
|
43
44
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
45
|
"lint": "lint update && lint",
|
|
45
46
|
"lint:fix": "lint update && lint fix",
|
|
@@ -47,18 +48,19 @@
|
|
|
47
48
|
"prepare": "husky"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@diplodoc/lint": "^1.2
|
|
51
|
+
"@diplodoc/lint": "^1.13.2",
|
|
51
52
|
"@diplodoc/transform": "^4.48.4",
|
|
52
53
|
"@diplodoc/tsconfig": "^1.0.2",
|
|
53
54
|
"@types/lodash": "^4.17.15",
|
|
55
|
+
"@types/markdown-it": "^13.0.9",
|
|
54
56
|
"@types/markdown-it-attrs": "^4.1.3",
|
|
55
57
|
"@vitest/coverage-v8": "^3.0.8",
|
|
56
|
-
"esbuild": "^0.19.12",
|
|
57
58
|
"lodash": "^4.17.21",
|
|
59
|
+
"markdown-it": "^13.0.2",
|
|
58
60
|
"markdown-it-attrs": "^4.3.1",
|
|
59
61
|
"markdownlint": "github:diplodoc-platform/markdownlint#no-parse-micromark",
|
|
60
62
|
"ts-dedent": "^2.2.0",
|
|
61
|
-
"typescript": "5.
|
|
63
|
+
"typescript": "5.9.3",
|
|
62
64
|
"vite": "^6.2.1",
|
|
63
65
|
"vitest": "^3.0.8"
|
|
64
66
|
}
|