markuplint 3.0.0-canary.3 → 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.
Files changed (44) hide show
  1. package/README.md +8 -6
  2. package/lib/api/lint.d.ts +2 -2
  3. package/lib/api/ml-engine.d.ts +24 -23
  4. package/lib/api/ml-engine.js +37 -18
  5. package/lib/api/types.d.ts +33 -37
  6. package/lib/api/v1.d.ts +44 -44
  7. package/lib/api/v1.js +4 -7
  8. package/lib/cli/bootstrap.d.ts +3 -2
  9. package/lib/cli/bootstrap.js +1 -1
  10. package/lib/cli/command.d.ts +6 -2
  11. package/lib/cli/command.js +2 -2
  12. package/lib/cli/create-rule/index.js +48 -19
  13. package/lib/cli/index.js +1 -1
  14. package/lib/cli/init/create-config.d.ts +8 -0
  15. package/lib/cli/init/create-config.js +95 -0
  16. package/lib/cli/init/get-default-rules.d.ts +3 -0
  17. package/lib/cli/init/get-default-rules.js +57 -0
  18. package/lib/cli/init/index.js +23 -207
  19. package/lib/cli/init/install-module.d.ts +5 -3
  20. package/lib/cli/init/install-module.js +16 -2
  21. package/lib/cli/init/types.d.ts +20 -0
  22. package/lib/cli/init/types.js +2 -0
  23. package/lib/cli/output.d.ts +1 -1
  24. package/lib/cli/output.js +6 -2
  25. package/lib/cli/prompt.d.ts +18 -13
  26. package/lib/cli/search/index.d.ts +1 -1
  27. package/lib/cli/search/index.js +2 -1
  28. package/lib/global-settings.d.ts +1 -1
  29. package/lib/i18n.js +8 -7
  30. package/lib/reporter/github-reporter.d.ts +2 -0
  31. package/lib/reporter/github-reporter.js +23 -0
  32. package/lib/reporter/index.d.ts +1 -0
  33. package/lib/reporter/index.js +1 -0
  34. package/lib/reporter/simple-reporter.js +1 -1
  35. package/lib/reporter/standard-reporter.js +5 -4
  36. package/lib/testing-tool/index.d.ts +44 -26
  37. package/lib/types.d.ts +18 -19
  38. package/lib/util.d.ts +3 -5
  39. package/lib/util.js +9 -7
  40. package/package.json +25 -21
  41. package/media/screenshot01.png +0 -0
  42. package/test/plugin001.js +0 -24
  43. package/tsconfig.test.json +0 -3
  44. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfig = exports.langs = void 0;
