markuplint 2.0.0-rc.6 → 2.1.1
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 +70 -20
- package/lib/api/index.d.mts +2 -0
- package/lib/api/index.mjs +2 -0
- package/lib/api/lint.d.mts +4 -0
- package/lib/api/lint.mjs +15 -0
- package/lib/api/ml-engine.d.mts +27 -0
- package/lib/api/ml-engine.mjs +232 -0
- package/lib/api/types.d.mts +43 -0
- package/lib/api/types.mjs +1 -0
- package/lib/api/v1.d.mts +51 -0
- package/lib/api/v1.mjs +39 -0
- package/lib/cli/bootstrap.d.mts +52 -0
- package/lib/cli/bootstrap.mjs +81 -0
- package/lib/cli/command.d.mts +3 -0
- package/lib/cli/command.mjs +50 -0
- package/lib/cli/create-rule/index.d.mts +1 -0
- package/lib/cli/create-rule/index.mjs +51 -0
- package/lib/cli/index.d.mts +1 -0
- package/lib/cli/index.mjs +64 -0
- package/lib/cli/index.spec.d.mts +1 -0
- package/lib/cli/index.spec.mjs +48 -0
- package/lib/cli/init/index.d.mts +1 -0
- package/lib/cli/init/index.mjs +266 -0
- package/lib/cli/init/install-module.d.mts +5 -0
- package/lib/cli/init/install-module.mjs +61 -0
- package/lib/cli/output.d.mts +3 -0
- package/lib/cli/output.mjs +31 -0
- package/lib/cli/prompt.d.mts +18 -0
- package/lib/cli/prompt.mjs +68 -0
- package/lib/debug.d.mts +3 -0
- package/lib/debug.mjs +10 -0
- package/lib/global-settings.d.mts +5 -0
- package/lib/global-settings.mjs +10 -0
- package/lib/i18n.d.mts +6 -0
- package/lib/i18n.mjs +19 -0
- package/lib/index.d.mts +8 -0
- package/lib/index.mjs +8 -0
- package/lib/reporter/index.d.mts +2 -0
- package/lib/reporter/index.mjs +2 -0
- package/lib/reporter/simple-reporter.d.mts +3 -0
- package/lib/reporter/simple-reporter.mjs +30 -0
- package/lib/reporter/standard-reporter.d.mts +3 -0
- package/lib/reporter/standard-reporter.mjs +43 -0
- package/lib/testing-tool/index.d.mts +35 -0
- package/lib/testing-tool/index.mjs +83 -0
- package/lib/types.d.mts +27 -0
- package/lib/types.mjs +1 -0
- package/lib/util.d.mts +19 -0
- package/lib/util.mjs +73 -0
- package/lib/v1.d.mts +4 -0
- package/lib/v1.mjs +4 -0
- package/media/screenshot01.png +0 -0
- package/package.json +14 -14
- package/tsconfig.tsbuildinfo +1 -1
- package/RESOLVE_CONFIG.md +0 -77
- package/lib/cli/head.d.ts +0 -1
- package/lib/cli/head.js +0 -31
- package/lib/reporter/utils.d.ts +0 -6
- package/lib/reporter/utils.js +0 -40
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare type SelectQuestion<T> = {
|
|
2
|
+
message: string;
|
|
3
|
+
choices: {
|
|
4
|
+
name: string;
|
|
5
|
+
value: T;
|
|
6
|
+
}[];
|
|
7
|
+
};
|
|
8
|
+
export declare function select<T>(question: SelectQuestion<T>): Promise<T>;
|
|
9
|
+
export declare function multiSelect<T>(question: SelectQuestion<T>): Promise<T[]>;
|
|
10
|
+
export declare function input<T extends string = string>(question: string, validation?: RegExp): Promise<T>;
|
|
11
|
+
export declare function confirm(question: string, options?: {
|
|
12
|
+
initial?: boolean;
|
|
13
|
+
}): Promise<boolean>;
|
|
14
|
+
export declare function confirmSequence<T extends string = string>(questions: {
|
|
15
|
+
message: string;
|
|
16
|
+
name: T;
|
|
17
|
+
}[]): Promise<Record<T, boolean>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import c from 'cli-color';
|
|
2
|
+
import enquirer from 'enquirer';
|
|
3
|
+
const { prompt } = enquirer;
|
|
4
|
+
export async function select(question) {
|
|
5
|
+
const res = await prompt({
|
|
6
|
+
...question,
|
|
7
|
+
name: '__Q__',
|
|
8
|
+
type: 'select',
|
|
9
|
+
result(resName) {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
return this.options.choices.find(c => c.name === resName)?.value;
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return res['__Q__'];
|
|
16
|
+
}
|
|
17
|
+
export async function multiSelect(question) {
|
|
18
|
+
const res = await prompt({
|
|
19
|
+
...question,
|
|
20
|
+
name: '__Q__',
|
|
21
|
+
type: 'multiselect',
|
|
22
|
+
result(names) {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const map = this.map(names);
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
const values = names.map(name => map[name]);
|
|
27
|
+
return values;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return res['__Q__'];
|
|
32
|
+
}
|
|
33
|
+
export async function input(question, validation) {
|
|
34
|
+
// eslint-disable-next-line no-constant-condition
|
|
35
|
+
while (true) {
|
|
36
|
+
const _res = await prompt({
|
|
37
|
+
message: question,
|
|
38
|
+
name: '__Q__',
|
|
39
|
+
type: 'input',
|
|
40
|
+
});
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
const res = _res['__Q__'];
|
|
43
|
+
if (validation && !validation.test(res)) {
|
|
44
|
+
process.stdout.write(c.yellow('Oops! The name that you type is an invalid format.\n'));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function confirm(question, options) {
|
|
51
|
+
const res = await prompt({
|
|
52
|
+
message: question,
|
|
53
|
+
name: '__Q__',
|
|
54
|
+
type: 'confirm',
|
|
55
|
+
initial: !!options?.initial,
|
|
56
|
+
});
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
return !!res['__Q__'];
|
|
59
|
+
}
|
|
60
|
+
export async function confirmSequence(questions) {
|
|
61
|
+
const res = await prompt(questions.map(question => {
|
|
62
|
+
return {
|
|
63
|
+
...question,
|
|
64
|
+
type: 'confirm',
|
|
65
|
+
};
|
|
66
|
+
}));
|
|
67
|
+
return res;
|
|
68
|
+
}
|
package/lib/debug.d.mts
ADDED
package/lib/debug.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { enableDebug } from '@markuplint/ml-core';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
export const log = debug('markuplint-cli');
|
|
4
|
+
export function verbosely() {
|
|
5
|
+
if (!log.enabled) {
|
|
6
|
+
debug.enable(`${log.namespace}*`);
|
|
7
|
+
log(`Debug enable: ${log.namespace}`);
|
|
8
|
+
}
|
|
9
|
+
enableDebug();
|
|
10
|
+
}
|
package/lib/i18n.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function i18n(locale?: string): Promise<{
|
|
2
|
+
locale: string;
|
|
3
|
+
listFormat?: import("packages/@markuplint/i18n/src/types.js").ListFormat | undefined;
|
|
4
|
+
keywords?: import("packages/@markuplint/i18n/src/types.js").LocalesKeywords | undefined;
|
|
5
|
+
sentences?: import("packages/@markuplint/i18n/src/types.js").LocalesKeywords | undefined;
|
|
6
|
+
}>;
|
package/lib/i18n.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { osLocale } from 'os-locale';
|
|
2
|
+
let cachedLocale = null;
|
|
3
|
+
async function getLocale() {
|
|
4
|
+
if (!cachedLocale) {
|
|
5
|
+
cachedLocale = await osLocale({ spawn: true });
|
|
6
|
+
}
|
|
7
|
+
return cachedLocale;
|
|
8
|
+
}
|
|
9
|
+
export async function i18n(locale) {
|
|
10
|
+
locale = locale || (await getLocale()) || 'en';
|
|
11
|
+
const langCode = locale.split('-')[0];
|
|
12
|
+
const localeSet = langCode
|
|
13
|
+
? await import(`@markuplint/i18n/locales/${langCode}`).catch(() => null)
|
|
14
|
+
: null;
|
|
15
|
+
return {
|
|
16
|
+
locale: langCode,
|
|
17
|
+
...localeSet,
|
|
18
|
+
};
|
|
19
|
+
}
|
package/lib/index.d.mts
ADDED
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import c from 'cli-color';
|
|
2
|
+
import { markuplint, messageToString, p, w } from '../util.mjs';
|
|
3
|
+
const loggerError = c.red;
|
|
4
|
+
const loggerWarning = c.xterm(208);
|
|
5
|
+
export function simpleReporter(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
|
+
out.push(`<${markuplint}> ${c.underline(results.filePath)}: ${loggerError('✗')}`);
|
|
20
|
+
for (const violation of results.violations) {
|
|
21
|
+
const s = violation.severity === 'error' ? loggerError('✖') : loggerWarning('⚠️');
|
|
22
|
+
const meg = messageToString(violation.message, violation.reason);
|
|
23
|
+
out.push(` ${c.cyan(`${p(violation.line, sizes.line, true)}:${p(violation.col, sizes.col)}`)} ${s} ${p(meg, sizes.meg)} ${c.xterm(8)(violation.ruleId)} `);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (!options.problemOnly) {
|
|
27
|
+
out.push(`<${markuplint}> ${c.underline(results.filePath)}: ${c.green('✓')}`);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/util.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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
ADDED
package/lib/v1.mjs
ADDED
package/media/screenshot01.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markuplint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A Linter for All Markup Languages.",
|
|
5
5
|
"author": "Yusuke Hirao",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"execa": "^5.1.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@markuplint/create-rule-helper": "2.0.0
|
|
29
|
-
"@markuplint/file-resolver": "2.0.0
|
|
30
|
-
"@markuplint/html-parser": "2.0.0
|
|
31
|
-
"@markuplint/html-spec": "2.
|
|
32
|
-
"@markuplint/i18n": "2.0.0
|
|
33
|
-
"@markuplint/ml-ast": "2.0.0
|
|
34
|
-
"@markuplint/ml-config": "2.0.0
|
|
35
|
-
"@markuplint/ml-core": "2.0.0
|
|
36
|
-
"@markuplint/ml-spec": "2.0.0
|
|
37
|
-
"@markuplint/rules": "2.
|
|
38
|
-
"chokidar": "^3.5.
|
|
28
|
+
"@markuplint/create-rule-helper": "2.0.0",
|
|
29
|
+
"@markuplint/file-resolver": "2.0.0",
|
|
30
|
+
"@markuplint/html-parser": "2.0.0",
|
|
31
|
+
"@markuplint/html-spec": "^2.1.0",
|
|
32
|
+
"@markuplint/i18n": "2.0.0",
|
|
33
|
+
"@markuplint/ml-ast": "2.0.0",
|
|
34
|
+
"@markuplint/ml-config": "2.0.0",
|
|
35
|
+
"@markuplint/ml-core": "2.0.0",
|
|
36
|
+
"@markuplint/ml-spec": "2.0.0",
|
|
37
|
+
"@markuplint/rules": "^2.1.1",
|
|
38
|
+
"chokidar": "^3.5.3",
|
|
39
39
|
"cli-color": "^2.0.1",
|
|
40
|
-
"debug": "^4.3.
|
|
40
|
+
"debug": "^4.3.3",
|
|
41
41
|
"detect-installed": "^2.0.4",
|
|
42
42
|
"eastasianwidth": "^0.2.0",
|
|
43
43
|
"enquirer": "^2.3.6",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"tslib": "^2.3.1",
|
|
51
51
|
"uuid": "^8.3.2"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "4c735ccf6107a4aef999f8e1674527dc18e9e63c"
|
|
54
54
|
}
|