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,10 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConfig = exports.langs = void 0;
|
|
4
1
|
const extRExp = {
|
|
5
2
|
jsx: '\\.[jt]sx?$',
|
|
6
3
|
vue: '\\.vue$',
|
|
7
4
|
svelte: '\\.svelte$',
|
|
5
|
+
sveltekit: '\\.html$',
|
|
8
6
|
astro: '\\.astro$',
|
|
9
7
|
pug: '\\.pug$',
|
|
10
8
|
php: '\\.php$',
|
|
@@ -15,10 +13,11 @@ const extRExp = {
|
|
|
15
13
|
nunjucks: '\\.nunjucks$',
|
|
16
14
|
liquid: '\\.liquid$',
|
|
17
15
|
};
|
|
18
|
-
|
|
16
|
+
export const langs = {
|
|
19
17
|
jsx: 'React (JSX)',
|
|
20
18
|
vue: 'Vue',
|
|
21
19
|
svelte: 'Svelte',
|
|
20
|
+
sveltekit: 'SvelteKit',
|
|
22
21
|
astro: 'Astro',
|
|
23
22
|
pug: 'Pug',
|
|
24
23
|
php: 'PHP',
|
|
@@ -29,8 +28,7 @@ exports.langs = {
|
|
|
29
28
|
nunjucks: 'Nunjucks',
|
|
30
29
|
liquid: 'liquid (Shopify)',
|
|
31
30
|
};
|
|
32
|
-
function createConfig(langs, mode, defaultRules) {
|
|
33
|
-
var _a;
|
|
31
|
+
export function createConfig(langs, mode, defaultRules) {
|
|
34
32
|
let config = {};
|
|
35
33
|
const parser = { ...config.parser };
|
|
36
34
|
for (const lang of langs) {
|
|
@@ -38,8 +36,15 @@ function createConfig(langs, mode, defaultRules) {
|
|
|
38
36
|
if (!ext) {
|
|
39
37
|
continue;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
switch (lang) {
|
|
40
|
+
case 'sveltekit': {
|
|
41
|
+
parser[ext] = '@markuplint/svelte-parser/kit';
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
parser[ext] = `@markuplint/${lang}-parser`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
if (lang === 'vue') {
|
|
44
49
|
config = {
|
|
45
50
|
...config,
|
|
@@ -71,13 +76,12 @@ function createConfig(langs, mode, defaultRules) {
|
|
|
71
76
|
continue;
|
|
72
77
|
}
|
|
73
78
|
if (mode.includes(rule.category)) {
|
|
74
|
-
// @ts-ignore
|
|
75
79
|
rules[ruleName] = rule.defaultValue;
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
else if (mode === 'recommended') {
|
|
80
|
-
config.extends = [...(
|
|
84
|
+
config.extends = [...(config.extends ?? []), 'markuplint:recommended'];
|
|
81
85
|
}
|
|
82
86
|
else {
|
|
83
87
|
const ruleNames = Object.keys(defaultRules);
|
|
@@ -86,7 +90,6 @@ function createConfig(langs, mode, defaultRules) {
|
|
|
86
90
|
if (!rule) {
|
|
87
91
|
continue;
|
|
88
92
|
}
|
|
89
|
-
// @ts-ignore
|
|
90
93
|
rules[ruleName] = rule.defaultValue;
|
|
91
94
|
}
|
|
92
95
|
}
|
|
@@ -95,4 +98,3 @@ function createConfig(langs, mode, defaultRules) {
|
|
|
95
98
|
}
|
|
96
99
|
return config;
|
|
97
100
|
}
|
|
98
|
-
exports.createConfig = createConfig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function getDefaultRules(
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export declare function getDefaultRules(): {
|
|
2
|
+
[x: string]: import("./types.js").Rule;
|
|
3
|
+
};
|
|
@@ -1,57 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getDefaultRules = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
|
|
6
|
-
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
7
|
-
const RULES_SCHEMA_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/schema.json';
|
|
8
|
-
const RULES_README_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/src/[NAME]/README.md';
|
|
9
|
-
async function getDefaultRules(version) {
|
|
10
|
-
const json = await safeFetch(RULES_SCHEMA_URL, version);
|
|
1
|
+
import builtinRules from '@markuplint/rules';
|
|
2
|
+
export function getDefaultRules() {
|
|
11
3
|
const rules = {};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
for (const [ruleName, rule] of Object.entries(builtinRules)) {
|
|
5
|
+
const defaultSeverity = rule.defaultSeverity;
|
|
6
|
+
const defaultValue = defaultSeverity === 'warning' ? false : rule.defaultValue ?? true;
|
|
7
|
+
const category = rule.meta?.category;
|
|
8
|
+
if (category) {
|
|
9
|
+
rules[ruleName] = {
|
|
10
|
+
defaultValue,
|
|
11
|
+
category,
|
|
12
|
+
};
|
|
21
13
|
}
|
|
22
|
-
const defaultValue = severity === 'warning' ? false : (_d = json.definitions.value.default) !== null && _d !== void 0 ? _d : true;
|
|
23
|
-
rules[name] = {
|
|
24
|
-
defaultValue,
|
|
25
|
-
category,
|
|
26
|
-
};
|
|
27
|
-
}));
|
|
28
|
-
return rules;
|
|
29
|
-
}
|
|
30
|
-
exports.getDefaultRules = getDefaultRules;
|
|
31
|
-
async function safeFetch(baseUrl, version, type = 'json') {
|
|
32
|
-
const url = baseUrl.replace('[VERSION]', `v${version}`);
|
|
33
|
-
const res = await (0, node_fetch_1.default)(url);
|
|
34
|
-
if (!res.ok) {
|
|
35
|
-
return safeFetch(baseUrl, '3.0.0', type);
|
|
36
|
-
}
|
|
37
|
-
if (type === 'json') {
|
|
38
|
-
return (await res.json());
|
|
39
14
|
}
|
|
40
|
-
|
|
41
|
-
const { data } = (0, gray_matter_1.default)(md);
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Fallback fetching until 3.0.x
|
|
46
|
-
*
|
|
47
|
-
* @param version
|
|
48
|
-
* @param name
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
async function getCatAndSeverityFromLegacy(version, name) {
|
|
52
|
-
const data = await safeFetch(RULES_README_URL.replace('[NAME]', name), version, 'md');
|
|
53
|
-
return {
|
|
54
|
-
category: data.category,
|
|
55
|
-
severity: data.severity,
|
|
56
|
-
};
|
|
15
|
+
return rules;
|
|
57
16
|
}
|
package/lib/cli/init/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const util_1 = tslib_1.__importDefault(require("util"));
|
|
8
|
-
const util_2 = require("../../util");
|
|
9
|
-
const prompt_1 = require("../prompt");
|
|
10
|
-
const create_config_1 = require("./create-config");
|
|
11
|
-
const get_default_rules_1 = require("./get-default-rules");
|
|
12
|
-
const install_module_1 = require("./install-module");
|
|
13
|
-
const writeFile = util_1.default.promisify(fs_1.default.writeFile);
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { installModule, multiSelect, confirm, confirmSequence, header } from '@markuplint/cli-utils';
|
|
4
|
+
import { createConfig, langs } from './create-config.js';
|
|
5
|
+
import { getDefaultRules } from './get-default-rules.js';
|
|
6
|
+
import { selectModules } from './select-modules.js';
|
|
14
7
|
const ruleCategories = {
|
|
15
8
|
validation: {
|
|
16
9
|
message: 'Are you going to conformance check according to HTML standard?',
|
|
@@ -28,19 +21,20 @@ const ruleCategories = {
|
|
|
28
21
|
message: 'Are you going to check for the code styles?',
|
|
29
22
|
},
|
|
30
23
|
};
|
|
31
|
-
async function initialize() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
export async function initialize() {
|
|
25
|
+
process.stdout.write(header('Initialization'));
|
|
26
|
+
process.stdout.write('\n');
|
|
27
|
+
process.stdout.write('\n');
|
|
28
|
+
const selectedLangs = await multiSelect({
|
|
35
29
|
message: 'Which do you use template engines?',
|
|
36
|
-
choices: Object.entries(
|
|
30
|
+
choices: Object.entries(langs).map(([key, name]) => ({ name, value: key })),
|
|
37
31
|
});
|
|
38
|
-
const autoInstall = await
|
|
39
|
-
const customize = await
|
|
32
|
+
const autoInstall = await confirm('May I install them automatically?');
|
|
33
|
+
const customize = await confirm('Do you customize rules?');
|
|
40
34
|
let ruleSettingMode = 'none';
|
|
41
35
|
if (customize) {
|
|
42
36
|
const categories = Object.keys(ruleCategories);
|
|
43
|
-
const selectedCategories = await
|
|
37
|
+
const selectedCategories = await confirmSequence(categories.map(catName => {
|
|
44
38
|
const cat = ruleCategories[catName];
|
|
45
39
|
return {
|
|
46
40
|
message: cat.message,
|
|
@@ -51,33 +45,30 @@ async function initialize() {
|
|
|
51
45
|
.map(([name, enabled]) => (enabled ? name : ''))
|
|
52
46
|
.filter((name) => !!name);
|
|
53
47
|
}
|
|
54
|
-
else if (await
|
|
48
|
+
else if (await confirm('Does it import the recommended config?')) {
|
|
55
49
|
ruleSettingMode = 'recommended';
|
|
56
50
|
}
|
|
57
51
|
let defaultRules = {};
|
|
58
52
|
if (ruleSettingMode !== 'recommended') {
|
|
59
|
-
|
|
60
|
-
const rulesVersion = require('../../../package.json').version;
|
|
61
|
-
defaultRules = await (0, get_default_rules_1.getDefaultRules)(rulesVersion);
|
|
53
|
+
defaultRules = getDefaultRules();
|
|
62
54
|
}
|
|
63
|
-
const config =
|
|
64
|
-
const filePath =
|
|
65
|
-
await writeFile(filePath, JSON.stringify(config, null, 2), { encoding: '
|
|
66
|
-
|
|
55
|
+
const config = createConfig(selectedLangs, ruleSettingMode, defaultRules);
|
|
56
|
+
const filePath = path.resolve(process.cwd(), '.markuplintrc');
|
|
57
|
+
await fs.writeFile(filePath, JSON.stringify(config, null, 2), { encoding: 'utf8' });
|
|
58
|
+
process.stdout.write(`✨Created: ${filePath}\n`);
|
|
67
59
|
if (autoInstall) {
|
|
68
|
-
|
|
69
|
-
const modules =
|
|
70
|
-
const result = await
|
|
60
|
+
process.stdout.write('Install automatically\n');
|
|
61
|
+
const modules = selectModules(selectedLangs);
|
|
62
|
+
const result = await installModule(modules, true).catch(error_ => new Error(error_));
|
|
71
63
|
if (result instanceof Error) {
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
65
|
+
process.exit(1);
|
|
74
66
|
}
|
|
75
67
|
if (result.alreadyExists) {
|
|
76
|
-
|
|
68
|
+
process.stdout.write('Modules are installed already.\n');
|
|
77
69
|
}
|
|
78
70
|
else {
|
|
79
|
-
|
|
71
|
+
process.stdout.write('✨ Success\n');
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
|
-
exports.initialize = initialize;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function selectModules(selectedLangs) {
|
|
2
|
+
const modules = ['markuplint', ...selectedLangs.map(lang => `@markuplint/${lang}-parser`)];
|
|
3
|
+
if (selectedLangs.includes('vue')) {
|
|
4
|
+
modules.push('@markuplint/vue-spec');
|
|
5
|
+
}
|
|
6
|
+
if (selectedLangs.includes('jsx')) {
|
|
7
|
+
modules.push('@markuplint/react-spec');
|
|
8
|
+
}
|
|
9
|
+
return modules;
|
|
10
|
+
}
|
package/lib/cli/init/types.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
| 'vue'
|
|
4
|
-
| 'svelte'
|
|
5
|
-
| 'astro'
|
|
6
|
-
| 'pug'
|
|
7
|
-
| 'php'
|
|
8
|
-
| 'smarty'
|
|
9
|
-
| 'erb'
|
|
10
|
-
| 'ejs'
|
|
11
|
-
| 'mustache'
|
|
12
|
-
| 'nunjucks'
|
|
13
|
-
| 'liquid';
|
|
1
|
+
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
2
|
+
export type Langs = 'jsx' | 'vue' | 'svelte' | 'sveltekit' | 'astro' | 'pug' | 'php' | 'smarty' | 'erb' | 'ejs' | 'mustache' | 'nunjucks' | 'liquid';
|
|
14
3
|
export type Category = 'validation' | 'a11y' | 'naming-convention' | 'style' | 'maintainability';
|
|
15
4
|
export type RuleSettingMode = readonly Category[] | 'recommended' | 'none';
|
|
16
5
|
export type DefaultRules = Readonly<Record<string, Rule>>;
|
|
17
6
|
export type Rule = {
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
readonly category: Category;
|
|
8
|
+
readonly defaultValue: RuleConfigValue;
|
|
20
9
|
};
|
package/lib/cli/init/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/cli/output.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CLIOptions } from './bootstrap';
|
|
2
|
-
import type { MLResultInfo } from '../types';
|
|
1
|
+
import type { CLIOptions } from './bootstrap.js';
|
|
2
|
+
import type { MLResultInfo } from '../types.js';
|
|
3
3
|
export declare function output(results: MLResultInfo, options: CLIOptions): void;
|
package/lib/cli/output.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
6
|
-
const reporter_1 = require("../reporter");
|
|
7
|
-
function output(results, options) {
|
|
8
|
-
var _a;
|
|
9
|
-
const format = (_a = options.format) !== null && _a !== void 0 ? _a : 'Standard';
|
|
1
|
+
import stripAnsi from 'strip-ansi';
|
|
2
|
+
import { simpleReporter, standardReporter, githubReporter } from '../reporter/index.js';
|
|
3
|
+
export function output(results, options) {
|
|
4
|
+
const format = options.format ?? 'Standard';
|
|
10
5
|
let out;
|
|
11
6
|
switch (format.toLowerCase()) {
|
|
12
7
|
case 'json': {
|
|
13
8
|
return;
|
|
14
9
|
}
|
|
15
10
|
case 'simple': {
|
|
16
|
-
out =
|
|
11
|
+
out = simpleReporter(results, options);
|
|
17
12
|
break;
|
|
18
13
|
}
|
|
19
14
|
case 'github': {
|
|
20
|
-
out =
|
|
15
|
+
out = githubReporter(results);
|
|
21
16
|
break;
|
|
22
17
|
}
|
|
23
18
|
default: {
|
|
24
|
-
out =
|
|
19
|
+
out = standardReporter(results, options);
|
|
25
20
|
}
|
|
26
21
|
}
|
|
27
22
|
if (out.length === 0) {
|
|
28
23
|
return;
|
|
29
24
|
}
|
|
30
25
|
let msg = `${out.join('\n')}\n`;
|
|
31
|
-
msg = options.color ? msg : (
|
|
26
|
+
msg = options.color ? msg : stripAnsi(msg);
|
|
32
27
|
// If it has errors, Write to `stderr` and failure and exit.
|
|
33
28
|
if (results.violations.length > 0) {
|
|
34
29
|
process.stderr.write(msg);
|
|
@@ -37,4 +32,3 @@ function output(results, options) {
|
|
|
37
32
|
}
|
|
38
33
|
process.stdout.write(msg);
|
|
39
34
|
}
|
|
40
|
-
exports.output = output;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CLIOptions } from '../bootstrap';
|
|
2
|
-
export
|
|
1
|
+
import type { CLIOptions } from '../bootstrap.js';
|
|
2
|
+
export declare function search(files: readonly string[], options: CLIOptions, selectors: string): Promise<void>;
|
package/lib/cli/search/index.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const command_1 = require("../command");
|
|
5
|
-
async function default_1(files, options, selectors) {
|
|
1
|
+
import { createRule, MLRule } from '@markuplint/ml-core';
|
|
2
|
+
import { command } from '../command.js';
|
|
3
|
+
export async function search(files, options, selectors) {
|
|
6
4
|
const name = '__CLI_SEARCH__';
|
|
7
5
|
const locations = [];
|
|
8
|
-
await
|
|
6
|
+
await command(files, {
|
|
9
7
|
...options,
|
|
10
8
|
problemOnly: true,
|
|
11
9
|
importPresetRules: false,
|
|
12
10
|
}, {
|
|
13
11
|
rules: [
|
|
14
|
-
new
|
|
12
|
+
new MLRule({
|
|
15
13
|
name,
|
|
16
|
-
...
|
|
14
|
+
...createRule({
|
|
17
15
|
verify({ document }) {
|
|
18
16
|
const nodes = document.querySelectorAll(selectors);
|
|
19
|
-
locations.push(...
|
|
20
|
-
var _a;
|
|
17
|
+
locations.push(...[...nodes].map(node => {
|
|
21
18
|
return {
|
|
22
|
-
file:
|
|
19
|
+
file: document.filename ?? '_NO_FILE_',
|
|
23
20
|
line: node.startLine,
|
|
24
21
|
col: node.startCol,
|
|
25
22
|
};
|
|
@@ -34,8 +31,7 @@ async function default_1(files, options, selectors) {
|
|
|
34
31
|
},
|
|
35
32
|
},
|
|
36
33
|
});
|
|
37
|
-
|
|
34
|
+
for (const loc of locations) {
|
|
38
35
|
process.stdout.write(`${loc.file}:${loc.line}:${loc.col}\n`);
|
|
39
|
-
}
|
|
36
|
+
}
|
|
40
37
|
}
|
|
41
|
-
exports.default = default_1;
|
package/lib/debug.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!exports.log.enabled) {
|
|
10
|
-
debug_1.default.enable(`${exports.log.namespace}*`);
|
|
11
|
-
(0, exports.log)(`Debug enable: ${exports.log.namespace}`);
|
|
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
|
+
const namespace = `${log.namespace}*,ml-*`;
|
|
7
|
+
debug.enable(namespace);
|
|
8
|
+
log(`[Debug] Enable: "${namespace}"`);
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
enableDebug();
|
|
14
11
|
}
|
|
15
|
-
exports.verbosely = verbosely;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getJsonModule<T extends {}>(modulePath: string): T | null;
|
package/lib/global-settings.d.ts
CHANGED
package/lib/global-settings.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGlobal = exports.setGlobal = void 0;
|
|
4
1
|
let globalSettings = {};
|
|
5
|
-
function setGlobal(settings) {
|
|
2
|
+
export function setGlobal(settings) {
|
|
6
3
|
globalSettings = {
|
|
7
4
|
...globalSettings,
|
|
8
5
|
...settings,
|
|
9
6
|
};
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
function getGlobal() {
|
|
8
|
+
export function getGlobal() {
|
|
13
9
|
return globalSettings;
|
|
14
10
|
}
|
|
15
|
-
exports.getGlobal = getGlobal;
|
package/lib/i18n.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.i18n = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const os_locale_1 = tslib_1.__importDefault(require("os-locale"));
|
|
1
|
+
import { osLocale } from 'os-locale';
|
|
2
|
+
import { getJsonModule } from './get-json-module.js';
|
|
6
3
|
let cachedLocale = null;
|
|
7
4
|
async function getLocale() {
|
|
8
5
|
if (!cachedLocale) {
|
|
9
|
-
cachedLocale = await (
|
|
6
|
+
cachedLocale = await osLocale({ spawn: true });
|
|
10
7
|
}
|
|
11
8
|
return cachedLocale;
|
|
12
9
|
}
|
|
13
|
-
async function i18n(locale) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const localeSet = loadLocaleSet !== null && loadLocaleSet !== void 0 ? loadLocaleSet :
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
(await Promise.resolve().then(() => tslib_1.__importStar(require('@markuplint/i18n/locales/en'))));
|
|
10
|
+
export async function i18n(locale) {
|
|
11
|
+
locale = locale ?? (await getLocale()) ?? 'en';
|
|
12
|
+
const langCode = locale.split('-')[0] ?? locale;
|
|
13
|
+
const loadLocaleSet = getJsonModule(`@markuplint/i18n/locales/${langCode}.json`);
|
|
14
|
+
const localeSet = loadLocaleSet ?? getJsonModule('@markuplint/i18n/locales/en.json');
|
|
21
15
|
return {
|
|
22
16
|
...localeSet,
|
|
23
17
|
locale: loadLocaleSet ? langCode : 'en',
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
|
-
exports.i18n = i18n;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export { MLEngine } from './api';
|
|
2
|
-
export
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
1
|
+
export { MLEngine, FromCodeOptions } from './api/index.js';
|
|
2
|
+
export { MLEngineEventMap } from './api/types.js';
|
|
3
|
+
export * from './i18n.js';
|
|
4
|
+
export * from './testing-tool/index.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { version } from './version.js';
|
|
5
7
|
/**
|
|
6
8
|
* @deprecated
|
|
7
9
|
*/
|
|
8
|
-
export * from './v1';
|
|
10
|
+
export * from './v1.js';
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "MLEngine", { enumerable: true, get: function () { return api_1.MLEngine; } });
|
|
7
|
-
tslib_1.__exportStar(require("./i18n"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./testing-tool"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export { MLEngine } from './api/index.js';
|
|
2
|
+
export * from './i18n.js';
|
|
3
|
+
export * from './testing-tool/index.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export { version } from './version.js';
|
|
10
6
|
/**
|
|
11
7
|
* @deprecated
|
|
12
8
|
*/
|
|
13
|
-
|
|
9
|
+
export * from './v1.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MLResultInfo } from '../types';
|
|
1
|
+
import type { MLResultInfo } from '../types.js';
|
|
2
2
|
export declare function githubReporter(results: MLResultInfo): string[];
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.githubReporter = void 0;
|
|
4
|
-
const util_1 = require("../util");
|
|
5
|
-
function githubReporter(results) {
|
|
1
|
+
import { messageToString } from '@markuplint/cli-utils';
|
|
2
|
+
export function githubReporter(results) {
|
|
6
3
|
const out = [];
|
|
7
4
|
for (const violation of results.violations) {
|
|
8
5
|
const command = severityToCommand(violation.severity);
|
|
9
|
-
const meg =
|
|
6
|
+
const meg = messageToString(violation.message, violation.reason);
|
|
10
7
|
out.push(`::${command} file=${results.filePath},line=${violation.line},col=${violation.col}::${meg} (${violation.ruleId})`);
|
|
11
8
|
}
|
|
12
9
|
return out;
|
|
13
10
|
}
|
|
14
|
-
exports.githubReporter = githubReporter;
|
|
15
11
|
function severityToCommand(severity) {
|
|
16
12
|
switch (severity) {
|
|
17
|
-
case 'info':
|
|
13
|
+
case 'info': {
|
|
18
14
|
return 'notice';
|
|
15
|
+
}
|
|
19
16
|
case 'error':
|
|
20
|
-
case 'warning':
|
|
17
|
+
case 'warning': {
|
|
21
18
|
return severity;
|
|
19
|
+
}
|
|
22
20
|
}
|
|
23
21
|
}
|
package/lib/reporter/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './standard-reporter';
|
|
2
|
-
export * from './simple-reporter';
|
|
3
|
-
export * from './github-reporter';
|
|
1
|
+
export * from './standard-reporter.js';
|
|
2
|
+
export * from './simple-reporter.js';
|
|
3
|
+
export * from './github-reporter.js';
|
package/lib/reporter/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./standard-reporter"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./simple-reporter"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./github-reporter"), exports);
|
|
1
|
+
export * from './standard-reporter.js';
|
|
2
|
+
export * from './simple-reporter.js';
|
|
3
|
+
export * from './github-reporter.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CLIOptions } from '../cli/bootstrap';
|
|
2
|
-
import type { MLResultInfo } from '../types';
|
|
1
|
+
import type { CLIOptions } from '../cli/bootstrap.js';
|
|
2
|
+
import type { MLResultInfo } from '../types.js';
|
|
3
3
|
export declare function simpleReporter(results: MLResultInfo, options: CLIOptions): string[];
|