markuplint 3.0.0-alpha.66 → 3.0.0-dev.176
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 +29 -24
- package/lib/api/lint.d.ts +2 -2
- package/lib/api/ml-engine.d.ts +26 -23
- package/lib/api/ml-engine.js +114 -83
- package/lib/api/types.d.ts +35 -38
- package/lib/api/v1.d.ts +44 -44
- package/lib/api/v1.js +4 -7
- package/lib/cli/bootstrap.d.ts +3 -2
- package/lib/cli/bootstrap.js +2 -2
- package/lib/cli/command.d.ts +6 -2
- package/lib/cli/command.js +17 -3
- package/lib/cli/create-rule/index.js +48 -19
- package/lib/cli/index.js +5 -2
- package/lib/cli/init/create-config.d.ts +8 -0
- package/lib/cli/init/create-config.js +95 -0
- package/lib/cli/init/get-default-rules.d.ts +3 -0
- package/lib/cli/init/get-default-rules.js +57 -0
- package/lib/cli/init/index.js +23 -199
- package/lib/cli/init/install-module.d.ts +6 -4
- package/lib/cli/init/install-module.js +16 -2
- package/lib/cli/init/types.d.ts +20 -0
- package/lib/cli/init/types.js +2 -0
- package/lib/cli/output.d.ts +1 -1
- package/lib/cli/output.js +6 -3
- package/lib/cli/prompt.d.ts +19 -14
- package/lib/cli/search/index.d.ts +1 -1
- package/lib/cli/search/index.js +2 -1
- package/lib/global-settings.d.ts +2 -2
- package/lib/i18n.d.ts +2 -6
- package/lib/i18n.js +8 -6
- package/lib/reporter/github-reporter.d.ts +2 -0
- package/lib/reporter/github-reporter.js +23 -0
- package/lib/reporter/index.d.ts +1 -0
- package/lib/reporter/index.js +1 -0
- package/lib/reporter/simple-reporter.js +1 -1
- package/lib/reporter/standard-reporter.js +5 -4
- package/lib/testing-tool/index.d.ts +44 -26
- package/lib/types.d.ts +18 -19
- package/lib/util.d.ts +4 -6
- package/lib/util.js +12 -10
- package/package.json +27 -23
- package/.markuplintrc +0 -19
- 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/cli/init/index.js
CHANGED
|
@@ -5,9 +5,10 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const util_1 = tslib_1.__importDefault(require("util"));
|
|
8
|
-
const ml_config_1 = require("@markuplint/ml-config");
|
|
9
8
|
const util_2 = require("../../util");
|
|
10
9
|
const prompt_1 = require("../prompt");
|
|
10
|
+
const create_config_1 = require("./create-config");
|
|
11
|
+
const get_default_rules_1 = require("./get-default-rules");
|
|
11
12
|
const install_module_1 = require("./install-module");
|
|
12
13
|
const writeFile = util_1.default.promisify(fs_1.default.writeFile);
|
|
13
14
|
const ruleCategories = {
|
|
@@ -15,234 +16,57 @@ const ruleCategories = {
|
|
|
15
16
|
message: 'Are you going to conformance check according to HTML standard?',
|
|
16
17
|
},
|
|
17
18
|
a11y: {
|
|
18
|
-
message: '
|
|
19
|
+
message: 'Do you want high accessibility?',
|
|
19
20
|
},
|
|
20
21
|
'naming-convention': {
|
|
21
22
|
message: 'Are you going to set the convention about naming?',
|
|
22
23
|
},
|
|
24
|
+
maintainability: {
|
|
25
|
+
message: 'Do you want high maintainability?',
|
|
26
|
+
},
|
|
23
27
|
style: {
|
|
24
28
|
message: 'Are you going to check for the code styles?',
|
|
25
29
|
},
|
|
26
30
|
};
|
|
27
|
-
const defaultRules = {
|
|
28
|
-
'attr-duplication': {
|
|
29
|
-
category: 'validation',
|
|
30
|
-
default: true,
|
|
31
|
-
},
|
|
32
|
-
'attr-value-quotes': {
|
|
33
|
-
category: 'style',
|
|
34
|
-
default: true,
|
|
35
|
-
},
|
|
36
|
-
'case-sensitive-attr-name': {
|
|
37
|
-
category: 'style',
|
|
38
|
-
default: true,
|
|
39
|
-
},
|
|
40
|
-
'case-sensitive-attr-value': {
|
|
41
|
-
category: 'style',
|
|
42
|
-
default: true,
|
|
43
|
-
},
|
|
44
|
-
'case-sensitive-tag-name': {
|
|
45
|
-
category: 'style',
|
|
46
|
-
default: true,
|
|
47
|
-
},
|
|
48
|
-
'character-reference': {
|
|
49
|
-
category: 'validation',
|
|
50
|
-
default: true,
|
|
51
|
-
},
|
|
52
|
-
'class-naming': {
|
|
53
|
-
category: 'naming-convention',
|
|
54
|
-
default: false,
|
|
55
|
-
recommendedValue: '/.+/',
|
|
56
|
-
},
|
|
57
|
-
'deprecated-attr': {
|
|
58
|
-
category: 'validation',
|
|
59
|
-
default: true,
|
|
60
|
-
},
|
|
61
|
-
'deprecated-element': {
|
|
62
|
-
category: 'validation',
|
|
63
|
-
default: true,
|
|
64
|
-
},
|
|
65
|
-
'disallowed-element': {
|
|
66
|
-
category: 'validation',
|
|
67
|
-
default: false,
|
|
68
|
-
},
|
|
69
|
-
doctype: {
|
|
70
|
-
category: 'validation',
|
|
71
|
-
default: true,
|
|
72
|
-
},
|
|
73
|
-
'end-tag': {
|
|
74
|
-
category: 'style',
|
|
75
|
-
default: true,
|
|
76
|
-
},
|
|
77
|
-
'id-duplication': {
|
|
78
|
-
category: 'validation',
|
|
79
|
-
default: true,
|
|
80
|
-
},
|
|
81
|
-
'ineffective-attr': {
|
|
82
|
-
category: 'validation',
|
|
83
|
-
default: true,
|
|
84
|
-
},
|
|
85
|
-
'invalid-attr': {
|
|
86
|
-
category: 'validation',
|
|
87
|
-
default: true,
|
|
88
|
-
},
|
|
89
|
-
'landmark-roles': {
|
|
90
|
-
category: 'a11y',
|
|
91
|
-
default: true,
|
|
92
|
-
},
|
|
93
|
-
'no-boolean-attr-value': {
|
|
94
|
-
category: 'style',
|
|
95
|
-
default: true,
|
|
96
|
-
},
|
|
97
|
-
'no-default-value': {
|
|
98
|
-
category: 'style',
|
|
99
|
-
default: true,
|
|
100
|
-
},
|
|
101
|
-
'no-hard-code-id': {
|
|
102
|
-
category: 'style',
|
|
103
|
-
default: true,
|
|
104
|
-
},
|
|
105
|
-
'no-refer-to-non-existent-id': {
|
|
106
|
-
category: 'a11y',
|
|
107
|
-
default: true,
|
|
108
|
-
},
|
|
109
|
-
'no-use-event-handler-attr': {
|
|
110
|
-
category: 'style',
|
|
111
|
-
default: true,
|
|
112
|
-
},
|
|
113
|
-
'permitted-contents': {
|
|
114
|
-
category: 'validation',
|
|
115
|
-
default: true,
|
|
116
|
-
},
|
|
117
|
-
'required-attr': {
|
|
118
|
-
category: 'validation',
|
|
119
|
-
default: true,
|
|
120
|
-
},
|
|
121
|
-
'required-element': {
|
|
122
|
-
category: 'validation',
|
|
123
|
-
default: true,
|
|
124
|
-
},
|
|
125
|
-
'required-h1': {
|
|
126
|
-
category: 'a11y',
|
|
127
|
-
default: true,
|
|
128
|
-
},
|
|
129
|
-
'use-list': {
|
|
130
|
-
category: 'a11y',
|
|
131
|
-
default: false,
|
|
132
|
-
},
|
|
133
|
-
'wai-aria': {
|
|
134
|
-
category: 'a11y',
|
|
135
|
-
default: true,
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
const extRExp = {
|
|
139
|
-
jsx: '\\.[jt]sx?$',
|
|
140
|
-
vue: '\\.vue$',
|
|
141
|
-
svelte: '\\.svelte$',
|
|
142
|
-
astro: '\\.astro',
|
|
143
|
-
pug: '\\.pug$',
|
|
144
|
-
php: '\\.php$',
|
|
145
|
-
erb: '\\.erb$',
|
|
146
|
-
ejs: '\\.ejs$',
|
|
147
|
-
mustache: '\\.(mustache|handlebars)$',
|
|
148
|
-
nunjucks: '\\.nunjucks$',
|
|
149
|
-
liquid: '\\.liquid$',
|
|
150
|
-
};
|
|
151
31
|
async function initialize() {
|
|
152
|
-
let config = {};
|
|
153
32
|
(0, util_2.write)((0, util_2.head)('Initialization'));
|
|
154
33
|
util_2.write.break();
|
|
155
|
-
const
|
|
34
|
+
const selectedLangs = await (0, prompt_1.multiSelect)({
|
|
156
35
|
message: 'Which do you use template engines?',
|
|
157
|
-
choices: [
|
|
158
|
-
{ name: 'React (JSX)', value: 'jsx' },
|
|
159
|
-
{ name: 'Vue', value: 'vue' },
|
|
160
|
-
{ name: 'Svelte', value: 'svelte' },
|
|
161
|
-
{ name: 'Astro', value: 'astro' },
|
|
162
|
-
{ name: 'Pug', value: 'pug' },
|
|
163
|
-
{ name: 'PHP', value: 'php' },
|
|
164
|
-
{ name: 'Smarty', value: 'smarty' },
|
|
165
|
-
{ name: 'eRuby', value: 'erb' },
|
|
166
|
-
{ name: 'EJS', value: 'ejs' },
|
|
167
|
-
{ name: 'Mustache/Handlebars', value: 'mustache' },
|
|
168
|
-
{ name: 'Nunjucks', value: 'nunjucks' },
|
|
169
|
-
{ name: 'liquid (Shopify)', value: 'liquid' },
|
|
170
|
-
],
|
|
36
|
+
choices: Object.entries(create_config_1.langs).map(([key, name]) => ({ name, value: key })),
|
|
171
37
|
});
|
|
172
38
|
const autoInstall = await (0, prompt_1.confirm)('May I install them automatically?');
|
|
173
39
|
const customize = await (0, prompt_1.confirm)('Do you customize rules?');
|
|
174
|
-
|
|
175
|
-
config.parser = config.parser || {};
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
const ext = extRExp[lang];
|
|
178
|
-
if (!ext) {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
config.parser[ext] = `@markuplint/${lang}-parser`;
|
|
182
|
-
if (lang === 'vue') {
|
|
183
|
-
config = (0, ml_config_1.mergeConfig)(config, {
|
|
184
|
-
specs: {
|
|
185
|
-
'\\.vue$': '@markuplint/vue-spec',
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (lang === 'jsx') {
|
|
190
|
-
config = (0, ml_config_1.mergeConfig)(config, {
|
|
191
|
-
specs: {
|
|
192
|
-
'\\.[jt]sx?$': '@markuplint/react-spec',
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
40
|
+
let ruleSettingMode = 'none';
|
|
197
41
|
if (customize) {
|
|
198
|
-
const ruleNames = Object.keys(defaultRules);
|
|
199
42
|
const categories = Object.keys(ruleCategories);
|
|
200
|
-
const
|
|
43
|
+
const selectedCategories = await (0, prompt_1.confirmSequence)(categories.map(catName => {
|
|
201
44
|
const cat = ruleCategories[catName];
|
|
202
45
|
return {
|
|
203
46
|
message: cat.message,
|
|
204
47
|
name: catName,
|
|
205
48
|
};
|
|
206
49
|
}));
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
if (res[rule.category]) {
|
|
213
|
-
if (!config.rules) {
|
|
214
|
-
config.rules = {};
|
|
215
|
-
}
|
|
216
|
-
config.rules[ruleName] = rule.recommendedValue || true;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
50
|
+
ruleSettingMode = Object.entries(selectedCategories)
|
|
51
|
+
.map(([name, enabled]) => (enabled ? name : ''))
|
|
52
|
+
.filter((name) => !!name);
|
|
219
53
|
}
|
|
220
|
-
else {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
for (const ruleName of ruleNames) {
|
|
229
|
-
const rule = defaultRules[ruleName];
|
|
230
|
-
config.rules[ruleName] = rule.default;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
54
|
+
else if (await (0, prompt_1.confirm)('Does it import the recommended config?')) {
|
|
55
|
+
ruleSettingMode = 'recommended';
|
|
56
|
+
}
|
|
57
|
+
let defaultRules = {};
|
|
58
|
+
if (ruleSettingMode !== 'recommended') {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
60
|
+
const rulesVersion = require('../../../package.json').version;
|
|
61
|
+
defaultRules = await (0, get_default_rules_1.getDefaultRules)(rulesVersion);
|
|
233
62
|
}
|
|
63
|
+
const config = (0, create_config_1.createConfig)(selectedLangs, ruleSettingMode, defaultRules);
|
|
234
64
|
const filePath = path_1.default.resolve(process.cwd(), '.markuplintrc');
|
|
235
65
|
await writeFile(filePath, JSON.stringify(config, null, 2), { encoding: 'utf-8' });
|
|
236
66
|
(0, util_2.write)(`✨Created: ${filePath}`);
|
|
237
67
|
if (autoInstall) {
|
|
238
68
|
(0, util_2.write)('Install automatically');
|
|
239
|
-
const modules =
|
|
240
|
-
if (langs.includes('vue')) {
|
|
241
|
-
modules.push('@markuplint/vue-spec');
|
|
242
|
-
}
|
|
243
|
-
if (langs.includes('jsx')) {
|
|
244
|
-
modules.push('@markuplint/react-spec');
|
|
245
|
-
}
|
|
69
|
+
const modules = (0, install_module_1.selectModules)(selectedLangs);
|
|
246
70
|
const result = await (0, install_module_1.installModule)(modules, true).catch(e => new Error(e));
|
|
247
71
|
if (result instanceof Error) {
|
|
248
72
|
util_2.error.exit();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Langs } from './types';
|
|
2
|
+
export type InstallModuleResult = {
|
|
3
|
+
success: boolean;
|
|
4
|
+
alreadyExists: boolean;
|
|
4
5
|
};
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function selectModules(selectedLangs: readonly Langs[]): string[];
|
|
7
|
+
export declare function installModule(module: readonly string[], dev?: boolean): Promise<InstallModuleResult>;
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installModule = void 0;
|
|
3
|
+
exports.installModule = exports.selectModules = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
const detect_installed_1 = tslib_1.__importDefault(require("detect-installed"));
|
|
9
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;
|
|
10
21
|
async function installModule(module, dev = false) {
|
|
11
22
|
module = module.map(m => m.trim());
|
|
12
23
|
const uninstallMods = [];
|
|
@@ -21,7 +32,7 @@ async function installModule(module, dev = false) {
|
|
|
21
32
|
catch (_) {
|
|
22
33
|
// void
|
|
23
34
|
}
|
|
24
|
-
if (
|
|
35
|
+
if (uninstallMods.length === 0) {
|
|
25
36
|
return {
|
|
26
37
|
success: true,
|
|
27
38
|
alreadyExists: true,
|
|
@@ -33,6 +44,9 @@ async function installModule(module, dev = false) {
|
|
|
33
44
|
if (dev) {
|
|
34
45
|
opt.push('-D');
|
|
35
46
|
}
|
|
47
|
+
if (!(0, has_yarn_1.default)()) {
|
|
48
|
+
opt.push('--legacy-peer-deps');
|
|
49
|
+
}
|
|
36
50
|
opt.push(...uninstallMods);
|
|
37
51
|
return new Promise((resolve, reject) => {
|
|
38
52
|
process.stdout.write(cli_color_1.default.blackBright(`${mod} ${opt.join(' ')}\n`));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Langs =
|
|
2
|
+
| 'jsx'
|
|
3
|
+
| 'vue'
|
|
4
|
+
| 'svelte'
|
|
5
|
+
| 'astro'
|
|
6
|
+
| 'pug'
|
|
7
|
+
| 'php'
|
|
8
|
+
| 'smarty'
|
|
9
|
+
| 'erb'
|
|
10
|
+
| 'ejs'
|
|
11
|
+
| 'mustache'
|
|
12
|
+
| 'nunjucks'
|
|
13
|
+
| 'liquid';
|
|
14
|
+
export type Category = 'validation' | 'a11y' | 'naming-convention' | 'style' | 'maintainability';
|
|
15
|
+
export type RuleSettingMode = readonly Category[] | 'recommended' | 'none';
|
|
16
|
+
export type DefaultRules = Readonly<Record<string, Rule>>;
|
|
17
|
+
export type Rule = {
|
|
18
|
+
readonly category: Category;
|
|
19
|
+
readonly defaultValue: boolean | string | number;
|
|
20
|
+
};
|
package/lib/cli/output.d.ts
CHANGED
package/lib/cli/output.js
CHANGED
|
@@ -10,24 +10,27 @@ function output(results, options) {
|
|
|
10
10
|
let out;
|
|
11
11
|
switch (format.toLowerCase()) {
|
|
12
12
|
case 'json': {
|
|
13
|
-
process.stdout.write(JSON.stringify(results.violations, null, 2));
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
15
|
case 'simple': {
|
|
17
16
|
out = (0, reporter_1.simpleReporter)(results, options);
|
|
18
17
|
break;
|
|
19
18
|
}
|
|
19
|
+
case 'github': {
|
|
20
|
+
out = (0, reporter_1.githubReporter)(results);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
20
23
|
default: {
|
|
21
24
|
out = (0, reporter_1.standardReporter)(results, options);
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
if (
|
|
27
|
+
if (out.length === 0) {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
27
30
|
let msg = `${out.join('\n')}\n`;
|
|
28
31
|
msg = options.color ? msg : (0, strip_ansi_1.default)(msg);
|
|
29
32
|
// If it has errors, Write to `stderr` and failure and exit.
|
|
30
|
-
if (results.violations.length) {
|
|
33
|
+
if (results.violations.length > 0) {
|
|
31
34
|
process.stderr.write(msg);
|
|
32
35
|
process.exitCode = 1;
|
|
33
36
|
return;
|
package/lib/cli/prompt.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type SelectQuestion<T> = {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
readonly choices: readonly {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly value: T;
|
|
6
|
+
}[];
|
|
7
7
|
};
|
|
8
8
|
export declare function select<T>(question: SelectQuestion<T>): Promise<T>;
|
|
9
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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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>>;
|
|
18
23
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { CLIOptions } from '../bootstrap';
|
|
2
|
-
export default function (files: string[], options: CLIOptions, selectors: string): Promise<void>;
|
|
2
|
+
export default function (files: readonly string[], options: CLIOptions, selectors: string): Promise<void>;
|
package/lib/cli/search/index.js
CHANGED
|
@@ -17,8 +17,9 @@ async function default_1(files, options, selectors) {
|
|
|
17
17
|
verify({ document }) {
|
|
18
18
|
const nodes = document.querySelectorAll(selectors);
|
|
19
19
|
locations.push(...Array.from(nodes).map(node => {
|
|
20
|
+
var _a;
|
|
20
21
|
return {
|
|
21
|
-
file: document.filename
|
|
22
|
+
file: (_a = document.filename) !== null && _a !== void 0 ? _a : '_NO_FILE_',
|
|
22
23
|
line: node.startLine,
|
|
23
24
|
col: node.startCol,
|
|
24
25
|
};
|
package/lib/global-settings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type GlobalSettings = {
|
|
2
|
+
readonly locale: string;
|
|
3
3
|
};
|
|
4
4
|
export declare function setGlobal(settings: Partial<GlobalSettings>): void;
|
|
5
5
|
export declare function getGlobal(): Readonly<Partial<GlobalSettings>>;
|
package/lib/i18n.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
listFormat?: import("packages/@markuplint/i18n/src/types").ListFormat | undefined;
|
|
4
|
-
keywords?: import("packages/@markuplint/i18n/src/types").LocalesKeywords | undefined;
|
|
5
|
-
sentences?: import("packages/@markuplint/i18n/src/types").LocalesKeywords | undefined;
|
|
6
|
-
}>;
|
|
1
|
+
import type { LocaleSet } from '@markuplint/i18n';
|
|
2
|
+
export declare function i18n(locale?: string): Promise<LocaleSet>;
|
package/lib/i18n.js
CHANGED
|
@@ -11,14 +11,16 @@ async function getLocale() {
|
|
|
11
11
|
return cachedLocale;
|
|
12
12
|
}
|
|
13
13
|
async function i18n(locale) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
var _a, _b;
|
|
15
|
+
locale = (_a = locale !== null && locale !== void 0 ? locale : (await getLocale())) !== null && _a !== void 0 ? _a : 'en';
|
|
16
|
+
const langCode = (_b = locale.split('-')[0]) !== null && _b !== void 0 ? _b : locale;
|
|
17
|
+
const loadLocaleSet = await Promise.resolve(`${`@markuplint/i18n/locales/${langCode}`}`).then(s => tslib_1.__importStar(require(s))).catch(() => null);
|
|
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'))));
|
|
19
21
|
return {
|
|
20
|
-
locale: langCode,
|
|
21
22
|
...localeSet,
|
|
23
|
+
locale: loadLocaleSet ? langCode : 'en',
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
exports.i18n = i18n;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.githubReporter = void 0;
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
function githubReporter(results) {
|
|
6
|
+
const out = [];
|
|
7
|
+
for (const violation of results.violations) {
|
|
8
|
+
const command = severityToCommand(violation.severity);
|
|
9
|
+
const meg = (0, util_1.messageToString)(violation.message, violation.reason);
|
|
10
|
+
out.push(`::${command} file=${results.filePath},line=${violation.line},col=${violation.col}::${meg} (${violation.ruleId})`);
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
exports.githubReporter = githubReporter;
|
|
15
|
+
function severityToCommand(severity) {
|
|
16
|
+
switch (severity) {
|
|
17
|
+
case 'info':
|
|
18
|
+
return 'notice';
|
|
19
|
+
case 'error':
|
|
20
|
+
case 'warning':
|
|
21
|
+
return severity;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/lib/reporter/index.d.ts
CHANGED
package/lib/reporter/index.js
CHANGED
|
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./standard-reporter"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./simple-reporter"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./github-reporter"), exports);
|
|
@@ -19,7 +19,7 @@ function simpleReporter(results, options) {
|
|
|
19
19
|
sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
|
|
20
20
|
}
|
|
21
21
|
const out = [];
|
|
22
|
-
if (results.violations.length) {
|
|
22
|
+
if (results.violations.length > 0) {
|
|
23
23
|
out.push(`<${util_1.markuplint}> ${cli_color_1.default.underline(results.filePath)}: ${loggerError('✗')}`);
|
|
24
24
|
for (const violation of results.violations) {
|
|
25
25
|
const s = violation.severity === 'error' ? loggerError('✖') : loggerWarning('⚠️');
|
|
@@ -7,6 +7,7 @@ const util_1 = require("../util");
|
|
|
7
7
|
const loggerError = cli_color_1.default.red;
|
|
8
8
|
const loggerWarning = cli_color_1.default.xterm(208);
|
|
9
9
|
function standardReporter(results, options) {
|
|
10
|
+
var _a, _b, _c;
|
|
10
11
|
const sizes = {
|
|
11
12
|
line: 0,
|
|
12
13
|
col: 0,
|
|
@@ -19,12 +20,12 @@ function standardReporter(results, options) {
|
|
|
19
20
|
sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
|
|
20
21
|
}
|
|
21
22
|
const out = [];
|
|
22
|
-
if (results.violations.length) {
|
|
23
|
+
if (results.violations.length > 0) {
|
|
23
24
|
const lines = results.sourceCode.split(/\r?\n/g);
|
|
24
25
|
for (const violation of results.violations) {
|
|
25
|
-
const prev = lines[violation.line - 2]
|
|
26
|
-
const line = lines[violation.line - 1]
|
|
27
|
-
const next = lines[violation.line - 0]
|
|
26
|
+
const prev = (_a = lines[violation.line - 2]) !== null && _a !== void 0 ? _a : '';
|
|
27
|
+
const line = (_b = lines[violation.line - 1]) !== null && _b !== void 0 ? _b : '';
|
|
28
|
+
const next = (_c = lines[violation.line - 0]) !== null && _c !== void 0 ? _c : '';
|
|
28
29
|
const before = line.substring(0, violation.col - 1);
|
|
29
30
|
const after = line.substring(violation.col - 1 + violation.raw.length);
|
|
30
31
|
const logger = violation.severity === 'error' ? loggerError : loggerWarning;
|
|
@@ -1,33 +1,51 @@
|
|
|
1
1
|
import type { Target } from '@markuplint/file-resolver';
|
|
2
|
-
import type { Config, RuleConfigValue, Rule, RegexSelector } from '@markuplint/ml-config';
|
|
2
|
+
import type { Config, RuleConfigValue, Rule, RegexSelector, PlainData } from '@markuplint/ml-config';
|
|
3
3
|
import type { AnyMLRule, RuleSeed } from '@markuplint/ml-core';
|
|
4
|
-
export declare function mlTest(
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare function mlTest(
|
|
5
|
+
sourceCode: string,
|
|
6
|
+
config: Config,
|
|
7
|
+
rules?: readonly Readonly<AnyMLRule>[],
|
|
8
|
+
locale?: string,
|
|
9
|
+
fix?: boolean,
|
|
10
|
+
): Promise<{
|
|
11
|
+
violations: readonly import('@markuplint/ml-config').Violation[];
|
|
12
|
+
fixedCode: string;
|
|
7
13
|
}>;
|
|
8
|
-
export declare function mlRuleTest<T extends RuleConfigValue, O
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
export declare function mlRuleTest<T extends RuleConfigValue, O extends PlainData>(
|
|
15
|
+
rule: Readonly<RuleSeed<T, O>>,
|
|
16
|
+
sourceCode: string,
|
|
17
|
+
config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
|
|
18
|
+
rule?: Rule<T, Partial<O>>;
|
|
19
|
+
nodeRule?: NodeRule<T, Partial<O>>[];
|
|
20
|
+
childNodeRule?: ChildNodeRule<T, Partial<O>>[];
|
|
21
|
+
},
|
|
22
|
+
fix?: boolean,
|
|
23
|
+
locale?: string,
|
|
24
|
+
): Promise<{
|
|
25
|
+
violations: readonly import('@markuplint/ml-config').Violation[];
|
|
26
|
+
fixedCode: string;
|
|
15
27
|
}>;
|
|
16
|
-
export declare function mlTestFile(
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
export declare function mlTestFile(
|
|
29
|
+
target: Target,
|
|
30
|
+
config?: Config,
|
|
31
|
+
rules?: readonly Readonly<AnyMLRule>[],
|
|
32
|
+
locale?: string,
|
|
33
|
+
fix?: boolean,
|
|
34
|
+
): Promise<{
|
|
35
|
+
violations: readonly import('@markuplint/ml-config').Violation[];
|
|
36
|
+
fixedCode: string | undefined;
|
|
19
37
|
}>;
|
|
20
|
-
export interface NodeRule<T extends RuleConfigValue, O =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
export interface NodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
39
|
+
selector?: string;
|
|
40
|
+
regexSelector?: RegexSelector;
|
|
41
|
+
categories?: string[];
|
|
42
|
+
roles?: string[];
|
|
43
|
+
obsolete?: boolean;
|
|
44
|
+
rule?: Rule<T, O>;
|
|
27
45
|
}
|
|
28
|
-
export interface ChildNodeRule<T extends RuleConfigValue, O =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
export interface ChildNodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
47
|
+
selector?: string;
|
|
48
|
+
regexSelector?: RegexSelector;
|
|
49
|
+
inheritance?: boolean;
|
|
50
|
+
rule?: Rule<T, O>;
|
|
33
51
|
}
|