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.
Files changed (65) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -2
  3. package/bin/markuplint.mjs +3 -0
  4. package/lib/api/index.d.ts +2 -2
  5. package/lib/api/index.js +2 -10
  6. package/lib/api/lint.d.ts +2 -2
  7. package/lib/api/lint.js +5 -10
  8. package/lib/api/ml-engine.d.ts +28 -23
  9. package/lib/api/ml-engine.js +123 -103
  10. package/lib/api/types.d.ts +32 -32
  11. package/lib/api/types.js +1 -2
  12. package/lib/api/v1.d.ts +43 -43
  13. package/lib/api/v1.js +12 -20
  14. package/lib/cli/bootstrap.d.ts +65 -63
  15. package/lib/cli/bootstrap.js +12 -11
  16. package/lib/cli/command.d.ts +3 -7
  17. package/lib/cli/command.js +26 -34
  18. package/lib/cli/index.js +59 -71
  19. package/lib/cli/init/create-config.d.ts +2 -6
  20. package/lib/cli/init/create-config.js +14 -12
  21. package/lib/cli/init/get-default-rules.d.ts +3 -3
  22. package/lib/cli/init/get-default-rules.js +12 -53
  23. package/lib/cli/init/index.js +28 -37
  24. package/lib/cli/init/select-modules.d.ts +2 -0
  25. package/lib/cli/init/select-modules.js +10 -0
  26. package/lib/cli/init/types.d.ts +4 -15
  27. package/lib/cli/init/types.js +1 -2
  28. package/lib/cli/output.d.ts +2 -2
  29. package/lib/cli/output.js +8 -14
  30. package/lib/cli/search/index.d.ts +2 -2
  31. package/lib/cli/search/index.js +10 -14
  32. package/lib/debug.js +9 -13
  33. package/lib/get-json-module.d.ts +1 -0
  34. package/lib/get-json-module.js +10 -0
  35. package/lib/global-settings.d.ts +1 -1
  36. package/lib/global-settings.js +2 -7
  37. package/lib/i18n.js +8 -15
  38. package/lib/index.d.ts +7 -5
  39. package/lib/index.js +6 -10
  40. package/lib/reporter/github-reporter.d.ts +1 -1
  41. package/lib/reporter/github-reporter.js +7 -9
  42. package/lib/reporter/index.d.ts +3 -3
  43. package/lib/reporter/index.js +3 -6
  44. package/lib/reporter/simple-reporter.d.ts +2 -2
  45. package/lib/reporter/simple-reporter.js +11 -16
  46. package/lib/reporter/standard-reporter.d.ts +2 -2
  47. package/lib/reporter/standard-reporter.js +37 -28
  48. package/lib/testing-tool/index.d.ts +23 -41
  49. package/lib/testing-tool/index.js +41 -47
  50. package/lib/types.d.ts +17 -17
  51. package/lib/types.js +1 -2
  52. package/lib/v1.d.ts +1 -1
  53. package/lib/v1.js +1 -5
  54. package/lib/version.d.ts +1 -0
  55. package/lib/version.js +3 -0
  56. package/package.json +26 -34
  57. package/bin/markuplint +0 -3
  58. package/lib/cli/create-rule/index.d.ts +0 -1
  59. package/lib/cli/create-rule/index.js +0 -85
  60. package/lib/cli/init/install-module.d.ts +0 -7
  61. package/lib/cli/init/install-module.js +0 -80
  62. package/lib/cli/prompt.d.ts +0 -23
  63. package/lib/cli/prompt.js +0 -77
  64. package/lib/util.d.ts +0 -17
  65. package/lib/util.js +0 -88
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
  $ npx markuplint target.html
