markuplint 3.12.0 → 4.0.0-alpha.1

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 (54) hide show
  1. package/README.md +1 -0
  2. package/bin/markuplint.mjs +3 -0
  3. package/lib/api/index.d.ts +2 -2
  4. package/lib/api/index.js +2 -10
  5. package/lib/api/lint.d.ts +2 -2
  6. package/lib/api/lint.js +5 -10
  7. package/lib/api/ml-engine.d.ts +7 -2
  8. package/lib/api/ml-engine.js +99 -99
  9. package/lib/api/types.js +1 -2
  10. package/lib/api/v1.d.ts +1 -1
  11. package/lib/api/v1.js +12 -20
  12. package/lib/cli/bootstrap.d.ts +4 -5
  13. package/lib/cli/bootstrap.js +7 -10
  14. package/lib/cli/command.d.ts +2 -2
  15. package/lib/cli/command.js +19 -25
  16. package/lib/cli/create-rule/index.js +26 -32
  17. package/lib/cli/index.js +26 -29
  18. package/lib/cli/init/create-config.d.ts +1 -1
  19. package/lib/cli/init/create-config.js +3 -8
  20. package/lib/cli/init/get-default-rules.d.ts +1 -1
  21. package/lib/cli/init/get-default-rules.js +8 -13
  22. package/lib/cli/init/index.js +30 -34
  23. package/lib/cli/init/install-module.d.ts +1 -1
  24. package/lib/cli/init/install-module.js +12 -18
  25. package/lib/cli/init/types.js +1 -2
  26. package/lib/cli/output.d.ts +2 -2
  27. package/lib/cli/output.js +8 -14
  28. package/lib/cli/prompt.js +15 -25
  29. package/lib/cli/search/index.d.ts +1 -1
  30. package/lib/cli/search/index.js +7 -11
  31. package/lib/debug.js +8 -13
  32. package/lib/get-json-module.d.ts +1 -0
  33. package/lib/get-json-module.js +10 -0
  34. package/lib/global-settings.js +2 -7
  35. package/lib/i18n.js +8 -15
  36. package/lib/index.d.ts +6 -5
  37. package/lib/index.js +6 -10
  38. package/lib/reporter/github-reporter.d.ts +1 -1
  39. package/lib/reporter/github-reporter.js +3 -7
  40. package/lib/reporter/index.d.ts +3 -3
  41. package/lib/reporter/index.js +3 -6
  42. package/lib/reporter/simple-reporter.d.ts +2 -2
  43. package/lib/reporter/simple-reporter.js +11 -16
  44. package/lib/reporter/standard-reporter.d.ts +2 -2
  45. package/lib/reporter/standard-reporter.js +17 -23
  46. package/lib/testing-tool/index.js +17 -25
  47. package/lib/types.js +1 -2
  48. package/lib/util.js +21 -33
  49. package/lib/v1.d.ts +1 -1
  50. package/lib/v1.js +1 -5
  51. package/lib/version.d.ts +1 -0
  52. package/lib/version.js +3 -0
  53. package/package.json +30 -25
  54. package/bin/markuplint +0 -3
package/README.md CHANGED
@@ -77,6 +77,7 @@ Options
77
77
  --format, -f FORMAT Output format. Support "JSON", "Simple", "GitHub" and "Standard". Default: "Standard".
78
78
  --no-search-config No search a configure file automatically.
79
79
  --ignore-ext Evaluate files that are received even though the type of extension.
80
+ --allow-warnings Return status code 0 even if there are warnings.
80
81
  --no-import-preset-rules No import preset rules.
81
82
  --locale Locale of the message of violation. Default is an OS setting.
82
83
  --no-color, Output no color.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ await import('../lib/cli/index.js');
@@ -1,2 +1,2 @@
1
- export { default as MLEngine } from './ml-engine';
2
- export { lint } from './lint';
1
+ export { default as MLEngine, FromCodeOptions } from './ml-engine.js';
2
+ export { lint } from './lint.js';
package/lib/api/index.js CHANGED
@@ -1,10 +1,2 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.lint = exports.MLEngine = void 0;
7
- var ml_engine_1 = require("./ml-engine");
8
- Object.defineProperty(exports, "MLEngine", { enumerable: true, get: function () { return __importDefault(ml_engine_1).default; } });
9
- var lint_1 = require("./lint");
10
- Object.defineProperty(exports, "lint", { enumerable: true, get: function () { return lint_1.lint; } });
1
+ export { default as MLEngine } from './ml-engine.js';
2
+ export { lint } from './lint.js';
package/lib/api/lint.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { APIOptions } from './types';
2
- import type { MLResultInfo } from '../types';
1
+ import type { APIOptions } from './types.js';
2
+ import type { MLResultInfo } from '../types.js';
3
3
  import type { Target } from '@markuplint/file-resolver';