4
+ const extRExp = {
5
+ jsx: '\\.[jt]sx?$',
6
+ vue: '\\.vue$',
7
+ svelte: '\\.svelte$',
8
+ astro: '\\.astro$',
9
+ pug: '\\.pug$',
10
+ php: '\\.php$',
11
+ smarty: '\\.tpl$',
12
+ erb: '\\.erb$',
13
+ ejs: '\\.ejs$',
14
+ mustache: '\\.(mustache|hbs)$',
15
+ nunjucks: '\\.nunjucks$',
16
+ liquid: '\\.liquid$',
17
+ };
18
+ exports.langs = {
19
+ jsx: 'React (JSX)',
20
+ vue: 'Vue',
21
+ svelte: 'Svelte',
22
+ astro: 'Astro',
23
+ pug: 'Pug',
24
+ php: 'PHP',
25
+ smarty: 'Smarty',
26
+ erb: 'eRuby',
27
+ ejs: 'EJS',
28
+ mustache: 'Mustache/Handlebars',
29
+ nunjucks: 'Nunjucks',
30
+ liquid: 'liquid (Shopify)',
31
+ };
32
+ function createConfig(langs, mode, defaultRules) {
33
+ var _a;
34
+ let config = {};
35
+ const parser = { ...config.parser };
36
+ for (const lang of langs) {
37
+ const ext = extRExp[lang];
38
+ if (!ext) {
39
+ continue;
40
+ }
41
+ parser[ext] = `@markuplint/${lang}-parser`;
42
+ if (lang === 'vue') {
43
+ config = {
44
+ ...config,
45
+ specs: {
46
+ ...config.specs,
47
+ '\\.vue$': '@markuplint/vue-spec',
48
+ },
49
+ };
50
+ }
51
+ if (lang === 'jsx') {
52
+ config = {
53
+ ...config,
54
+ specs: {
55
+ ...config.specs,
56
+ '\\.[jt]sx?$': '@markuplint/react-spec',
57
+ },
58
+ };
59
+ }
60
+ }
61
+ if (Object.keys(parser).length > 0) {
62
+ config.parser = parser;
63
+ }
64
+ const rules = { ...config.rules };
65
+ if (Array.isArray(mode)) {
66
+ const ruleNames = Object.keys(defaultRules);
67
+ for (const ruleName of ruleNames) {
68
+ const rule = defaultRules[ruleName];
69
+ if (!rule) {
70
+ continue;
71
+ }
72
+ if (mode.includes(rule.category)) {
73
+ rules[ruleName] = rule.defaultValue;
74
+ }
75
+ }
76
+ }
77
+ else if (mode === 'recommended') {
78
+ config.extends = [...((_a = config.extends) !== null && _a !== void 0 ? _a : []), 'markuplint:recommended'];
79
+ }
80
+ else {
81
+ const ruleNames = Object.keys(defaultRules);
82
+ for (const ruleName of ruleNames) {
83
+ const rule = defaultRules[ruleName];
84
+ if (!rule) {
85
+ continue;
86
+ }
87
+ rules[ruleName] = rule.defaultValue;
88
+ }
89
+ }
90
+ if (Object.keys(rules).length > 0) {
91
+ config.rules = rules;
92
+ }
93
+ return config;
94
+ }
95
+ exports.createConfig = createConfig;
@@ -0,0 +1,3 @@
1
+ export declare function getDefaultRules(version: string): Promise<{
2
+ [x: string]: import('./types').Rule;
3
+ }>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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);
11
+ const rules = {};
12
+ await Promise.all(Object.entries(json.definitions.rules.properties).map(async ([name, rule]) => {
13
+ var _a, _b, _c, _d;
14
+ const json = await safeFetch(rule.$ref.replace('/main/', '/[VERSION]/'), version);
15
+ let severity = (_c = (_b = (_a = (Array.isArray(json.oneOf) ? json.oneOf : []).find((val) => val.properties)) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.severity) === null || _c === void 0 ? void 0 : _c.default;
16
+ let category = json._category;
17
+ if (severity == null || category == null) {
18
+ const data = await getCatAndSeverityFromLegacy(version, name);
19
+ severity = data.severity;
20
+ category = data.category;
21
+ }
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
+ }
40
+ const md = await res.text();
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
+ };
57
+ }
@@ -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,242 +16,57 @@ const ruleCategories = {
15
16
  message: 'Are you going to conformance check according to HTML standard?',
16
17
  },
17
18
  a11y: {
18
- message: 'Are you going to do with accessibility better practices?',
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: 'style',
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
- 'label-has-control': {
90
- category: 'a11y',
91
- default: false,
92
- },
93
- 'landmark-roles': {
94
- category: 'a11y',
95
- default: true,
96
- },
97
- 'no-boolean-attr-value': {
98
- category: 'style',
99
- default: true,
100
- },
101
- 'no-default-value': {
102
- category: 'style',
103
- default: true,
104
- },
105
- 'no-empty-palpable-content': {
106
- category: 'validation',
107
- default: false,
108
- },
109
- 'no-hard-code-id': {
110
- category: 'style',
111
- default: true,
112
- },
113
- 'no-refer-to-non-existent-id': {
114
- category: 'a11y',
115
- default: true,
116
- },
117
- 'no-use-event-handler-attr': {
118
- category: 'style',
119
- default: true,
120
- },
121
- 'permitted-contents': {
122
- category: 'validation',
123
- default: true,
124
- },
125
- 'required-attr': {
126
- category: 'validation',
127
- default: true,
128
- },
129
- 'required-element': {
130
- category: 'validation',
131
- default: true,
132
- },
133
- 'required-h1': {
134
- category: 'a11y',
135
- default: true,
136
- },
137
- 'use-list': {
138
- category: 'a11y',
139
- default: false,
140
- },
141
- 'wai-aria': {
142
- category: 'a11y',
143
- default: true,
144
- },
145
- };
146
- const extRExp = {
147
- jsx: '\\.[jt]sx?$',
148
- vue: '\\.vue$',
149
- svelte: '\\.svelte$',
150
- astro: '\\.astro',
151
- pug: '\\.pug$',
152
- php: '\\.php$',
153
- erb: '\\.erb$',
154
- ejs: '\\.ejs$',
155
- mustache: '\\.(mustache|handlebars)$',
156
- nunjucks: '\\.nunjucks$',
157
- liquid: '\\.liquid$',
158
- };
159
31
  async function initialize() {
160
- let config = {};
161
32
  (0, util_2.write)((0, util_2.head)('Initialization'));
162
33
  util_2.write.break();
163
- const langs = await (0, prompt_1.multiSelect)({
34
+ const selectedLangs = await (0, prompt_1.multiSelect)({
164
35
  message: 'Which do you use template engines?',
165
- choices: [
166
- { name: 'React (JSX)', value: 'jsx' },
167
- { name: 'Vue', value: 'vue' },
168
- { name: 'Svelte', value: 'svelte' },
169
- { name: 'Astro', value: 'astro' },
170
- { name: 'Pug', value: 'pug' },
171
- { name: 'PHP', value: 'php' },
172
- { name: 'Smarty', value: 'smarty' },
173
- { name: 'eRuby', value: 'erb' },
174
- { name: 'EJS', value: 'ejs' },
175
- { name: 'Mustache/Handlebars', value: 'mustache' },
176
- { name: 'Nunjucks', value: 'nunjucks' },
177
- { name: 'liquid (Shopify)', value: 'liquid' },
178
- ],
36
+ choices: Object.entries(create_config_1.langs).map(([key, name]) => ({ name, value: key })),
179
37
  });
180
38
  const autoInstall = await (0, prompt_1.confirm)('May I install them automatically?');
181
39
  const customize = await (0, prompt_1.confirm)('Do you customize rules?');
182
- for (const lang of langs) {
183
- config.parser = config.parser || {};
184
- // @ts-ignore
185
- const ext = extRExp[lang];
186
- if (!ext) {
187
- continue;
188
- }
189
- config.parser[ext] = `@markuplint/${lang}-parser`;
190
- if (lang === 'vue') {
191
- config = (0, ml_config_1.mergeConfig)(config, {
192
- specs: {
193
- '\\.vue$': '@markuplint/vue-spec',
194
- },
195
- });
196
- }
197
- if (lang === 'jsx') {
198
- config = (0, ml_config_1.mergeConfig)(config, {
199
- specs: {
200
- '\\.[jt]sx?$': '@markuplint/react-spec',
201
- },
202
- });
203
- }
204
- }
40
+ let ruleSettingMode = 'none';
205
41
  if (customize) {
206
- const ruleNames = Object.keys(defaultRules);
207
42
  const categories = Object.keys(ruleCategories);
208
- const res = await (0, prompt_1.confirmSequence)(categories.map(catName => {
43
+ const selectedCategories = await (0, prompt_1.confirmSequence)(categories.map(catName => {
209
44
  const cat = ruleCategories[catName];
210
45
  return {
211
46
  message: cat.message,
212
47
  name: catName,
213
48
  };
214
49
  }));
215
- for (const ruleName of ruleNames) {
216
- const rule = defaultRules[ruleName];
217
- if (!rule) {
218
- continue;
219
- }
220
- if (res[rule.category]) {
221
- if (!config.rules) {
222
- config.rules = {};
223
- }
224
- config.rules[ruleName] = rule.recommendedValue || true;
225
- }
226
- }
50
+ ruleSettingMode = Object.entries(selectedCategories)
51
+ .map(([name, enabled]) => (enabled ? name : ''))
52
+ .filter((name) => !!name);
227
53
  }
228
- else {
229
- const recommended = await (0, prompt_1.confirm)('Does it import the recommended config?');
230
- if (recommended) {
231
- config.extends = [...(config.extends || []), 'markuplint:recommended'];
232
- }
233
- else {
234
- config.rules = {};
235
- const ruleNames = Object.keys(defaultRules);
236
- for (const ruleName of ruleNames) {
237
- const rule = defaultRules[ruleName];
238
- config.rules[ruleName] = rule.default;
239
- }
240
- }
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);
241
62
  }
63
+ const config = (0, create_config_1.createConfig)(selectedLangs, ruleSettingMode, defaultRules);
242
64
  const filePath = path_1.default.resolve(process.cwd(), '.markuplintrc');
243
65
  await writeFile(filePath, JSON.stringify(config, null, 2), { encoding: 'utf-8' });
244
66
  (0, util_2.write)(`✨Created: ${filePath}`);
245
67
  if (autoInstall) {
246
68
  (0, util_2.write)('Install automatically');
247
- const modules = ['markuplint', ...langs.map(lang => `@markuplint/${lang}-parser`)];
248
- if (langs.includes('vue')) {
249
- modules.push('@markuplint/vue-spec');
250
- }
251
- if (langs.includes('jsx')) {
252
- modules.push('@markuplint/react-spec');
253
- }
69
+ const modules = (0, install_module_1.selectModules)(selectedLangs);
254
70
  const result = await (0, install_module_1.installModule)(modules, true).catch(e => new Error(e));
255
71
  if (result instanceof Error) {
256
72
  util_2.error.exit();
@@ -1,5 +1,7 @@
1
+ import type { Langs } from './types';
1
2
  export type InstallModuleResult = {
2
- success: boolean;
3
- alreadyExists: boolean;
3
+ success: boolean;
4
+ alreadyExists: boolean;
4
5
  };
5
- export declare function installModule(module: string[], dev?: boolean): Promise<InstallModuleResult>;
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 (!uninstallMods.length) {
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
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
- import type { MLResultInfo } from '../types';
2
1
  import type { CLIOptions } from './bootstrap';
2
+ import type { MLResultInfo } from '../types';
3
3
  export declare function output(results: MLResultInfo, options: CLIOptions): void;
package/lib/cli/output.js CHANGED
@@ -16,17 +16,21 @@ function output(results, options) {
16
16
  out = (0, reporter_1.simpleReporter)(results, options);
17
17
  break;
18
18
  }
19
+ case 'github': {
20
+ out = (0, reporter_1.githubReporter)(results);
21
+ break;
22
+ }
19
23
  default: {
20
24
  out = (0, reporter_1.standardReporter)(results, options);
21
25
  }
22
26
  }
23
- if (!out.length) {
27
+ if (out.length === 0) {
24
28
  return;
25
29
  }
26
30
  let msg = `${out.join('\n')}\n`;
27
31
  msg = options.color ? msg : (0, strip_ansi_1.default)(msg);
28
32
  // If it has errors, Write to `stderr` and failure and exit.
29
- if (results.violations.length) {
33
+ if (results.violations.length > 0) {
30
34
  process.stderr.write(msg);
31
35
  process.exitCode = 1;
32
36
  return;
@@ -1,18 +1,23 @@
1
1
  type SelectQuestion<T> = {
2
- message: string;
3
- choices: {
4
- name: string;
5
- value: T;
6
- }[];
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(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>>;
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>;
@@ -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 || '_NO_FILE_',
22
+ file: (_a = document.filename) !== null && _a !== void 0 ? _a : '_NO_FILE_',
22
23
  line: node.startLine,
23
24
  col: node.startCol,
24
25
  };
@@ -1,5 +1,5 @@
1
1
  export type GlobalSettings = {
2
- locale: string;
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.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.i18n = void 0;
5
4
  const tslib_1 = require("tslib");
@@ -12,14 +11,16 @@ async function getLocale() {
12
11
  return cachedLocale;
13
12
  }
14
13
  async function i18n(locale) {
15
- locale = locale || (await getLocale()) || 'en';
16
- const langCode = locale.split('-')[0];
17
- const localeSet = langCode
18
- ? await (_a = `@markuplint/i18n/locales/${langCode}`, Promise.resolve().then(() => tslib_1.__importStar(require(_a)))).catch(() => null)
19
- : null;
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'))));
20
21
  return {
21
- locale: langCode,
22
22
  ...localeSet,
23
+ locale: loadLocaleSet ? langCode : 'en',
23
24
  };
24
25
  }
25
26
  exports.i18n = i18n;
@@ -0,0 +1,2 @@
1
+ import type { MLResultInfo } from '../types';
2
+ export declare function githubReporter(results: MLResultInfo): string[];
@@ -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
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './standard-reporter';
2
2
  export * from './simple-reporter';
3
+ export * from './github-reporter';