26
26
  ```
27
27
 
28
- Supported for _Node.js_ `v14.6.0` or later.
28
+ Supported for _Node.js_ `v18.18.0` or later.
29
29
 
30
30
  ## Usage
31
31
 
@@ -83,9 +83,9 @@ Options
83
83
  --no-color, Output no color.
84
84
  --problem-only, -p Output only problems, without passeds.
85
85
  --verbose Output with detailed information.
86
+ --include-node-modules Include files in node_modules directory. Default: false.
86
87
 
87
88
  --init Initialize settings interactively.
88
- --create-rule Add the scaffold of a custom rule.
89
89
 
90
90
  --help, -h Show help.
91
91
  --version, -v Show version.
@@ -125,6 +125,8 @@ Need [Sponsors❤️‍🔥](https://github.com/sponsors/markuplint)
125
125
  [<img width="36" src="https://avatars.githubusercontent.com/u/6581173" alt="miita" />](https://github.com/mikimhk)
126
126
  [<img width="36" src="https://avatars.githubusercontent.com/u/111797" alt="Yasuo Fukuda" />](https://github.com/sigwyg)
127
127
  [<img width="36" src="https://avatars.githubusercontent.com/u/802921" alt="Hideyuki Saito" />](https://github.com/hideyukisaito)
128
+ [<img width="36" src="https://avatars.githubusercontent.com/u/3056064" alt="tamshow" />](https://github.com/tamshow)
129
+ [<img width="36" src="https://avatars.githubusercontent.com/u/91047157" alt="shamokit" />](https://github.com/shamokit)
128
130
 
129
131
  ## Thanks
130
132
 
@@ -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 { 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 { 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,31 +1,36 @@
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';
6
6
  import { Emitter } from 'strict-event-emitter';
7
7
  type MLEngineOptions = {
8
- readonly debug?: boolean;
9
- readonly watch?: boolean;
8
+ readonly debug?: boolean;
9
+ readonly watch?: boolean;
10
10
  };
11
- export default class MLEngine extends Emitter<MLEngineEventMap> {
12
- #private;
13
- static toMLFile(target: Target): Promise<MLFile | undefined>;
14
- constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
15
- get document(): Document<RuleConfigValue, PlainData> | null;
16
- close(): Promise<void>;
17
- exec(): Promise<MLResultInfo | null>;
18
- setCode(code: string): Promise<void>;
19
- watchMode(enable: boolean): void;
20
- private createCore;
21
- private i18n;
22
- private onChange;
23
- private provide;
24
- private resolveConfig;
25
- private resolveParser;
26
- private resolveRules;
27
- private resolveRuleset;
28
- private resolveSchemas;
29
- private setup;
11
+ export type FromCodeOptions = APIOptions & MLEngineOptions & {
12
+ readonly name?: string;
13
+ readonly dirname?: string;
14
+ };
15
+ export declare class MLEngine extends Emitter<MLEngineEventMap> {
16
+ #private;
17
+ static fromCode(sourceCode: string, options?: FromCodeOptions): Promise<MLEngine>;
18
+ static toMLFile(target: Target): Promise<MLFile | undefined>;
19
+ constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
20
+ get document(): Document<RuleConfigValue, PlainData> | null;
21
+ close(): Promise<void>;
22
+ exec(): Promise<MLResultInfo | null>;
23
+ setCode(code: string): Promise<void>;
24
+ watchMode(enable: boolean): void;
25
+ private createCore;
26
+ private i18n;
27
+ private onChange;
28
+ private provide;
29
+ private resolveConfig;
30
+ private resolveParser;
31
+ private resolveRules;
32
+ private resolveRuleset;
33
+ private resolveSchemas;
34
+ private setup;
30
35
  }
31
36
  export {};
@@ -1,67 +1,90 @@
1
- "use strict";
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
2
12
  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');
13
+ import { ConfigProvider, resolveFiles, resolveParser, resolveRules, resolveSpecs } from '@markuplint/file-resolver';
14
+ import { MLCore, convertRuleset } from '@markuplint/ml-core';
15
+ import { FSWatcher } from 'chokidar';
16
+ import { Emitter } from 'strict-event-emitter';
17
+ import { log as coreLog, verbosely } from '../debug.js';
18
+ import { i18n } from '../i18n.js';
19
+ const log = coreLog.extend('ml-engine');
12
20
  const fileLog = log.extend('file');
13
21
  const configLog = log.extend('config');
14
- class MLEngine extends strict_event_emitter_1.Emitter {
22
+ export class MLEngine extends Emitter {
23
+ static async fromCode(sourceCode, options) {
24
+ if (options?.debug) {
25
+ verbosely();
26
+ }
27
+ log('[fromCode] Creates: %O', options);
28
+ const file = await MLEngine.toMLFile({
29
+ sourceCode,
30
+ name: options?.name,
31
+ workspace: options?.dirname,
32
+ });
33
+ if (!file) {
34
+ throw new Error('Never reach error');
35
+ }
36
+ log('[fromCode] Created file: %s', file.path);
37
+ const engine = new MLEngine(file, options);
38
+ return engine;
39
+ }
15
40
  static async toMLFile(target) {
16
- const files = await (0, file_resolver_1.resolveFiles)([target]);
41
+ const files = await resolveFiles([target]);
17
42
  return files[0];
18
43
  }
19
44
  constructor(file, options) {
20
- var _a, _b;
21
45
  super();
22
46
  _MLEngine_configProvider.set(this, void 0);
23
47
  _MLEngine_core.set(this, null);
24
48
  _MLEngine_file.set(this, void 0);
25
49
  _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)();
50
+ _MLEngine_watcher.set(this, new FSWatcher());
51
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
52
+ verbosely();
33
53
  }
54
+ __classPrivateFieldSet(this, _MLEngine_file, file, "f");
55
+ __classPrivateFieldSet(this, _MLEngine_options, options, "f");
56
+ __classPrivateFieldSet(this, _MLEngine_configProvider, new ConfigProvider(), "f");
57
+ this.watchMode(!!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch);
58
+ log('[MLEngine] Initialized: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
34
59
  }
35
60
  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) {
61
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")?.document instanceof Error) {
38
62
  return null;
39
63
  }
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;
64
+ return __classPrivateFieldGet(this, _MLEngine_core, "f")?.document ?? null;
41
65
  }
42
66
  async close() {
43
67
  this.removeAllListeners();
44
- await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
68
+ await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
45
69
  }
46
70
  async exec() {
47
- var _a, _b;
48
71
  log('exec: start');
49
72
  const core = await this.setup();
50
73
  if (!core) {
51
74
  log('exec: cancel (unsetuped yet)');
52
75
  return null;
53
76
  }
54
- const violations = await core.verify((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.fix).catch(e => {
55
- if (e instanceof Error) {
56
- return e;
77
+ const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(error => {
78
+ if (error instanceof Error) {
79
+ return error;
57
80
  }
58
- throw e;
81
+ throw error;
59
82
  });
60
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
61
- const fixedCode = core.document.toString();
83
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
84
+ const fixedCode = core.document.toString(true);
62
85
  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;
86
+ this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
87
+ const errMessage = violations.stack ?? violations.message;
65
88
  log('exec: error %O', errMessage);
66
89
  return {
67
90
  violations: [
@@ -74,17 +97,17 @@ class MLEngine extends strict_event_emitter_1.Emitter {
74
97
  raw: '',
75
98
  },
76
99
  ],
77
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
100
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
78
101
  sourceCode,
79
102
  fixedCode,
80
103
  };
81
104
  }
82
105
  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);
106
+ this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
84
107
  log('exec: end');
85
108
  return {
86
109
  violations,
87
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
110
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
88
111
  sourceCode,
89
112
  fixedCode,
90
113
  };
@@ -94,47 +117,44 @@ class MLEngine extends strict_event_emitter_1.Emitter {
94
117
  if (!core) {
95
118
  return;
96
119
  }
97
- tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
120
+ __classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
98
121
  core.setCode(code);
99
122
  }
100
123
  watchMode(enable) {
101
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
102
- ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
124
+ __classPrivateFieldSet(this, _MLEngine_options, {
125
+ ...__classPrivateFieldGet(this, _MLEngine_options, "f"),
103
126
  watch: enable,
104
127
  }, "f");
105
128
  if (enable) {
106
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
129
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
107
130
  }
108
131
  else {
109
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
132
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
110
133
  }
111
134
  }
112
135
  async createCore(fabric) {
113
- var _a;
114
136
  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);
137
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
138
+ fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
117
139
  // cspell: disable-next-line
118
140
  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({
141
+ this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
142
+ const core = new MLCore({
121
143
  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,
144
+ filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
145
+ debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
124
146
  ...fabric,
125
147
  });
126
- tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
148
+ __classPrivateFieldSet(this, _MLEngine_core, core, "f");
127
149
  return core;
128
150
  }
129
151
  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);
152
+ const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
153
+ this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
133
154
  return i18nSettings;
134
155
  }
135
156
  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)) {
157
+ if (!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
138
158
  return;
139
159
  }
140
160
  this.emit('log', 'watch:onChange', filePath);
@@ -143,14 +163,13 @@ class MLEngine extends strict_event_emitter_1.Emitter {
143
163
  return;
144
164
  }
145
165
  if (fabric.configErrors) {
146
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
166
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
147
167
  }
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);
168
+ this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
169
+ __classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
150
170
  await this.exec();
151
171
  }
152
172
  async provide(cache = true) {
153
- var _a, _b, _c, _d;
154
173
  let configSet;
155
174
  try {
156
175
  configSet = await this.resolveConfig(cache);
@@ -172,22 +191,22 @@ class MLEngine extends strict_event_emitter_1.Emitter {
172
191
  fileLog('Resolved Config: %O', configSet.config);
173
192
  fileLog('Resolved Plugins: %O', configSet.plugins);
174
193
  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);
194
+ if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
195
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
196
+ fileLog("The file doesn't exist or it is not a file: %s", __classPrivateFieldGet(this, _MLEngine_file, "f").path);
178
197
  return null;
179
198
  }
180
199
  // 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);
200
+ const excludeFiles = configSet.config.excludeFiles ?? [];
201
+ if (__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
202
+ fileLog('Excludes the file: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
184
203
  return null;
185
204
  }
186
205
  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);
206
+ const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
188
207
  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);
208
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
209
+ fileLog('Avoided linting because a file is unmatched by the extension: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
191
210
  return null;
192
211
  }
193
212
  const ruleset = this.resolveRuleset(configSet);
@@ -207,14 +226,14 @@ class MLEngine extends strict_event_emitter_1.Emitter {
207
226
  }
208
227
  const rules = await this.resolveRules(configSet.plugins, ruleset);
209
228
  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);
229
+ const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
211
230
  if (fileLog.enabled) {
212
231
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
213
232
  }
214
233
  return {
215
234
  parser,
216
235
  parserOptions,
217
- pretenders: (_d = configSet.config.pretenders) !== null && _d !== void 0 ? _d : [],
236
+ pretenders: configSet.config.pretenders ?? [],
218
237
  ruleset,
219
238
  schemas,
220
239
  rules,
@@ -223,78 +242,79 @@ class MLEngine extends strict_event_emitter_1.Emitter {
223
242
  };
224
243
  }
225
244
  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');
245
+ this.emit('log', 'resolveConfig', JSON.stringify(__classPrivateFieldGet(this, _MLEngine_configProvider, "f"), null, 2));
246
+ configLog('configProvider: %s', __classPrivateFieldGet(this, _MLEngine_configProvider, "f"));
247
+ const defaultConfigKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig);
248
+ configLog('defaultConfigKey: %s', defaultConfigKey ?? 'N/A');
249
+ this.emit('log', 'defaultConfigKey', defaultConfigKey ?? 'N/A');
250
+ const targetConfig = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(__classPrivateFieldGet(this, _MLEngine_file, "f"));
251
+ this.emit('log', 'targetConfig', targetConfig ?? 'N/A');
252
+ const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
253
+ ? defaultConfigKey ?? null
254
+ : targetConfig ?? defaultConfigKey;
255
+ configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget ?? 'N/A');
256
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget ?? 'N/A');
257
+ const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
258
+ configLog('option.config: %s', configKey ?? 'N/A');
259
+ this.emit('log', 'option.config', configFilePathsFromTarget ?? 'N/A');
238
260
  let defaultRecommended = null;
239
261
  if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
240
262
  // No configured
241
263
  // Default: set recommended
242
- defaultRecommended = tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
264
+ defaultRecommended = __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
243
265
  }
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) {
266
+ configLog('defaultRecommended: %s', defaultRecommended ?? 'N/A');
267
+ this.emit('log', 'defaultRecommended', defaultRecommended ?? 'N/A');
268
+ const configSet = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey, defaultRecommended], cache);
269
+ this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
270
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
249
271
  // 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));
272
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").add([...configSet.files]);
251
273
  }
252
274
  return configSet;
253
275
  }
254
276
  async resolveParser(
255
277
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
256
278
  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);
279
+ const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
280
+ this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
259
281
  fileLog('Fetched Parser module: %s', parser.parserModName);
260
282
  return parser;
261
283
  }
262
284
  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);
285
+ const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
286
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
287
+ rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
267
288
  }
268
- this.emit('rules', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
289
+ this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
269
290
  return rules;
270
291
  }
271
292
  resolveRuleset(
272
293
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
273
294
  configSet) {
274
- const ruleset = (0, ml_core_1.convertRuleset)(configSet.config);
275
- this.emit('ruleset', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
295
+ const ruleset = convertRuleset(configSet.config);
296
+ this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
276
297
  return ruleset;
277
298
  }
278
299
  async resolveSchemas(
279
300
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
280
301
  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);
302
+ const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
303
+ this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
283
304
  return schemas;
284
305
  }
285
306
  async setup() {
286
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
287
- return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
307
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
308
+ return __classPrivateFieldGet(this, _MLEngine_core, "f");
288
309
  }
289
310
  const fabric = await this.provide();
290
311
  if (!fabric) {
291
312
  return null;
292
313
  }
293
314
  if (fabric.configErrors) {
294
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
315
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
295
316
  }
296
317
  return this.createCore(fabric);
297
318
  }
298
319
  }
299
320
  _MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
300
- exports.default = MLEngine;
@@ -3,38 +3,38 @@ import type { LocaleSet } from '@markuplint/i18n';
3
3
  import type { Config, Violation } from '@markuplint/ml-config';
4
4
  import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
5
5
  export type APIOptions = {
6
- readonly configFile?: string;
7
- readonly config?: Config;
8
- readonly defaultConfig?: Config;
9
- readonly noSearchConfig?: boolean;
10
- readonly locale?: string;
11
- readonly fix?: boolean;
12
- readonly ignoreExt?: boolean;
13
- readonly rules?: readonly Readonly<AnyMLRule>[];
14
- readonly importPresetRules?: boolean;
15
- /**
16
- * @deprecated
17
- */
18
- readonly autoLoad?: boolean;
6
+ readonly configFile?: string;
7
+ readonly config?: Config;
8
+ readonly defaultConfig?: Config;
9
+ readonly noSearchConfig?: boolean;
10
+ readonly locale?: string;
11
+ readonly fix?: boolean;
12
+ readonly ignoreExt?: boolean;
13
+ readonly rules?: readonly Readonly<AnyMLRule>[];
14
+ readonly importPresetRules?: boolean;
15
+ /**
16
+ * @deprecated
17
+ */
18
+ readonly autoLoad?: boolean;
19
19
  };
20
20
  export type MLEngineEventMap = {
21
- log: [phase: string, message: string];
22
- config: [filePath: string, config: ConfigSet, message?: string];
23
- exclude: [filePath: string, setting: string, message?: string];
24
- parser: [filePath: string, parser: string, message?: string];
25
- ruleset: [filePath: string, ruleset: Ruleset, message?: string];
26
- schemas: [filePath: string, schemas: MLSchema, message?: string];
27
- rules: [filePath: string, rules: readonly Readonly<AnyMLRule>[], message?: string];
28
- i18n: [filePath: string, locale: LocaleSet, message?: string];
29
- code: [filePath: string, sourceCode: string, message?: string];
30
- lint: [
31
- filePath: string,
32
- sourceCode: string,
33
- violations: readonly Violation[],
34
- fixedCode: string,
35
- debug: readonly string[] | null,
36
- message?: string,
37
- ];
38
- 'lint-error': [filePath: string, sourceCode: string, error: Readonly<Error>];
39
- 'config-errors': [filePath: string, errors: readonly Readonly<Error>[]];
21
+ log: [phase: string, message: string];
22
+ config: [filePath: string, config: ConfigSet, message?: string];
23
+ exclude: [filePath: string, setting: string, message?: string];
24
+ parser: [filePath: string, parser: string, message?: string];
25
+ ruleset: [filePath: string, ruleset: Ruleset, message?: string];
26
+ schemas: [filePath: string, schemas: MLSchema, message?: string];
27
+ rules: [filePath: string, rules: readonly Readonly<AnyMLRule>[], message?: string];
28
+ i18n: [filePath: string, locale: LocaleSet, message?: string];
29
+ code: [filePath: string, sourceCode: string, message?: string];
30
+ lint: [
31
+ filePath: string,
32
+ sourceCode: string,
33
+ violations: readonly Violation[],
34
+ fixedCode: string,
35
+ debug: readonly string[] | null,
36
+ message?: string
37
+ ];
38
+ 'lint-error': [filePath: string, sourceCode: string, error: Readonly<Error>];
39
+ 'config-errors': [filePath: string, errors: readonly Readonly<Error>[]];
40
40
  };