markuplint 2.1.1 → 2.2.0
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/lib/cli/bootstrap.d.ts +4 -1
- package/lib/cli/bootstrap.js +4 -0
- package/lib/cli/command.d.ts +2 -1
- package/lib/cli/command.js +2 -1
- package/lib/cli/index.js +8 -0
- package/lib/cli/search/index.d.ts +2 -0
- package/lib/cli/search/index.js +40 -0
- package/package.json +7 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/api/index.d.mts +0 -2
- package/lib/api/index.mjs +0 -2
- package/lib/api/lint.d.mts +0 -4
- package/lib/api/lint.mjs +0 -15
- package/lib/api/ml-engine.d.mts +0 -27
- package/lib/api/ml-engine.mjs +0 -232
- package/lib/api/types.d.mts +0 -43
- package/lib/api/types.mjs +0 -1
- package/lib/api/v1.d.mts +0 -51
- package/lib/api/v1.mjs +0 -39
- package/lib/cli/bootstrap.d.mts +0 -52
- package/lib/cli/bootstrap.mjs +0 -81
- package/lib/cli/command.d.mts +0 -3
- package/lib/cli/command.mjs +0 -50
- package/lib/cli/create-rule/index.d.mts +0 -1
- package/lib/cli/create-rule/index.mjs +0 -51
- package/lib/cli/index.d.mts +0 -1
- package/lib/cli/index.mjs +0 -64
- package/lib/cli/index.spec.d.mts +0 -1
- package/lib/cli/index.spec.mjs +0 -48
- package/lib/cli/init/index.d.mts +0 -1
- package/lib/cli/init/index.mjs +0 -266
- package/lib/cli/init/install-module.d.mts +0 -5
- package/lib/cli/init/install-module.mjs +0 -61
- package/lib/cli/output.d.mts +0 -3
- package/lib/cli/output.mjs +0 -31
- package/lib/cli/prompt.d.mts +0 -18
- package/lib/cli/prompt.mjs +0 -68
- package/lib/debug.d.mts +0 -3
- package/lib/debug.mjs +0 -10
- package/lib/global-settings.d.mts +0 -5
- package/lib/global-settings.mjs +0 -10
- package/lib/i18n.d.mts +0 -6
- package/lib/i18n.mjs +0 -19
- package/lib/index.d.mts +0 -8
- package/lib/index.mjs +0 -8
- package/lib/reporter/index.d.mts +0 -2
- package/lib/reporter/index.mjs +0 -2
- package/lib/reporter/simple-reporter.d.mts +0 -3
- package/lib/reporter/simple-reporter.mjs +0 -30
- package/lib/reporter/standard-reporter.d.mts +0 -3
- package/lib/reporter/standard-reporter.mjs +0 -43
- package/lib/testing-tool/index.d.mts +0 -35
- package/lib/testing-tool/index.mjs +0 -83
- package/lib/types.d.mts +0 -27
- package/lib/types.mjs +0 -1
- package/lib/util.d.mts +0 -19
- package/lib/util.mjs +0 -73
- package/lib/v1.d.mts +0 -4
- package/lib/v1.mjs +0 -4
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import c from 'cli-color';
|
|
2
|
-
import { invisibleSpace, markuplint, messageToString, p, space, w } from '../util.mjs';
|
|
3
|
-
const loggerError = c.red;
|
|
4
|
-
const loggerWarning = c.xterm(208);
|
|
5
|
-
export function standardReporter(results, options) {
|
|
6
|
-
const sizes = {
|
|
7
|
-
line: 0,
|
|
8
|
-
col: 0,
|
|
9
|
-
meg: 0,
|
|
10
|
-
};
|
|
11
|
-
for (const violation of results.violations) {
|
|
12
|
-
sizes.line = Math.max(sizes.line, violation.line.toString(10).length);
|
|
13
|
-
sizes.col = Math.max(sizes.col, violation.col.toString(10).length);
|
|
14
|
-
const meg = messageToString(violation.message, violation.reason);
|
|
15
|
-
sizes.meg = Math.max(sizes.meg, w(meg));
|
|
16
|
-
}
|
|
17
|
-
const out = [];
|
|
18
|
-
if (results.violations.length) {
|
|
19
|
-
const lines = results.sourceCode.split(/\r?\n/g);
|
|
20
|
-
for (const violation of results.violations) {
|
|
21
|
-
const prev = lines[violation.line - 2] || '';
|
|
22
|
-
const line = lines[violation.line - 1] || '';
|
|
23
|
-
const next = lines[violation.line - 0] || '';
|
|
24
|
-
const before = line.substring(0, violation.col - 1);
|
|
25
|
-
const after = line.substring(violation.col - 1 + violation.raw.length);
|
|
26
|
-
const logger = violation.severity === 'error' ? loggerError : loggerWarning;
|
|
27
|
-
const meg = messageToString(violation.message, violation.reason);
|
|
28
|
-
out.push(`<${markuplint}> ${logger(`${violation.severity}: ${meg} (${violation.ruleId}) ${c.underline(`${results.filePath}:${violation.line}:${violation.col}`)}`)}`);
|
|
29
|
-
if (violation.line - 1 > 0) {
|
|
30
|
-
out.push(` ${c.cyan(p(violation.line - 1, sizes.col, true))}: ${space(prev)}`);
|
|
31
|
-
}
|
|
32
|
-
out.push(` ${c.cyan(p(violation.line, sizes.col, true))}: ${space(before)}${c.bgRed(violation.raw)}${space(after)}`);
|
|
33
|
-
if (!options.color) {
|
|
34
|
-
out.push(` ${invisibleSpace(before)}${'^'.repeat(violation.raw.length)}${invisibleSpace(after)}`);
|
|
35
|
-
}
|
|
36
|
-
out.push(` ${c.cyan(p(violation.line + 1, sizes.col, true))}: ${space(next)}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (!options.problemOnly) {
|
|
40
|
-
out.push(`<${markuplint}> ${c.green('passed')} ${c.underline(results.filePath)}`);
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Target } from '@markuplint/file-resolver';
|
|
2
|
-
import type { Config, RuleConfigValue, Rule, RegexSelector } from '@markuplint/ml-config';
|
|
3
|
-
import type { AnyMLRule, RuleSeed } from '@markuplint/ml-core';
|
|
4
|
-
export declare function mlTest(sourceCode: string, config: Config, rules?: AnyMLRule[], locale?: string, fix?: boolean): Promise<{
|
|
5
|
-
violations: import("@markuplint/ml-config").Violation[];
|
|
6
|
-
fixedCode: string;
|
|
7
|
-
}>;
|
|
8
|
-
export declare function mlRuleTest<T extends RuleConfigValue, O = null>(rule: RuleSeed<T, O>, sourceCode: string, config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
|
|
9
|
-
rule?: Rule<T, O>;
|
|
10
|
-
nodeRule?: NodeRule<T, O>[];
|
|
11
|
-
childNodeRule?: ChildNodeRule<T, O>[];
|
|
12
|
-
}, fix?: boolean, locale?: string): Promise<{
|
|
13
|
-
violations: import("@markuplint/ml-config").Violation[];
|
|
14
|
-
fixedCode: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function mlTestFile(target: Target, config?: Config, rules?: AnyMLRule[], locale?: string, fix?: boolean): Promise<{
|
|
17
|
-
violations: import("@markuplint/ml-config").Violation[];
|
|
18
|
-
fixedCode: string;
|
|
19
|
-
}>;
|
|
20
|
-
export interface NodeRule<T extends RuleConfigValue, O = void> {
|
|
21
|
-
tagName?: string;
|
|
22
|
-
selector?: string;
|
|
23
|
-
regexSelector?: RegexSelector;
|
|
24
|
-
categories?: string[];
|
|
25
|
-
roles?: string[];
|
|
26
|
-
obsolete?: boolean;
|
|
27
|
-
rule?: Rule<T, O>;
|
|
28
|
-
}
|
|
29
|
-
export interface ChildNodeRule<T extends RuleConfigValue, O = void> {
|
|
30
|
-
tagName?: string;
|
|
31
|
-
selector?: string;
|
|
32
|
-
regexSelector?: RegexSelector;
|
|
33
|
-
inheritance?: boolean;
|
|
34
|
-
rule?: Rule<T, O>;
|
|
35
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { MLRule } from '@markuplint/ml-core';
|
|
2
|
-
import { lint } from '../api/index.mjs';
|
|
3
|
-
import { getGlobal } from '../global-settings.mjs';
|
|
4
|
-
export async function mlTest(sourceCode, config, rules, locale = 'en', fix = false) {
|
|
5
|
-
const global = getGlobal();
|
|
6
|
-
const results = await lint([{ sourceCode }], {
|
|
7
|
-
config,
|
|
8
|
-
rules,
|
|
9
|
-
locale: locale ?? global.locale,
|
|
10
|
-
fix,
|
|
11
|
-
ignoreExt: true,
|
|
12
|
-
autoLoad: true,
|
|
13
|
-
importPresetRules: !rules,
|
|
14
|
-
});
|
|
15
|
-
const result = results[0];
|
|
16
|
-
return {
|
|
17
|
-
violations: result?.violations ?? [],
|
|
18
|
-
fixedCode: result?.fixedCode ?? sourceCode,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false, locale = 'en') {
|
|
22
|
-
const _config = {
|
|
23
|
-
...config,
|
|
24
|
-
rules: config.rule !== undefined
|
|
25
|
-
? {
|
|
26
|
-
'<current-rule>': config.rule,
|
|
27
|
-
}
|
|
28
|
-
: config.rule === undefined && config.nodeRule === undefined && config.childNodeRule === undefined
|
|
29
|
-
? {
|
|
30
|
-
'<current-rule>': true,
|
|
31
|
-
}
|
|
32
|
-
: undefined,
|
|
33
|
-
nodeRules: config.nodeRule !== undefined
|
|
34
|
-
? config.nodeRule.map(nodeConfig => ({
|
|
35
|
-
...nodeConfig,
|
|
36
|
-
rules: nodeConfig.rule !== undefined
|
|
37
|
-
? {
|
|
38
|
-
'<current-rule>': nodeConfig.rule,
|
|
39
|
-
}
|
|
40
|
-
: undefined,
|
|
41
|
-
}))
|
|
42
|
-
: undefined,
|
|
43
|
-
childNodeRules: config.childNodeRule !== undefined
|
|
44
|
-
? config.childNodeRule.map(childNodeConfig => ({
|
|
45
|
-
...childNodeConfig,
|
|
46
|
-
rules: childNodeConfig.rule !== undefined
|
|
47
|
-
? {
|
|
48
|
-
'<current-rule>': childNodeConfig.rule,
|
|
49
|
-
}
|
|
50
|
-
: undefined,
|
|
51
|
-
}))
|
|
52
|
-
: undefined,
|
|
53
|
-
};
|
|
54
|
-
const res = await mlTest(sourceCode, _config, [
|
|
55
|
-
new MLRule({
|
|
56
|
-
name: '<current-rule>',
|
|
57
|
-
...rule,
|
|
58
|
-
}),
|
|
59
|
-
], locale, fix);
|
|
60
|
-
res.violations.map(v => {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
delete v.ruleId;
|
|
63
|
-
});
|
|
64
|
-
return res;
|
|
65
|
-
}
|
|
66
|
-
export async function mlTestFile(target, config, rules, locale, fix = false) {
|
|
67
|
-
const global = getGlobal();
|
|
68
|
-
const results = await lint([target], {
|
|
69
|
-
config,
|
|
70
|
-
rules,
|
|
71
|
-
locale: locale ?? global.locale,
|
|
72
|
-
fix,
|
|
73
|
-
ignoreExt: true,
|
|
74
|
-
noSearchConfig: !!config,
|
|
75
|
-
autoLoad: true,
|
|
76
|
-
importPresetRules: !rules,
|
|
77
|
-
});
|
|
78
|
-
const result = results[0];
|
|
79
|
-
return {
|
|
80
|
-
violations: result?.violations ?? [],
|
|
81
|
-
fixedCode: result?.fixedCode ?? result?.sourceCode,
|
|
82
|
-
};
|
|
83
|
-
}
|
package/lib/types.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Config, Violation } from '@markuplint/ml-config';
|
|
2
|
-
import type { Document, Ruleset } from '@markuplint/ml-core';
|
|
3
|
-
export interface MLResultInfo {
|
|
4
|
-
violations: Violation[];
|
|
5
|
-
filePath: string;
|
|
6
|
-
sourceCode: string;
|
|
7
|
-
fixedCode: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated
|
|
11
|
-
*/
|
|
12
|
-
export interface MLResultInfo_v1 {
|
|
13
|
-
results: Violation[];
|
|
14
|
-
filePath: string;
|
|
15
|
-
sourceCode: string;
|
|
16
|
-
fixedCode: string;
|
|
17
|
-
document: Document<any, unknown> | null;
|
|
18
|
-
parser: string;
|
|
19
|
-
locale?: string;
|
|
20
|
-
ruleset: Ruleset;
|
|
21
|
-
configSet: {
|
|
22
|
-
config: Config;
|
|
23
|
-
files: string[];
|
|
24
|
-
error: string[];
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export declare type Nullable<T> = T | null | undefined;
|
package/lib/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/util.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from './types.mjs';
|
|
2
|
-
export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
|
|
3
|
-
export declare function uuid(): string;
|
|
4
|
-
export declare const markuplint: string;
|
|
5
|
-
export declare function write(message: string): void;
|
|
6
|
-
export declare namespace write {
|
|
7
|
-
var _a: () => boolean;
|
|
8
|
-
export { _a as break };
|
|
9
|
-
}
|
|
10
|
-
export declare function error(message: string): void;
|
|
11
|
-
export declare namespace error {
|
|
12
|
-
var exit: () => never;
|
|
13
|
-
}
|
|
14
|
-
export declare const head: (method: string, noColor?: boolean | undefined) => string;
|
|
15
|
-
export declare function p(s: number | string, pad: number, start?: boolean): string;
|
|
16
|
-
export declare function w(s: string): number;
|
|
17
|
-
export declare function space(str: string): string;
|
|
18
|
-
export declare function invisibleSpace(str: string): string;
|
|
19
|
-
export declare function messageToString(message: string, reason?: string): string;
|
package/lib/util.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import c from 'cli-color';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import eastasianwidth from 'eastasianwidth';
|
|
5
|
-
import stripAnsi from 'strip-ansi';
|
|
6
|
-
import { v4 } from 'uuid';
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
export function nonNullableFilter(item) {
|
|
9
|
-
return !!item;
|
|
10
|
-
}
|
|
11
|
-
export function uuid() {
|
|
12
|
-
return v4();
|
|
13
|
-
}
|
|
14
|
-
const logo = `<${c.xterm(39)('✔')}>`;
|
|
15
|
-
const version = require('../package.json').version;
|
|
16
|
-
const eaw = eastasianwidth;
|
|
17
|
-
const box = (lines, { width = 40, padding = 1, center = false, noColor = false }) => {
|
|
18
|
-
const bt = `┌${'─'.repeat(width - 2)}┐`;
|
|
19
|
-
const pd = `│${' '.repeat(width - 2)}│`;
|
|
20
|
-
const bb = `└${'─'.repeat(width - 2)}┘`;
|
|
21
|
-
const texts = lines.map(line => {
|
|
22
|
-
const nc = stripAnsi(line);
|
|
23
|
-
const length = nc.length;
|
|
24
|
-
const pad = width - 2 - 1 - length;
|
|
25
|
-
const pad2 = Math.floor(pad / 2);
|
|
26
|
-
const padD = pad % 2;
|
|
27
|
-
const padl = center ? pad2 : 0;
|
|
28
|
-
const padr = center ? pad2 + padD : pad;
|
|
29
|
-
const text = noColor ? nc : line;
|
|
30
|
-
return `│ ${' '.repeat(padl)}${text}${' '.repeat(padr)}│`;
|
|
31
|
-
});
|
|
32
|
-
const result = [bt, pd, ...texts, pd, bb];
|
|
33
|
-
return result.join('\n');
|
|
34
|
-
};
|
|
35
|
-
export const markuplint = `markup${c.xterm(39)('lint')}`;
|
|
36
|
-
export function write(message) {
|
|
37
|
-
process.stdout.write(message + '\n');
|
|
38
|
-
}
|
|
39
|
-
write.break = () => process.stdout.write('\n');
|
|
40
|
-
export function error(message) {
|
|
41
|
-
process.stderr.write(message + '\n');
|
|
42
|
-
}
|
|
43
|
-
error.exit = () => process.exit(1);
|
|
44
|
-
export const head = (method, noColor) => box([`${logo} ${markuplint}`, c.blackBright(`v${version}`), '', c.bold(method)], {
|
|
45
|
-
center: true,
|
|
46
|
-
noColor,
|
|
47
|
-
});
|
|
48
|
-
export function p(s, pad, start = false) {
|
|
49
|
-
const l = w(`${s}`.trim());
|
|
50
|
-
const d = pad - l;
|
|
51
|
-
const _ = ' '.repeat(d < 0 ? 0 : d);
|
|
52
|
-
return start ? `${_}${s}` : `${s}${_}`;
|
|
53
|
-
}
|
|
54
|
-
export function w(s) {
|
|
55
|
-
return s.replace(/./g, _ => '0'.repeat(eaw.characterLength(_))).length;
|
|
56
|
-
}
|
|
57
|
-
export function space(str) {
|
|
58
|
-
return str
|
|
59
|
-
.replace(/\s+/g, $0 => {
|
|
60
|
-
return c.xterm(8)($0);
|
|
61
|
-
})
|
|
62
|
-
.replace(/ /g, $0 => '•')
|
|
63
|
-
.replace(/\t/g, $0 => '→ ');
|
|
64
|
-
}
|
|
65
|
-
export function invisibleSpace(str) {
|
|
66
|
-
return str.replace(/\t/g, $0 => ' ').replace(/./g, $0 => ' ');
|
|
67
|
-
}
|
|
68
|
-
export function messageToString(message, reason) {
|
|
69
|
-
if (!reason) {
|
|
70
|
-
return message;
|
|
71
|
-
}
|
|
72
|
-
return `${message} / ${reason}`;
|
|
73
|
-
}
|
package/lib/v1.d.mts
DELETED
package/lib/v1.mjs
DELETED