4
4
  export declare function lint(targetList: readonly Readonly<Target>[], options?: APIOptions): Promise<MLResultInfo[]>;
package/lib/api/lint.js CHANGED
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lint = void 0;
4
- const tslib_1 = require("tslib");
5
- const file_resolver_1 = require("@markuplint/file-resolver");
6
- const ml_engine_1 = tslib_1.__importDefault(require("./ml-engine"));
7
- async function lint(targetList, options) {
1
+ import { resolveFiles } from '@markuplint/file-resolver';
2
+ import MLEngine from './ml-engine.js';
3
+ export async function lint(targetList, options) {
8
4
  const res = [];
9
- const files = await (0, file_resolver_1.resolveFiles)(targetList);
5
+ const files = await resolveFiles(targetList);
10
6
  for (const file of files) {
11
- const engine = new ml_engine_1.default(file, options);
7
+ const engine = new MLEngine(file, options);
12
8
  const result = await engine.exec();
13
9
  if (!result) {
14
10
  continue;
@@ -17,4 +13,3 @@ async function lint(targetList, options) {
17
13
  }
18
14
  return res;
19
15
  }
20
- exports.lint = lint;
@@ -1,5 +1,5 @@
1
- import type { APIOptions, MLEngineEventMap } from './types';
2
- import type { MLResultInfo } from '../types';
1
+ import type { APIOptions, MLEngineEventMap } from './types.js';
2
+ import type { MLResultInfo } from '../types.js';
3
3
  import type { MLFile, Target } from '@markuplint/file-resolver';
4
4
  import type { PlainData } from '@markuplint/ml-config';
5
5
  import type { Document, RuleConfigValue } from '@markuplint/ml-core';
@@ -8,8 +8,13 @@ type MLEngineOptions = {
8
8
  readonly debug?: boolean;
9
9
  readonly watch?: boolean;
10
10
  };
11
+ export type FromCodeOptions = APIOptions & MLEngineOptions & {
12
+ readonly name?: string;
13
+ readonly dirname?: string;
14
+ };
11
15
  export default class MLEngine extends Emitter<MLEngineEventMap> {
12
16
  #private;
17
+ static fromCode(sourceCode: string, options?: FromCodeOptions): Promise<MLEngine>;
13
18
  static toMLFile(target: Target): Promise<MLFile | undefined>;
14
19
  constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
15
20
  get document(): Document<RuleConfigValue, PlainData> | null;
@@ -1,67 +1,73 @@
1
- "use strict";
2
1
  var _MLEngine_configProvider, _MLEngine_core, _MLEngine_file, _MLEngine_options, _MLEngine_watcher;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const file_resolver_1 = require("@markuplint/file-resolver");
6
- const ml_core_1 = require("@markuplint/ml-core");
7
- const chokidar_1 = require("chokidar");
8
- const strict_event_emitter_1 = require("strict-event-emitter");
9
- const debug_1 = require("../debug");
10
- const i18n_1 = require("../i18n");
11
- const log = debug_1.log.extend('ml-engine');
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { ConfigProvider, resolveFiles, resolveParser, resolveRules, resolveSpecs } from '@markuplint/file-resolver';
4
+ import { MLCore, convertRuleset } from '@markuplint/ml-core';
5
+ import { FSWatcher } from 'chokidar';
6
+ import { Emitter } from 'strict-event-emitter';
7
+ import { log as coreLog, verbosely } from '../debug.js';
8
+ import { i18n } from '../i18n.js';
9
+ const log = coreLog.extend('ml-engine');
12
10
  const fileLog = log.extend('file');
13
11
  const configLog = log.extend('config');
14
- class MLEngine extends strict_event_emitter_1.Emitter {
12
+ class MLEngine extends Emitter {
13
+ static async fromCode(sourceCode, options) {
14
+ const file = await MLEngine.toMLFile({
15
+ sourceCode,
16
+ name: options?.name,
17
+ workspace: options?.dirname,
18
+ });
19
+ if (!file) {
20
+ throw new Error('Never reach error');
21
+ }
22
+ return new MLEngine(file, options);
23
+ }
15
24
  static async toMLFile(target) {
16
- const files = await (0, file_resolver_1.resolveFiles)([target]);
25
+ const files = await resolveFiles([target]);
17
26
  return files[0];
18
27
  }
19
28
  constructor(file, options) {
20
- var _a, _b;
21
29
  super();
22
30
  _MLEngine_configProvider.set(this, void 0);
23
31
  _MLEngine_core.set(this, null);
24
32
  _MLEngine_file.set(this, void 0);
25
33
  _MLEngine_options.set(this, void 0);
26
- _MLEngine_watcher.set(this, new chokidar_1.FSWatcher());
27
- tslib_1.__classPrivateFieldSet(this, _MLEngine_file, file, "f");
28
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, options, "f");
29
- tslib_1.__classPrivateFieldSet(this, _MLEngine_configProvider, new file_resolver_1.ConfigProvider(), "f");
30
- this.watchMode(!!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch));
31
- if ((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.debug) {
32
- (0, debug_1.verbosely)();
34
+ _MLEngine_watcher.set(this, new FSWatcher());
35
+ __classPrivateFieldSet(this, _MLEngine_file, file, "f");
36
+ __classPrivateFieldSet(this, _MLEngine_options, options, "f");
37
+ __classPrivateFieldSet(this, _MLEngine_configProvider, new ConfigProvider(), "f");
38
+ this.watchMode(!!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch);
39
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
40
+ verbosely();
33
41
  }
34
42
  }
35
43
  get document() {
36
- var _a, _b, _c;
37
- if (((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _a === void 0 ? void 0 : _a.document) instanceof Error) {
44
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")?.document instanceof Error) {
38
45
  return null;
39
46
  }
40
- return (_c = (_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _b === void 0 ? void 0 : _b.document) !== null && _c !== void 0 ? _c : null;
47
+ return __classPrivateFieldGet(this, _MLEngine_core, "f")?.document ?? null;
41
48
  }
42
49
  async close() {
43
50
  this.removeAllListeners();
44
- await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
51
+ await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
45
52
  }
46
53
  async exec() {
47
- var _a, _b;
48
54
  log('exec: start');
49
55
  const core = await this.setup();
50
56
  if (!core) {
51
57
  log('exec: cancel (unsetuped yet)');
52
58
  return null;
53
59
  }
54
- const violations = await core.verify((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.fix).catch(e => {
60
+ const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(e => {
55
61
  if (e instanceof Error) {
56
62
  return e;
57
63
  }
58
64
  throw e;
59
65
  });
60
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
66
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
61
67
  const fixedCode = core.document.toString();
62
68
  if (violations instanceof Error) {
63
- this.emit('lint-error', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
64
- const errMessage = (_b = violations.stack) !== null && _b !== void 0 ? _b : violations.message;
69
+ this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
70
+ const errMessage = violations.stack ?? violations.message;
65
71
  log('exec: error %O', errMessage);
66
72
  return {
67
73
  violations: [
@@ -74,17 +80,17 @@ class MLEngine extends strict_event_emitter_1.Emitter {
74
80
  raw: '',
75
81
  },
76
82
  ],
77
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
83
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
78
84
  sourceCode,
79
85
  fixedCode,
80
86
  };
81
87
  }
82
88
  const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
83
- this.emit('lint', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
89
+ this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
84
90
  log('exec: end');
85
91
  return {
86
92
  violations,
87
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
93
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
88
94
  sourceCode,
89
95
  fixedCode,
90
96
  };
@@ -94,47 +100,44 @@ class MLEngine extends strict_event_emitter_1.Emitter {
94
100
  if (!core) {
95
101
  return;
96
102
  }
97
- tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
103
+ __classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
98
104
  core.setCode(code);
99
105
  }
100
106
  watchMode(enable) {
101
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
102
- ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
107
+ __classPrivateFieldSet(this, _MLEngine_options, {
108
+ ...__classPrivateFieldGet(this, _MLEngine_options, "f"),
103
109
  watch: enable,
104
110
  }, "f");
105
111
  if (enable) {
106
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
112
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
107
113
  }
108
114
  else {
109
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
115
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
110
116
  }
111
117
  }
112
118
  async createCore(fabric) {
113
- var _a;
114
119
  fileLog('Get source code');
115
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
116
- fileLog('Source code path: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
120
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
121
+ fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
117
122
  // cspell: disable-next-line
118
123
  fileLog('Source code size: %dbyte', sourceCode.length);
119
- this.emit('code', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
120
- const core = new ml_core_1.MLCore({
124
+ this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
125
+ const core = new MLCore({
121
126
  sourceCode,
122
- filename: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
123
- debug: (_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.debug,
127
+ filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
128
+ debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
124
129
  ...fabric,
125
130
  });
126
- tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
131
+ __classPrivateFieldSet(this, _MLEngine_core, core, "f");
127
132
  return core;
128
133
  }
129
134
  async i18n() {
130
- var _a;
131
- const i18nSettings = await (0, i18n_1.i18n)((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.locale);
132
- this.emit('i18n', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
135
+ const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
136
+ this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
133
137
  return i18nSettings;
134
138
  }
135
139
  async onChange(filePath) {
136
- var _a, _b;
137
- if (!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch)) {
140
+ if (!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
138
141
  return;
139
142
  }
140
143
  this.emit('log', 'watch:onChange', filePath);
@@ -143,14 +146,13 @@ class MLEngine extends strict_event_emitter_1.Emitter {
143
146
  return;
144
147
  }
145
148
  if (fabric.configErrors) {
146
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
149
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
147
150
  }
148
- this.emit('log', 'update:core', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
149
- (_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _b === void 0 ? void 0 : _b.update(fabric);
151
+ this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
152
+ __classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
150
153
  await this.exec();
151
154
  }
152
155
  async provide(cache = true) {
153
- var _a, _b, _c, _d;
154
156
  let configSet;
155
157
  try {
156
158
  configSet = await this.resolveConfig(cache);
@@ -172,22 +174,22 @@ class MLEngine extends strict_event_emitter_1.Emitter {
172
174
  fileLog('Resolved Config: %O', configSet.config);
173
175
  fileLog('Resolved Plugins: %O', configSet.plugins);
174
176
  fileLog('Resolve Errors: %O', configSet.errs);
175
- if (!(await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
176
- this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
177
- fileLog("The file doesn't exist or it is not a file: %s", tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
177
+ if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
178
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
179
+ fileLog("The file doesn't exist or it is not a file: %s", __classPrivateFieldGet(this, _MLEngine_file, "f").path);
178
180
  return null;
179
181
  }
180
182
  // Exclude
181
- const excludeFiles = (_a = configSet.config.excludeFiles) !== null && _a !== void 0 ? _a : [];
182
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
183
- fileLog('Excludes the file: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
183
+ const excludeFiles = configSet.config.excludeFiles ?? [];
184
+ if (__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
185
+ fileLog('Excludes the file: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
184
186
  return null;
185
187
  }
186
188
  const { parser, parserOptions, matched } = await this.resolveParser(configSet);
187
- const checkingExt = !((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.ignoreExt);
189
+ const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
188
190
  if (checkingExt && !matched) {
189
- this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
190
- fileLog('Avoided linting because a file is unmatched by the extension: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
191
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
192
+ fileLog('Avoided linting because a file is unmatched by the extension: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
191
193
  return null;
192
194
  }
193
195
  const ruleset = this.resolveRuleset(configSet);
@@ -207,14 +209,14 @@ class MLEngine extends strict_event_emitter_1.Emitter {
207
209
  }
208
210
  const rules = await this.resolveRules(configSet.plugins, ruleset);
209
211
  fileLog('Resolved rules: %O', rules);
210
- const locale = await (0, i18n_1.i18n)((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.locale);
212
+ const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
211
213
  if (fileLog.enabled) {
212
214
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
213
215
  }
214
216
  return {
215
217
  parser,
216
218
  parserOptions,
217
- pretenders: (_d = configSet.config.pretenders) !== null && _d !== void 0 ? _d : [],
219
+ pretenders: configSet.config.pretenders ?? [],
218
220
  ruleset,
219
221
  schemas,
220
222
  rules,
@@ -223,78 +225,76 @@ class MLEngine extends strict_event_emitter_1.Emitter {
223
225
  };
224
226
  }
225
227
  async resolveConfig(cache) {
226
- var _a, _b, _c, _d, _e, _f, _g;
227
- const defaultConfigKey = ((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.defaultConfig) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.defaultConfig);
228
- configLog('defaultConfigKey: %s', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
229
- this.emit('log', 'defaultConfigKey', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
230
- const configFilePathsFromTarget = ((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.noSearchConfig)
231
- ? defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : null
232
- : (_d = (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f")))) !== null && _d !== void 0 ? _d : defaultConfigKey;
233
- configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
234
- this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
235
- const configKey = ((_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.config) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").config);
236
- configLog('option.config: %s', configKey !== null && configKey !== void 0 ? configKey : 'N/A');
237
- this.emit('log', 'option.config', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
228
+ const defaultConfigKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig);
229
+ configLog('defaultConfigKey: %s', defaultConfigKey ?? 'N/A');
230
+ this.emit('log', 'defaultConfigKey', defaultConfigKey ?? 'N/A');
231
+ const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
232
+ ? defaultConfigKey ?? null
233
+ : (await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(__classPrivateFieldGet(this, _MLEngine_file, "f"))) ?? defaultConfigKey;
234
+ configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget ?? 'N/A');
235
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget ?? 'N/A');
236
+ const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
237
+ configLog('option.config: %s', configKey ?? 'N/A');
238
+ this.emit('log', 'option.config', configFilePathsFromTarget ?? 'N/A');
238
239
  let defaultRecommended = null;
239
240
  if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
240
241
  // No configured
241
242
  // Default: set recommended
242
- defaultRecommended = tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
243
+ defaultRecommended = __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
243
244
  }
244
- configLog('defaultRecommended: %s', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
245
- this.emit('log', 'defaultRecommended', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
246
- const configSet = await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, (_f = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _f === void 0 ? void 0 : _f.configFile, configKey, defaultRecommended], cache);
247
- this.emit('config', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
248
- if ((_g = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _g === void 0 ? void 0 : _g.watch) {
245
+ configLog('defaultRecommended: %s', defaultRecommended ?? 'N/A');
246
+ this.emit('log', 'defaultRecommended', defaultRecommended ?? 'N/A');
247
+ const configSet = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey, defaultRecommended], cache);
248
+ this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
249
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
249
250
  // It doesn't watch the main HTML file because it may is watched and managed by a language server or text editor or more.
250
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
251
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
251
252
  }
252
253
  return configSet;
253
254
  }
254
255
  async resolveParser(
255
256
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
256
257
  configSet) {
257
- const parser = await (0, file_resolver_1.resolveParser)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
258
- this.emit('parser', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
258
+ const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
259
+ this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
259
260
  fileLog('Fetched Parser module: %s', parser.parserModName);
260
261
  return parser;
261
262
  }
262
263
  async resolveRules(plugins, ruleset) {
263
- var _a, _b, _c, _d, _e;
264
- const rules = await (0, file_resolver_1.resolveRules)(plugins, ruleset, (_b = (_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.importPresetRules) !== null && _b !== void 0 ? _b : true, (_d = (_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.autoLoad) !== null && _d !== void 0 ? _d : true);
265
- if ((_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.rules) {
266
- rules.push(...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
264
+ const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
265
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
266
+ rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
267
267
  }
268
- this.emit('rules', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
268
+ this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
269
269
  return rules;
270
270
  }
271
271
  resolveRuleset(
272
272
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
273
273
  configSet) {
274
- const ruleset = (0, ml_core_1.convertRuleset)(configSet.config);
275
- this.emit('ruleset', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
274
+ const ruleset = convertRuleset(configSet.config);
275
+ this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
276
276
  return ruleset;
277
277
  }
278
278
  async resolveSchemas(
279
279
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
280
280
  configSet) {
281
- const { schemas } = await (0, file_resolver_1.resolveSpecs)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
282
- this.emit('schemas', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
281
+ const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
282
+ this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
283
283
  return schemas;
284
284
  }
285
285
  async setup() {
286
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
287
- return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
286
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
287
+ return __classPrivateFieldGet(this, _MLEngine_core, "f");
288
288
  }
289
289
  const fabric = await this.provide();
290
290
  if (!fabric) {
291
291
  return null;
292
292
  }
293
293
  if (fabric.configErrors) {
294
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
294
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
295
295
  }
296
296
  return this.createCore(fabric);
297
297
  }
298
298
  }
299
299
  _MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
300
- exports.default = MLEngine;
300
+ export default MLEngine;
package/lib/api/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/api/v1.d.ts CHANGED
@@ -48,4 +48,4 @@ export declare function lint_v1(options: {
48
48
  * Locale
49
49
  */
50
50
  readonly locale?: string;
51
- }): Promise<import("..").MLResultInfo[]>;
51
+ }): Promise<import("../types.js").MLResultInfo[]>;
package/lib/api/v1.js CHANGED
@@ -1,27 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lint_v1 = void 0;
4
- const shared_1 = require("@markuplint/shared");
5
- const lint_1 = require("./lint");
1
+ import { toNoEmptyStringArrayFromStringOrArray } from '@markuplint/shared';
2
+ import { lint } from './lint.js';
6
3
  /**
7
4
  * @deprecated
8
5
  * @param options
9
6
  * @returns
10
7
  */
11
- async function lint_v1(options) {
12
- var _a;
13
- const filePathList = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.files);
14
- const codes = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.sourceCodes);
8
+ export async function lint_v1(options) {
9
+ const filePathList = toNoEmptyStringArrayFromStringOrArray(options.files);
10
+ const codes = toNoEmptyStringArrayFromStringOrArray(options.sourceCodes);
15
11
  const files = [
16
12
  ...filePathList,
17
- ...codes.map((code, i) => {
18
- var _a, _b;
19
- return ({
20
- sourceCode: code,
21
- name: Array.isArray(options.names) ? (_a = options.names) === null || _a === void 0 ? void 0 : _a[i] : options.names,
22
- workspace: (_b = options.workspace) === null || _b === void 0 ? void 0 : _b[i],
23
- });
24
- }),
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
+ })),
25
18
  ];
26
19
  let config;
27
20
  let configFile;
@@ -31,14 +24,13 @@ async function lint_v1(options) {
31
24
  else if (options.config) {
32
25
  config = options.config;
33
26
  }
34
- const result = await (0, lint_1.lint)(files, {
27
+ const result = await lint(files, {
35
28
  config,
36
29
  configFile,
37
30
  noSearchConfig: filePathList.length === 0,
38
31
  rules: options.rules,
39
- autoLoad: (_a = options.rulesAutoResolve) !== null && _a !== void 0 ? _a : true,
32
+ autoLoad: options.rulesAutoResolve ?? true,
40
33
  locale: options.locale,
41
34
  });
42
35
  return result;
43
36
  }
44
- exports.lint_v1 = lint_v1;
@@ -1,10 +1,9 @@
1
1
  import type { ReadonlyDeep } from 'type-fest';
2
- import meow from 'meow';
3
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";
4
- export declare const cli: meow.Result<{
3
+ export declare const cli: import("meow").Result<{
5
4
  config: {
6
5
  type: "string";
7
- alias: string;
6
+ shortFlag: string;
8
7
  };
9
8
  fix: {
10
9
  type: "boolean";
@@ -12,7 +11,7 @@ export declare const cli: meow.Result<{
12
11
  };
13
12
  format: {
14
13
  type: "string";
15
- alias: string;
14
+ shortFlag: string;
16
15
  };
17
16
  searchConfig: {
18
17
  type: "boolean";
@@ -35,7 +34,7 @@ export declare const cli: meow.Result<{
35
34
  };
36
35
  problemOnly: {
37
36
  type: "boolean";
38
- alias: string;
37
+ shortFlag: string;
39
38
  default: false;
40
39
  };
41
40
  allowWarnings: {
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
@@ -33,11 +29,12 @@ Examples
33
29
  $ markuplint verifyee.html --config path/to/.markuplintrc
34
30
  $ cat verifyee.html | markuplint
35
31
  `;
36
- exports.cli = (0, meow_1.default)(exports.help, {
32
+ export const cli = meow(help, {
33
+ importMeta: import.meta,
37
34
  flags: {
38
35
  config: {
39
36
  type: 'string',
40
- alias: 'c',
37
+ shortFlag: 'c',
41
38
  },
42
39
  fix: {
43
40
  type: 'boolean',
@@ -45,7 +42,7 @@ exports.cli = (0, meow_1.default)(exports.help, {
45
42
  },
46
43
  format: {
47
44
  type: 'string',
48
- alias: 'f',
45
+ shortFlag: 'f',
49
46
  },
50
47
  searchConfig: {
51
48
  type: 'boolean',
@@ -68,7 +65,7 @@ exports.cli = (0, meow_1.default)(exports.help, {
68
65
  },
69
66
  problemOnly: {
70
67
  type: 'boolean',
71
- alias: 'p',
68
+ shortFlag: 'p',
72
69
  default: false,
73
70
  },
74
71
  allowWarnings: {
@@ -1,4 +1,4 @@
1
- import type { CLIOptions } from './bootstrap';
2
- import type { APIOptions } from '../api/types';
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
4
  export declare function command(files: readonly Readonly<Target>[], options: CLIOptions, apiOptions?: APIOptions): Promise<boolean>;