markuplint 3.0.0-dev.24 → 3.0.0-dev.290
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 +10 -6
- 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 +3 -3
- package/lib/api/lint.js +5 -10
- package/lib/api/ml-engine.d.ts +15 -9
- package/lib/api/ml-engine.js +136 -102
- package/lib/api/types.d.ts +30 -34
- package/lib/api/types.js +1 -2
- package/lib/api/v1.d.ts +12 -12
- package/lib/api/v1.js +13 -24
- package/lib/cli/bootstrap.d.ts +15 -7
- package/lib/cli/bootstrap.js +19 -11
- package/lib/cli/command.d.ts +3 -3
- package/lib/cli/command.js +27 -26
- package/lib/cli/create-rule/index.js +56 -42
- package/lib/cli/index.js +27 -31
- package/lib/cli/init/create-config.d.ts +4 -0
- package/lib/cli/init/create-config.js +90 -0
- package/lib/cli/init/get-default-rules.d.ts +3 -0
- package/lib/cli/init/get-default-rules.js +52 -0
- package/lib/cli/init/index.js +43 -231
- package/lib/cli/init/install-module.d.ts +3 -1
- package/lib/cli/init/install-module.js +22 -17
- package/lib/cli/init/types.d.ts +8 -0
- package/lib/cli/init/types.js +1 -0
- package/lib/cli/output.d.ts +2 -2
- package/lib/cli/output.js +13 -15
- package/lib/cli/prompt.d.ts +9 -9
- package/lib/cli/prompt.js +15 -25
- package/lib/cli/search/index.d.ts +2 -2
- package/lib/cli/search/index.js +7 -10
- package/lib/debug.js +8 -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 +9 -15
- package/lib/index.d.ts +6 -5
- package/lib/index.js +6 -10
- package/lib/reporter/github-reporter.d.ts +2 -0
- package/lib/reporter/github-reporter.js +19 -0
- package/lib/reporter/index.d.ts +3 -2
- package/lib/reporter/index.js +3 -5
- package/lib/reporter/simple-reporter.d.ts +2 -2
- package/lib/reporter/simple-reporter.js +12 -17
- package/lib/reporter/standard-reporter.d.ts +2 -2
- package/lib/reporter/standard-reporter.js +18 -23
- package/lib/testing-tool/index.d.ts +10 -10
- package/lib/testing-tool/index.js +17 -25
- package/lib/types.d.ts +6 -7
- package/lib/types.js +1 -2
- package/lib/util.d.ts +0 -2
- package/lib/util.js +21 -37
- 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 +43 -31
- package/bin/markuplint +0 -3
- package/media/screenshot01.png +0 -0
- package/test/plugin001.js +0 -24
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/lib/api/v1.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Config, RuleConfigValue } from '@markuplint/ml-config';
|
|
1
|
+
import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
2
2
|
import type { MLRule } from '@markuplint/ml-core';
|
|
3
3
|
/**
|
|
4
4
|
* @deprecated
|
|
@@ -9,43 +9,43 @@ export declare function lint_v1(options: {
|
|
|
9
9
|
/**
|
|
10
10
|
* Glob pattern
|
|
11
11
|
*/
|
|
12
|
-
files?: string | string[];
|
|
12
|
+
readonly files?: string | readonly string[];
|
|
13
13
|
/**
|
|
14
14
|
* Target source code of evaluation
|
|
15
15
|
*/
|
|
16
|
-
sourceCodes?: string | string[];
|
|
16
|
+
readonly sourceCodes?: string | readonly string[];
|
|
17
17
|
/**
|
|
18
18
|
* File names when `sourceCodes`
|
|
19
19
|
*/
|
|
20
|
-
names?: string | string[];
|
|
20
|
+
readonly names?: string | readonly string[];
|
|
21
21
|
/**
|
|
22
22
|
* Workspace path when `sourceCodes`
|
|
23
23
|
*/
|
|
24
|
-
workspace?: string;
|
|
24
|
+
readonly workspace?: string;
|
|
25
25
|
/**
|
|
26
26
|
* Configure file or object
|
|
27
27
|
*/
|
|
28
|
-
config?: string | Config;
|
|
28
|
+
readonly config?: string | Config;
|
|
29
29
|
/**
|
|
30
30
|
* The config applied when not resolved from files or set it explicitly.
|
|
31
31
|
*/
|
|
32
|
-
defaultConfig?: Config;
|
|
32
|
+
readonly defaultConfig?: Config;
|
|
33
33
|
/**
|
|
34
34
|
* Rules (default: `@markuplint/rules`)
|
|
35
35
|
*/
|
|
36
|
-
rules?: MLRule<RuleConfigValue,
|
|
36
|
+
readonly rules?: readonly Readonly<MLRule<RuleConfigValue, PlainData>>[];
|
|
37
37
|
/**
|
|
38
38
|
* Auto resolve rules
|
|
39
39
|
*
|
|
40
40
|
* Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
|
|
41
41
|
*/
|
|
42
|
-
rulesAutoResolve?: boolean;
|
|
42
|
+
readonly rulesAutoResolve?: boolean;
|
|
43
43
|
/**
|
|
44
44
|
* Auto fix
|
|
45
45
|
*/
|
|
46
|
-
fix?: boolean;
|
|
46
|
+
readonly fix?: boolean;
|
|
47
47
|
/**
|
|
48
48
|
* Locale
|
|
49
49
|
*/
|
|
50
|
-
locale?: string;
|
|
51
|
-
}): Promise<import("
|
|
50
|
+
readonly locale?: string;
|
|
51
|
+
}): Promise<import("../types.js").MLResultInfo[]>;
|
package/lib/api/v1.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.lint_v1 = void 0;
|
|
4
|
-
const lint_1 = require("./lint");
|
|
1
|
+
import { toNoEmptyStringArrayFromStringOrArray } from '@markuplint/shared';
|
|
2
|
+
import { lint } from './lint.js';
|
|
5
3
|
/**
|
|
6
4
|
* @deprecated
|
|
7
5
|
* @param options
|
|
8
6
|
* @returns
|
|
9
7
|
*/
|
|
10
|
-
async function lint_v1(options) {
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const codes = options.sourceCodes
|
|
14
|
-
? Array.isArray(options.sourceCodes)
|
|
15
|
-
? options.sourceCodes
|
|
16
|
-
: [options.sourceCodes]
|
|
17
|
-
: [];
|
|
8
|
+
export async function lint_v1(options) {
|
|
9
|
+
const filePathList = toNoEmptyStringArrayFromStringOrArray(options.files);
|
|
10
|
+
const codes = toNoEmptyStringArrayFromStringOrArray(options.sourceCodes);
|
|
18
11
|
const files = [
|
|
19
12
|
...filePathList,
|
|
20
|
-
...codes.map((code, i) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
workspace: (_b = options.workspace) === null || _b === void 0 ? void 0 : _b[i],
|
|
26
|
-
});
|
|
27
|
-
}),
|
|
13
|
+
...codes.map((code, i) => ({
|
|
14
|
+
sourceCode: code,
|
|
15
|
+
name: Array.isArray(options.names) ? options.names?.[i] : options.names,
|
|
16
|
+
workspace: options.workspace?.[i],
|
|
17
|
+
})),
|
|
28
18
|
];
|
|
29
19
|
let config;
|
|
30
20
|
let configFile;
|
|
@@ -34,14 +24,13 @@ async function lint_v1(options) {
|
|
|
34
24
|
else if (options.config) {
|
|
35
25
|
config = options.config;
|
|
36
26
|
}
|
|
37
|
-
const result = await
|
|
27
|
+
const result = await lint(files, {
|
|
38
28
|
config,
|
|
39
29
|
configFile,
|
|
40
|
-
noSearchConfig:
|
|
30
|
+
noSearchConfig: filePathList.length === 0,
|
|
41
31
|
rules: options.rules,
|
|
42
|
-
autoLoad:
|
|
32
|
+
autoLoad: options.rulesAutoResolve ?? true,
|
|
43
33
|
locale: options.locale,
|
|
44
34
|
});
|
|
45
35
|
return result;
|
|
46
36
|
}
|
|
47
|
-
exports.lint_v1 = lint_v1;
|
package/lib/cli/bootstrap.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const help = "\nUsage\n\t$ markuplint <HTML file paths (glob format)>\n\t$ <stdout> | markuplint\n\nOptions\n\t--config, -c FILE_PATH A configuration file path.\n\t--fix, Fix HTML.\n\t--format, -f FORMAT Output format. Support \"JSON\", \"Simple\" and \"Standard\". Default: \"Standard\".\n\t--no-search-config No search a configure file automatically.\n\t--ignore-ext Evaluate files that are received even though the type of extension.\n\t--no-import-preset-rules No import preset rules.\n\t--locale Locale of the message of violation. Default is an OS setting.\n\t--no-color, Output no color.\n\t--problem-only, -p Output only problems, without passeds.\n\t--verbose Output with detailed information.\n\n\t--init Initialize settings interactively.\n\t--create-rule Add the scaffold of a custom rule.\n\t--search Search lines of codes that include the target element by selectors.\n\n\t--help, -h Show help.\n\t--version, -v Show version.\n\nExamples\n\t$ markuplint verifyee.html --config path/to/.markuplintrc\n\t$ cat verifyee.html | markuplint\n";
|
|
3
|
-
export declare const cli: meow.Result<{
|
|
1
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
export declare const help = "\nUsage\n\t$ markuplint <HTML file paths (glob format)>\n\t$ <stdout> | markuplint\n\nOptions\n\t--config, -c FILE_PATH A configuration file path.\n\t--fix, Fix HTML.\n\t--format, -f FORMAT Output format. Support \"JSON\", \"Simple\", \"GitHub\" and \"Standard\". Default: \"Standard\".\n\t--no-search-config No search a configure file automatically.\n\t--ignore-ext Evaluate files that are received even though the type of extension.\n\t--no-import-preset-rules No import preset rules.\n\t--locale Locale of the message of violation. Default is an OS setting.\n\t--no-color, Output no color.\n\t--problem-only, -p Output only problems, without passeds.\n\t--allow-warnings Return status code 0 even if there are warnings.\n\t--allow-empty-input Return status code 1 even if there are no input files.\n\t--verbose Output with detailed information.\n\n\t--init Initialize settings interactively.\n\t--create-rule Add the scaffold of a custom rule.\n\t--search Search lines of codes that include the target element by selectors.\n\n\t--help, -h Show help.\n\t--version, -v Show version.\n\nExamples\n\t$ markuplint verifyee.html --config path/to/.markuplintrc\n\t$ cat verifyee.html | markuplint\n";
|
|
3
|
+
export declare const cli: import("meow").Result<{
|
|
4
4
|
config: {
|
|
5
5
|
type: "string";
|
|
6
|
-
|
|
6
|
+
shortFlag: string;
|
|
7
7
|
};
|
|
8
8
|
fix: {
|
|
9
9
|
type: "boolean";
|
|
@@ -11,7 +11,7 @@ export declare const cli: meow.Result<{
|
|
|
11
11
|
};
|
|
12
12
|
format: {
|
|
13
13
|
type: "string";
|
|
14
|
-
|
|
14
|
+
shortFlag: string;
|
|
15
15
|
};
|
|
16
16
|
searchConfig: {
|
|
17
17
|
type: "boolean";
|
|
@@ -34,9 +34,17 @@ export declare const cli: meow.Result<{
|
|
|
34
34
|
};
|
|
35
35
|
problemOnly: {
|
|
36
36
|
type: "boolean";
|
|
37
|
-
|
|
37
|
+
shortFlag: string;
|
|
38
38
|
default: false;
|
|
39
39
|
};
|
|
40
|
+
allowWarnings: {
|
|
41
|
+
type: "boolean";
|
|
42
|
+
default: false;
|
|
43
|
+
};
|
|
44
|
+
allowEmptyInput: {
|
|
45
|
+
type: "boolean";
|
|
46
|
+
default: true;
|
|
47
|
+
};
|
|
40
48
|
verbose: {
|
|
41
49
|
type: "boolean";
|
|
42
50
|
default: false;
|
|
@@ -53,4 +61,4 @@ export declare const cli: meow.Result<{
|
|
|
53
61
|
type: "string";
|
|
54
62
|
};
|
|
55
63
|
}>;
|
|
56
|
-
export type CLIOptions = typeof cli.flags
|
|
64
|
+
export type CLIOptions = ReadonlyDeep<typeof cli.flags>;
|
package/lib/cli/bootstrap.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.cli = exports.help = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const meow_1 = tslib_1.__importDefault(require("meow"));
|
|
6
|
-
exports.help = `
|
|
1
|
+
import meow from 'meow';
|
|
2
|
+
export const help = `
|
|
7
3
|
Usage
|
|
8
4
|
$ markuplint <HTML file paths (glob format)>
|
|
9
5
|
$ <stdout> | markuplint
|
|
@@ -11,13 +7,15 @@ Usage
|
|
|
11
7
|
Options
|
|
12
8
|
--config, -c FILE_PATH A configuration file path.
|
|
13
9
|
--fix, Fix HTML.
|
|
14
|
-
--format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
|
|
10
|
+
--format, -f FORMAT Output format. Support "JSON", "Simple", "GitHub" and "Standard". Default: "Standard".
|
|
15
11
|
--no-search-config No search a configure file automatically.
|
|
16
12
|
--ignore-ext Evaluate files that are received even though the type of extension.
|
|
17
13
|
--no-import-preset-rules No import preset rules.
|
|
18
14
|
--locale Locale of the message of violation. Default is an OS setting.
|
|
19
15
|
--no-color, Output no color.
|
|
20
16
|
--problem-only, -p Output only problems, without passeds.
|
|
17
|
+
--allow-warnings Return status code 0 even if there are warnings.
|
|
18
|
+
--allow-empty-input Return status code 1 even if there are no input files.
|
|
21
19
|
--verbose Output with detailed information.
|
|
22
20
|
|
|
23
21
|
--init Initialize settings interactively.
|
|
@@ -31,11 +29,12 @@ Examples
|
|
|
31
29
|
$ markuplint verifyee.html --config path/to/.markuplintrc
|
|
32
30
|
$ cat verifyee.html | markuplint
|
|
33
31
|
`;
|
|
34
|
-
|
|
32
|
+
export const cli = meow(help, {
|
|
33
|
+
importMeta: import.meta,
|
|
35
34
|
flags: {
|
|
36
35
|
config: {
|
|
37
36
|
type: 'string',
|
|
38
|
-
|
|
37
|
+
shortFlag: 'c',
|
|
39
38
|
},
|
|
40
39
|
fix: {
|
|
41
40
|
type: 'boolean',
|
|
@@ -43,7 +42,7 @@ exports.cli = (0, meow_1.default)(exports.help, {
|
|
|
43
42
|
},
|
|
44
43
|
format: {
|
|
45
44
|
type: 'string',
|
|
46
|
-
|
|
45
|
+
shortFlag: 'f',
|
|
47
46
|
},
|
|
48
47
|
searchConfig: {
|
|
49
48
|
type: 'boolean',
|
|
@@ -66,9 +65,18 @@ exports.cli = (0, meow_1.default)(exports.help, {
|
|
|
66
65
|
},
|
|
67
66
|
problemOnly: {
|
|
68
67
|
type: 'boolean',
|
|
69
|
-
|
|
68
|
+
shortFlag: 'p',
|
|
70
69
|
default: false,
|
|
71
70
|
},
|
|
71
|
+
allowWarnings: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
// TODO: It will be changed to `true` in the next major version.
|
|
74
|
+
default: false,
|
|
75
|
+
},
|
|
76
|
+
allowEmptyInput: {
|
|
77
|
+
type: 'boolean',
|
|
78
|
+
default: true,
|
|
79
|
+
},
|
|
72
80
|
verbose: {
|
|
73
81
|
type: 'boolean',
|
|
74
82
|
default: false,
|
package/lib/cli/command.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { CLIOptions } from './bootstrap.js';
|
|
2
|
+
import type { APIOptions } from '../api/types.js';
|
|
3
3
|
import type { Target } from '@markuplint/file-resolver';
|
|
4
|
-
export declare function command(files: Target[], options: CLIOptions, apiOptions?: APIOptions): Promise<boolean>;
|
|
4
|
+
export declare function command(files: readonly Readonly<Target>[], options: CLIOptions, apiOptions?: APIOptions): Promise<boolean>;
|
package/lib/cli/command.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const api_1 = require("../api");
|
|
9
|
-
const debug_1 = require("../debug");
|
|
10
|
-
const output_1 = require("./output");
|
|
11
|
-
async function command(files, options, apiOptions) {
|
|
12
|
-
var _a;
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolveFiles } from '@markuplint/file-resolver';
|
|
4
|
+
import { MLEngine } from '../api/index.js';
|
|
5
|
+
import { log } from '../debug.js';
|
|
6
|
+
import { output } from './output.js';
|
|
7
|
+
export async function command(files, options, apiOptions) {
|
|
13
8
|
const fix = options.fix;
|
|
14
|
-
const configFile = options.config &&
|
|
9
|
+
const configFile = options.config && path.join(process.cwd(), options.config);
|
|
15
10
|
const locale = options.locale;
|
|
16
11
|
const searchConfig = options.searchConfig;
|
|
17
12
|
const ignoreExt = options.ignoreExt;
|
|
18
13
|
const importPresetRules = options.importPresetRules;
|
|
19
14
|
const verbose = options.verbose;
|
|
20
|
-
const fileList = await
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const fileList = await resolveFiles(files);
|
|
16
|
+
if (fileList.length === 0 && !options.allowEmptyInput) {
|
|
17
|
+
process.stderr.write('Markuplint: No target files.\n');
|
|
18
|
+
// Error
|
|
19
|
+
return true;
|
|
25
20
|
}
|
|
26
|
-
|
|
21
|
+
if (log.enabled) {
|
|
22
|
+
log('File list: %O', fileList.map(f => f.path));
|
|
23
|
+
log('Config: %s', configFile ?? 'N/A');
|
|
24
|
+
log('Fix option: %s', fix);
|
|
25
|
+
}
|
|
26
|
+
const format = options.format?.toLowerCase().trim();
|
|
27
27
|
let hasError = false;
|
|
28
28
|
const jsonOutput = [];
|
|
29
29
|
for (const file of fileList) {
|
|
30
|
-
const engine = new
|
|
30
|
+
const engine = new MLEngine(file, {
|
|
31
31
|
configFile,
|
|
32
32
|
fix,
|
|
33
33
|
locale,
|
|
@@ -41,12 +41,14 @@ async function command(files, options, apiOptions) {
|
|
|
41
41
|
if (!result) {
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
const errorCount = result.violations.filter(v => v.severity === 'error').length;
|
|
45
|
+
const warningCount = result.violations.filter(v => v.severity === 'warning').length;
|
|
46
|
+
if (!hasError && (errorCount > 0 || (warningCount > 0 && !options.allowWarnings))) {
|
|
45
47
|
hasError = true;
|
|
46
48
|
}
|
|
47
49
|
if (fix) {
|
|
48
|
-
|
|
49
|
-
await
|
|
50
|
+
log('Overwrite file: %s', result.filePath);
|
|
51
|
+
await fs.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
|
|
50
52
|
process.stdout.write(`markuplint: Fix "${result.filePath}"\n`);
|
|
51
53
|
}
|
|
52
54
|
else {
|
|
@@ -57,8 +59,8 @@ async function command(files, options, apiOptions) {
|
|
|
57
59
|
})));
|
|
58
60
|
continue;
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
log('Output reports');
|
|
63
|
+
output(result, options);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
if (format === 'json') {
|
|
@@ -67,4 +69,3 @@ async function command(files, options, apiOptions) {
|
|
|
67
69
|
}
|
|
68
70
|
return hasError;
|
|
69
71
|
}
|
|
70
|
-
exports.command = command;
|
|
@@ -1,65 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { isMarkuplintRepo, createRuleHelper } from '@markuplint/create-rule-helper';
|
|
3
|
+
import c from 'cli-color';
|
|
4
|
+
import { write, head } from '../../util.js';
|
|
5
|
+
import { installModule } from '../init/install-module.js';
|
|
6
|
+
import { input, select, confirm } from '../prompt.js';
|
|
7
|
+
const icons = {
|
|
8
|
+
README: '📝',
|
|
9
|
+
index: '📜',
|
|
10
|
+
schema: '⚙️ ',
|
|
11
|
+
package: '🎁',
|
|
12
|
+
tsconfig: '💎',
|
|
13
|
+
};
|
|
14
|
+
export async function createRule() {
|
|
15
|
+
write(head('Create a rule'));
|
|
16
|
+
write.break();
|
|
13
17
|
const firstChoices = [
|
|
14
18
|
{ name: 'Add the rule to this project', value: 'ADD_TO_PROJECT' },
|
|
15
19
|
{ name: 'Create the rule and publish it as a package', value: 'PUBLISH_AS_PACKAGE' },
|
|
16
20
|
];
|
|
17
|
-
if (await
|
|
21
|
+
if (await isMarkuplintRepo()) {
|
|
18
22
|
firstChoices.push({ name: 'Contribute the new rule to markuplint core rules', value: 'CONTRIBUTE_TO_CORE' });
|
|
19
23
|
}
|
|
20
|
-
const purpose = await
|
|
24
|
+
const purpose = await select({
|
|
21
25
|
message: 'What purpose do you create the rule for?',
|
|
22
26
|
choices: firstChoices,
|
|
23
27
|
});
|
|
24
|
-
const
|
|
28
|
+
const dirQuestion = purpose === 'ADD_TO_PROJECT' ? 'What is the directory name?' : 'What is the plugin name?';
|
|
29
|
+
const pluginName = purpose === 'CONTRIBUTE_TO_CORE' ? '' : await input(dirQuestion, /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
|
|
30
|
+
const ruleName = await input('What is the rule name?', /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
|
|
31
|
+
const core = purpose === 'CONTRIBUTE_TO_CORE'
|
|
32
|
+
? {
|
|
33
|
+
description: await input('Description:'),
|
|
34
|
+
category: await select({
|
|
35
|
+
message: 'Category:',
|
|
36
|
+
choices: [
|
|
37
|
+
{ name: 'Conformance checking', value: 'validation' },
|
|
38
|
+
{ name: 'Accessibility', value: 'a11y' },
|
|
39
|
+
{ name: 'Naming Convention', value: 'naming-convention' },
|
|
40
|
+
{ name: 'Maintainability', value: 'maintainability' },
|
|
41
|
+
{ name: 'Style', value: 'style' },
|
|
42
|
+
],
|
|
43
|
+
}),
|
|
44
|
+
severity: await select({
|
|
45
|
+
message: 'Severity:',
|
|
46
|
+
choices: [
|
|
47
|
+
{ name: 'error', value: 'error' },
|
|
48
|
+
{ name: 'warning', value: 'warning' },
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
51
|
+
}
|
|
52
|
+
: undefined;
|
|
25
53
|
const lang = purpose === 'CONTRIBUTE_TO_CORE'
|
|
26
54
|
? 'TYPESCRIPT'
|
|
27
|
-
: await
|
|
55
|
+
: await select({
|
|
28
56
|
message: 'Which language will you implement?',
|
|
29
57
|
choices: [
|
|
30
58
|
{ name: 'TypeScript', value: 'TYPESCRIPT' },
|
|
31
59
|
{ name: 'JavaScript', value: 'JAVASCRIPT' },
|
|
32
60
|
],
|
|
33
61
|
});
|
|
34
|
-
const needTest = purpose === 'CONTRIBUTE_TO_CORE' ? true : await
|
|
35
|
-
const result = await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (result.test) {
|
|
39
|
-
output(name, '🖍 ', 'index.spec', result.test);
|
|
40
|
-
}
|
|
41
|
-
if (result.rules) {
|
|
42
|
-
output(name, '🛡 ', 'rules', result.rules);
|
|
62
|
+
const needTest = purpose === 'CONTRIBUTE_TO_CORE' ? true : await confirm('Do you need the test?', { initial: true });
|
|
63
|
+
const result = await createRuleHelper({ purpose, pluginName, ruleName, lang, needTest, core });
|
|
64
|
+
for (const file of result.files) {
|
|
65
|
+
output(pluginName || 'core', file.test ? '🖍 ' : icons[file.name] ?? '🛡 ', file.fileName, resolve(file.destDir, file.fileName + file.ext));
|
|
43
66
|
}
|
|
44
|
-
if (result.
|
|
45
|
-
|
|
67
|
+
if (result.dependencies.length > 0) {
|
|
68
|
+
await installModule(result.dependencies);
|
|
46
69
|
}
|
|
47
|
-
if (result.
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (result.packageJson) {
|
|
51
|
-
output(name, '🎁', 'package.json', result.packageJson);
|
|
52
|
-
if (result.tsConfig) {
|
|
53
|
-
output(name, '💎', 'tsconfig.json', result.tsConfig);
|
|
54
|
-
}
|
|
55
|
-
await (0, install_module_1.installModule)(result.dependencies);
|
|
56
|
-
await (0, install_module_1.installModule)(result.devDependencies, true);
|
|
70
|
+
if (result.devDependencies.length > 0) {
|
|
71
|
+
await installModule(result.devDependencies, true);
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
|
-
exports.createRule = createRule;
|
|
60
74
|
function output(name, icon, title, path) {
|
|
61
|
-
const _marker =
|
|
62
|
-
const _title = (icon, title) => `${icon} ` +
|
|
63
|
-
const _file = (path) => ' ' +
|
|
64
|
-
|
|
75
|
+
const _marker = c.xterm(39)('✔') + ' ';
|
|
76
|
+
const _title = (icon, title) => `${icon} ` + c.bold(`${name}/${title}`);
|
|
77
|
+
const _file = (path) => ' ' + c.cyanBright(path);
|
|
78
|
+
write(_marker + _title(icon, title) + _file(path));
|
|
65
79
|
}
|
package/lib/cli/index.js
CHANGED
|
@@ -1,59 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const create_rule_1 = require("./create-rule");
|
|
9
|
-
const init_1 = require("./init");
|
|
10
|
-
const search_1 = tslib_1.__importDefault(require("./search"));
|
|
1
|
+
import getStdin from 'get-stdin';
|
|
2
|
+
import { verbosely } from '../debug.js';
|
|
3
|
+
import { cli } from './bootstrap.js';
|
|
4
|
+
import { command } from './command.js';
|
|
5
|
+
import { createRule } from './create-rule/index.js';
|
|
6
|
+
import { initialize } from './init/index.js';
|
|
7
|
+
import search from './search/index.js';
|
|
11
8
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
12
9
|
(async () => {
|
|
13
|
-
if (
|
|
14
|
-
|
|
10
|
+
if (cli.flags.v) {
|
|
11
|
+
cli.showVersion(); // And exit successfully.
|
|
15
12
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
13
|
+
if (cli.flags.h) {
|
|
14
|
+
cli.showHelp(0); // And exit successfully.
|
|
18
15
|
}
|
|
19
|
-
if (
|
|
20
|
-
|
|
16
|
+
if (cli.flags.verbose) {
|
|
17
|
+
verbosely();
|
|
21
18
|
}
|
|
22
|
-
if (
|
|
23
|
-
await
|
|
19
|
+
if (cli.flags.init) {
|
|
20
|
+
await initialize().catch(err => {
|
|
24
21
|
process.stderr.write(err + '\n');
|
|
25
22
|
process.exit(1);
|
|
26
23
|
});
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
|
-
if (
|
|
30
|
-
await
|
|
26
|
+
if (cli.flags.createRule) {
|
|
27
|
+
await createRule().catch(err => {
|
|
31
28
|
process.stderr.write(err + '\n');
|
|
32
29
|
process.exit(1);
|
|
33
30
|
});
|
|
34
31
|
return;
|
|
35
32
|
}
|
|
36
|
-
const files =
|
|
37
|
-
if (files.length) {
|
|
38
|
-
if (
|
|
39
|
-
await (
|
|
33
|
+
const files = cli.input;
|
|
34
|
+
if (files.length > 0) {
|
|
35
|
+
if (cli.flags.search) {
|
|
36
|
+
await search(files, cli.flags, cli.flags.search).catch(err => {
|
|
40
37
|
process.stderr.write(err + '\n');
|
|
41
38
|
process.exit(1);
|
|
42
39
|
});
|
|
43
40
|
return;
|
|
44
41
|
}
|
|
45
|
-
const hasError = await
|
|
42
|
+
const hasError = await command(files, cli.flags).catch(err => {
|
|
46
43
|
throw err;
|
|
47
|
-
// process.exit(1);
|
|
48
44
|
});
|
|
49
45
|
process.exit(hasError ? 1 : 0);
|
|
50
46
|
}
|
|
51
47
|
if (usePipe()) {
|
|
52
|
-
(
|
|
48
|
+
getStdin()
|
|
53
49
|
.then(async (stdin) => {
|
|
54
50
|
if (stdin) {
|
|
55
|
-
const hasError = await
|
|
56
|
-
...
|
|
51
|
+
const hasError = await command([{ sourceCode: stdin }], {
|
|
52
|
+
...cli.flags,
|
|
57
53
|
ignoreExt: true,
|
|
58
54
|
}).catch(err => {
|
|
59
55
|
process.stderr.write(err + '\n');
|
|
@@ -62,7 +58,7 @@ const search_1 = tslib_1.__importDefault(require("./search"));
|
|
|
62
58
|
process.exit(hasError ? 1 : 0);
|
|
63
59
|
}
|
|
64
60
|
// result is empty
|
|
65
|
-
|
|
61
|
+
cli.showHelp(1);
|
|
66
62
|
})
|
|
67
63
|
.catch(reason => {
|
|
68
64
|
// eslint-disable-next-line no-console
|
|
@@ -71,7 +67,7 @@ const search_1 = tslib_1.__importDefault(require("./search"));
|
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
69
|
else {
|
|
74
|
-
|
|
70
|
+
cli.showHelp(1);
|
|
75
71
|
}
|
|
76
72
|
})();
|
|
77
73
|
function usePipe() {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DefaultRules, Langs, RuleSettingMode } from './types.js';
|
|
2
|
+
import type { Config } from '@markuplint/ml-config';
|
|
3
|
+
export declare const langs: Record<Langs, string>;
|
|
4
|
+
export declare function createConfig(langs: readonly Langs[], mode: RuleSettingMode, defaultRules: DefaultRules): Config;
|