markuplint 3.15.0 → 4.0.0-alpha.10
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 +1 -1
- package/README.md +4 -2
- package/bin/markuplint.mjs +3 -0
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.js +2 -10
- package/lib/api/lint.d.ts +2 -2
- package/lib/api/lint.js +5 -10
- package/lib/api/ml-engine.d.ts +28 -23
- package/lib/api/ml-engine.js +123 -103
- package/lib/api/types.d.ts +32 -32
- package/lib/api/types.js +1 -2
- package/lib/api/v1.d.ts +43 -43
- package/lib/api/v1.js +12 -20
- package/lib/cli/bootstrap.d.ts +65 -63
- package/lib/cli/bootstrap.js +12 -11
- package/lib/cli/command.d.ts +3 -7
- package/lib/cli/command.js +26 -34
- package/lib/cli/index.js +59 -71
- package/lib/cli/init/create-config.d.ts +2 -6
- package/lib/cli/init/create-config.js +14 -12
- package/lib/cli/init/get-default-rules.d.ts +3 -3
- package/lib/cli/init/get-default-rules.js +12 -53
- package/lib/cli/init/index.js +28 -37
- package/lib/cli/init/select-modules.d.ts +2 -0
- package/lib/cli/init/select-modules.js +10 -0
- package/lib/cli/init/types.d.ts +4 -15
- package/lib/cli/init/types.js +1 -2
- package/lib/cli/output.d.ts +2 -2
- package/lib/cli/output.js +8 -14
- package/lib/cli/search/index.d.ts +2 -2
- package/lib/cli/search/index.js +10 -14
- package/lib/debug.js +9 -13
- package/lib/get-json-module.d.ts +1 -0
- package/lib/get-json-module.js +10 -0
- package/lib/global-settings.d.ts +1 -1
- package/lib/global-settings.js +2 -7
- package/lib/i18n.js +8 -15
- package/lib/index.d.ts +7 -5
- package/lib/index.js +6 -10
- package/lib/reporter/github-reporter.d.ts +1 -1
- package/lib/reporter/github-reporter.js +7 -9
- package/lib/reporter/index.d.ts +3 -3
- package/lib/reporter/index.js +3 -6
- package/lib/reporter/simple-reporter.d.ts +2 -2
- package/lib/reporter/simple-reporter.js +11 -16
- package/lib/reporter/standard-reporter.d.ts +2 -2
- package/lib/reporter/standard-reporter.js +37 -28
- package/lib/testing-tool/index.d.ts +23 -41
- package/lib/testing-tool/index.js +41 -47
- package/lib/types.d.ts +17 -17
- package/lib/types.js +1 -2
- package/lib/v1.d.ts +1 -1
- package/lib/v1.js +1 -5
- package/lib/version.d.ts +1 -0
- package/lib/version.js +3 -0
- package/package.json +26 -34
- package/bin/markuplint +0 -3
- package/lib/cli/create-rule/index.d.ts +0 -1
- package/lib/cli/create-rule/index.js +0 -85
- package/lib/cli/init/install-module.d.ts +0 -7
- package/lib/cli/init/install-module.js +0 -80
- package/lib/cli/prompt.d.ts +0 -23
- package/lib/cli/prompt.js +0 -77
- package/lib/util.d.ts +0 -17
- package/lib/util.js +0 -88
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installModule = exports.selectModules = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const detect_installed_1 = tslib_1.__importDefault(require("detect-installed"));
|
|
9
|
-
const has_yarn_1 = tslib_1.__importDefault(require("has-yarn"));
|
|
10
|
-
function selectModules(selectedLangs) {
|
|
11
|
-
const modules = ['markuplint', ...selectedLangs.map(lang => `@markuplint/${lang}-parser`)];
|
|
12
|
-
if (selectedLangs.includes('vue')) {
|
|
13
|
-
modules.push('@markuplint/vue-spec');
|
|
14
|
-
}
|
|
15
|
-
if (selectedLangs.includes('jsx')) {
|
|
16
|
-
modules.push('@markuplint/react-spec');
|
|
17
|
-
}
|
|
18
|
-
return modules;
|
|
19
|
-
}
|
|
20
|
-
exports.selectModules = selectModules;
|
|
21
|
-
async function installModule(module, dev = false) {
|
|
22
|
-
module = module.map(m => m.trim());
|
|
23
|
-
const uninstallMods = [];
|
|
24
|
-
try {
|
|
25
|
-
for (const mod of module) {
|
|
26
|
-
const installed = await isInstalled(mod);
|
|
27
|
-
if (!installed) {
|
|
28
|
-
uninstallMods.push(mod);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (_) {
|
|
33
|
-
// void
|
|
34
|
-
}
|
|
35
|
-
if (uninstallMods.length === 0) {
|
|
36
|
-
return {
|
|
37
|
-
success: true,
|
|
38
|
-
alreadyExists: true,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const mod = (0, has_yarn_1.default)() ? 'yarn' : 'npm';
|
|
42
|
-
const installOpt = (0, has_yarn_1.default)() ? 'add' : 'install';
|
|
43
|
-
const opt = [installOpt];
|
|
44
|
-
if (dev) {
|
|
45
|
-
opt.push('-D');
|
|
46
|
-
}
|
|
47
|
-
if (!(0, has_yarn_1.default)()) {
|
|
48
|
-
opt.push('--legacy-peer-deps');
|
|
49
|
-
}
|
|
50
|
-
opt.push(...uninstallMods);
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
process.stdout.write(cli_color_1.default.blackBright(`${mod} ${opt.join(' ')}\n`));
|
|
53
|
-
const result = (0, child_process_1.spawnSync)(mod, opt, { stdio: 'inherit' });
|
|
54
|
-
if (result.error || result.status !== 0) {
|
|
55
|
-
const message = 'Error running command.';
|
|
56
|
-
const error = new Error(message);
|
|
57
|
-
error.stack = message;
|
|
58
|
-
reject(error);
|
|
59
|
-
}
|
|
60
|
-
resolve({
|
|
61
|
-
success: true,
|
|
62
|
-
alreadyExists: false,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
exports.installModule = installModule;
|
|
67
|
-
function isInstalled(module) {
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
try {
|
|
70
|
-
(0, detect_installed_1.default)(module, {
|
|
71
|
-
local: true,
|
|
72
|
-
}).then((exists) => {
|
|
73
|
-
resolve(exists);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
reject(err);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
package/lib/cli/prompt.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type SelectQuestion<T> = {
|
|
2
|
-
readonly message: string;
|
|
3
|
-
readonly choices: readonly {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly 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?: Readonly<RegExp>): Promise<T>;
|
|
11
|
-
export declare function confirm(
|
|
12
|
-
question: string,
|
|
13
|
-
options?: {
|
|
14
|
-
readonly initial?: boolean;
|
|
15
|
-
},
|
|
16
|
-
): Promise<boolean>;
|
|
17
|
-
export declare function confirmSequence<T extends string = string>(
|
|
18
|
-
questions: readonly {
|
|
19
|
-
readonly message: string;
|
|
20
|
-
readonly name: T;
|
|
21
|
-
}[],
|
|
22
|
-
): Promise<Record<T, boolean>>;
|
|
23
|
-
export {};
|
package/lib/cli/prompt.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.confirmSequence = exports.confirm = exports.input = exports.multiSelect = exports.select = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
|
|
6
|
-
const enquirer_1 = require("enquirer");
|
|
7
|
-
async function select(question) {
|
|
8
|
-
const res = await (0, enquirer_1.prompt)({
|
|
9
|
-
...question,
|
|
10
|
-
name: '__Q__',
|
|
11
|
-
type: 'select',
|
|
12
|
-
result(resName) {
|
|
13
|
-
var _a;
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return (_a = this.options.choices.find(c => c.name === resName)) === null || _a === void 0 ? void 0 : _a.value;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
return res['__Q__'];
|
|
20
|
-
}
|
|
21
|
-
exports.select = select;
|
|
22
|
-
async function multiSelect(question) {
|
|
23
|
-
const res = await (0, enquirer_1.prompt)({
|
|
24
|
-
...question,
|
|
25
|
-
name: '__Q__',
|
|
26
|
-
type: 'multiselect',
|
|
27
|
-
result(names) {
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
const map = this.map(names);
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
const values = names.map(name => map[name]);
|
|
32
|
-
return values;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
return res['__Q__'];
|
|
37
|
-
}
|
|
38
|
-
exports.multiSelect = multiSelect;
|
|
39
|
-
async function input(question, validation) {
|
|
40
|
-
// eslint-disable-next-line no-constant-condition
|
|
41
|
-
while (true) {
|
|
42
|
-
const _res = await (0, enquirer_1.prompt)({
|
|
43
|
-
message: question,
|
|
44
|
-
name: '__Q__',
|
|
45
|
-
type: 'input',
|
|
46
|
-
});
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
const res = _res['__Q__'];
|
|
49
|
-
if (validation && !validation.test(res)) {
|
|
50
|
-
process.stdout.write(cli_color_1.default.yellow('Oops! The name that you type is an invalid format.\n'));
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
return res;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.input = input;
|
|
57
|
-
async function confirm(question, options) {
|
|
58
|
-
const res = await (0, enquirer_1.prompt)({
|
|
59
|
-
message: question,
|
|
60
|
-
name: '__Q__',
|
|
61
|
-
type: 'confirm',
|
|
62
|
-
initial: !!(options === null || options === void 0 ? void 0 : options.initial),
|
|
63
|
-
});
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
return !!res['__Q__'];
|
|
66
|
-
}
|
|
67
|
-
exports.confirm = confirm;
|
|
68
|
-
async function confirmSequence(questions) {
|
|
69
|
-
const res = await (0, enquirer_1.prompt)(questions.map(question => {
|
|
70
|
-
return {
|
|
71
|
-
...question,
|
|
72
|
-
type: 'confirm',
|
|
73
|
-
};
|
|
74
|
-
}));
|
|
75
|
-
return res;
|
|
76
|
-
}
|
|
77
|
-
exports.confirmSequence = confirmSequence;
|
package/lib/util.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare function uuid(): string;
|
|
2
|
-
export declare const markuplint: string;
|
|
3
|
-
export declare function write(message: string): void;
|
|
4
|
-
export declare namespace write {
|
|
5
|
-
var _a: () => boolean;
|
|
6
|
-
export { _a as break };
|
|
7
|
-
}
|
|
8
|
-
export declare function error(message: string): void;
|
|
9
|
-
export declare namespace error {
|
|
10
|
-
var exit: () => never;
|
|
11
|
-
}
|
|
12
|
-
export declare const head: (method: string, noColor?: boolean) => string;
|
|
13
|
-
export declare function p(s: number | string, pad: number, start?: boolean): string;
|
|
14
|
-
export declare function w(s: string): number;
|
|
15
|
-
export declare function space(str: string): string;
|
|
16
|
-
export declare function invisibleSpace(str: string): string;
|
|
17
|
-
export declare function messageToString(message: string, reason?: string): string;
|
package/lib/util.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messageToString = exports.invisibleSpace = exports.space = exports.w = exports.p = exports.head = exports.error = exports.write = exports.markuplint = exports.uuid = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
const eastasianwidth_1 = tslib_1.__importDefault(require("eastasianwidth"));
|
|
8
|
-
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
|
-
function uuid() {
|
|
11
|
-
return (0, uuid_1.v4)();
|
|
12
|
-
}
|
|
13
|
-
exports.uuid = uuid;
|
|
14
|
-
/**
|
|
15
|
-
* Brand color (xTerm color)
|
|
16
|
-
*
|
|
17
|
-
* @see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
|
|
18
|
-
*/
|
|
19
|
-
const PRIMARY_COLOR = 33;
|
|
20
|
-
const logo = `/${cli_color_1.default.xterm(PRIMARY_COLOR)('✔')}\\`;
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
22
|
-
const version = require('../package.json').version;
|
|
23
|
-
const eaw = eastasianwidth_1.default;
|
|
24
|
-
const box = (lines, { width = 40, padding = 1, center = false, noColor = false }) => {
|
|
25
|
-
const bt = `┌${'─'.repeat(width - 2)}┐`;
|
|
26
|
-
const pd = `│${' '.repeat(width - 2)}│`;
|
|
27
|
-
const bb = `└${'─'.repeat(width - 2)}┘`;
|
|
28
|
-
const texts = lines.map(line => {
|
|
29
|
-
const nc = (0, strip_ansi_1.default)(line);
|
|
30
|
-
const length = nc.length;
|
|
31
|
-
const pad = width - 2 - 1 - length;
|
|
32
|
-
const pad2 = Math.floor(pad / 2);
|
|
33
|
-
const padD = pad % 2;
|
|
34
|
-
const padL = center ? pad2 : 0;
|
|
35
|
-
const padR = center ? pad2 + padD : pad;
|
|
36
|
-
const text = noColor ? nc : line;
|
|
37
|
-
return `│ ${' '.repeat(padL)}${text}${' '.repeat(padR)}│`;
|
|
38
|
-
});
|
|
39
|
-
const result = [bt, pd, ...texts, pd, bb];
|
|
40
|
-
return result.join('\n');
|
|
41
|
-
};
|
|
42
|
-
exports.markuplint = `markup${cli_color_1.default.xterm(PRIMARY_COLOR)('lint')}`;
|
|
43
|
-
function write(message) {
|
|
44
|
-
process.stdout.write(message + '\n');
|
|
45
|
-
}
|
|
46
|
-
exports.write = write;
|
|
47
|
-
write.break = () => process.stdout.write('\n');
|
|
48
|
-
function error(message) {
|
|
49
|
-
process.stderr.write(message + '\n');
|
|
50
|
-
}
|
|
51
|
-
exports.error = error;
|
|
52
|
-
error.exit = () => process.exit(1);
|
|
53
|
-
const head = (method, noColor) => box([`${logo} ${exports.markuplint}`, cli_color_1.default.blackBright(`v${version}`), '', cli_color_1.default.bold(method)], {
|
|
54
|
-
center: true,
|
|
55
|
-
noColor,
|
|
56
|
-
});
|
|
57
|
-
exports.head = head;
|
|
58
|
-
function p(s, pad, start = false) {
|
|
59
|
-
const l = w(`${s}`.trim());
|
|
60
|
-
const d = pad - l;
|
|
61
|
-
const _ = ' '.repeat(d < 0 ? 0 : d);
|
|
62
|
-
return start ? `${_}${s}` : `${s}${_}`;
|
|
63
|
-
}
|
|
64
|
-
exports.p = p;
|
|
65
|
-
function w(s) {
|
|
66
|
-
return s.replace(/./g, _ => '0'.repeat(eaw.characterLength(_))).length;
|
|
67
|
-
}
|
|
68
|
-
exports.w = w;
|
|
69
|
-
function space(str) {
|
|
70
|
-
return str
|
|
71
|
-
.replace(/\s+/g, $0 => {
|
|
72
|
-
return cli_color_1.default.xterm(8)($0);
|
|
73
|
-
})
|
|
74
|
-
.replace(/ /g, $0 => '•')
|
|
75
|
-
.replace(/\t/g, $0 => '→ ');
|
|
76
|
-
}
|
|
77
|
-
exports.space = space;
|
|
78
|
-
function invisibleSpace(str) {
|
|
79
|
-
return str.replace(/\t/g, $0 => ' ').replace(/./g, $0 => ' ');
|
|
80
|
-
}
|
|
81
|
-
exports.invisibleSpace = invisibleSpace;
|
|
82
|
-
function messageToString(message, reason) {
|
|
83
|
-
if (!reason) {
|
|
84
|
-
return message;
|
|
85
|
-
}
|
|
86
|
-
return `${message} / ${reason}`;
|
|
87
|
-
}
|
|
88
|
-
exports.messageToString = messageToString;
|