markuplint 3.0.0-dev.25 → 3.0.0-dev.290

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/README.md +10 -6
  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 +3 -3
  6. package/lib/api/lint.js +5 -10
  7. package/lib/api/ml-engine.d.ts +15 -9
  8. package/lib/api/ml-engine.js +136 -102
  9. package/lib/api/types.d.ts +30 -34
  10. package/lib/api/types.js +1 -2
  11. package/lib/api/v1.d.ts +12 -12
  12. package/lib/api/v1.js +13 -24
  13. package/lib/cli/bootstrap.d.ts +15 -7
  14. package/lib/cli/bootstrap.js +19 -11
  15. package/lib/cli/command.d.ts +3 -3
  16. package/lib/cli/command.js +27 -26
  17. package/lib/cli/create-rule/index.js +56 -42
  18. package/lib/cli/index.js +27 -31
  19. package/lib/cli/init/create-config.d.ts +4 -0
  20. package/lib/cli/init/create-config.js +90 -0
  21. package/lib/cli/init/get-default-rules.d.ts +3 -0
  22. package/lib/cli/init/get-default-rules.js +52 -0
  23. package/lib/cli/init/index.js +43 -231
  24. package/lib/cli/init/install-module.d.ts +3 -1
  25. package/lib/cli/init/install-module.js +22 -17
  26. package/lib/cli/init/types.d.ts +8 -0
  27. package/lib/cli/init/types.js +1 -0
  28. package/lib/cli/output.d.ts +2 -2
  29. package/lib/cli/output.js +13 -15
  30. package/lib/cli/prompt.d.ts +9 -9
  31. package/lib/cli/prompt.js +15 -25
  32. package/lib/cli/search/index.d.ts +2 -2
  33. package/lib/cli/search/index.js +7 -10
  34. package/lib/debug.js +8 -13
  35. package/lib/get-json-module.d.ts +1 -0
  36. package/lib/get-json-module.js +10 -0
  37. package/lib/global-settings.d.ts +1 -1
  38. package/lib/global-settings.js +2 -7
  39. package/lib/i18n.js +9 -15
  40. package/lib/index.d.ts +6 -5
  41. package/lib/index.js +6 -10
  42. package/lib/reporter/github-reporter.d.ts +2 -0
  43. package/lib/reporter/github-reporter.js +19 -0
  44. package/lib/reporter/index.d.ts +3 -2
  45. package/lib/reporter/index.js +3 -5
  46. package/lib/reporter/simple-reporter.d.ts +2 -2
  47. package/lib/reporter/simple-reporter.js +12 -17
  48. package/lib/reporter/standard-reporter.d.ts +2 -2
  49. package/lib/reporter/standard-reporter.js +18 -23
  50. package/lib/testing-tool/index.d.ts +10 -10
  51. package/lib/testing-tool/index.js +17 -25
  52. package/lib/types.d.ts +6 -7
  53. package/lib/types.js +1 -2
  54. package/lib/util.d.ts +0 -2
  55. package/lib/util.js +21 -37
  56. package/lib/v1.d.ts +1 -1
  57. package/lib/v1.js +1 -5
  58. package/lib/version.d.ts +1 -0
  59. package/lib/version.js +3 -0
  60. package/package.json +43 -31
  61. package/bin/markuplint +0 -3
  62. package/media/screenshot01.png +0 -0
  63. package/test/plugin001.js +0 -24
  64. package/tsconfig.test.json +0 -3
  65. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![GitHub Stars](https://img.shields.io/github/stars/markuplint.svg)](https://github.com/markuplint/markuplint)
8
8
  [![Follow us on Twitter](https://img.shields.io/twitter/follow/markuplint?label=Follow)](https://twitter.com/intent/user?screen_name=markuplint)
9
9
 
10
- **Peace of mind in your markup** - A linter for all markup developers.
10
+ **Peace of mind in your markup** - An HTML linter for all markup developers.
11
11
 
12
12
  ## Features
13
13
 
@@ -47,7 +47,7 @@ Add a command to the `scripts` option on `package.json`:
47
47
  ```json
48
48
  {
49
49
  "scripts": {
50
- "html:lint": "markuplint **/*.html"
50
+ "lint:html": "markuplint **/*.html"
51
51
  }
52
52
  }
53
53
  ```
@@ -57,9 +57,9 @@ If you want to change the target path, you can change it for your project.
57
57
  Execute the script:
58
58
 
59
59
  ```
60
- $ npm run html:lint
60
+ $ npm run lint:html
61
61
  # or
62
- $ yarn html:lint
62
+ $ yarn lint:html
63
63
  ```
64
64
 
65
65
  ### Command line options
@@ -74,9 +74,10 @@ Usage
74
74
  Options
75
75
  --config, -c FILE_PATH A configuration file path.
76
76
  --fix, Fix HTML.
77
- --format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
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.
@@ -120,7 +121,10 @@ Need [Sponsors❤️‍🔥](https://github.com/sponsors/markuplint)
120
121
  ### Personal Supporters
121
122
 
122
123
  [<img width="36" src="https://avatars.githubusercontent.com/u/91733847" alt="Tokitake" />](https://github.com/Tokitake)
123
- [<img width="36" src="https://avatars.githubusercontent.com/u/1996642" alt="yamanoku" />](https://github.com/yamanoku)
124
+ [<img width="36" src="https://avatars.githubusercontent.com/u/1996642" alt="Okuto Oyama" />](https://github.com/yamanoku)
125
+ [<img width="36" src="https://avatars.githubusercontent.com/u/6581173" alt="miita" />](https://github.com/mikimhk)
126
+ [<img width="36" src="https://avatars.githubusercontent.com/u/111797" alt="Yasuo Fukuda" />](https://github.com/sigwyg)
127
+ [<img width="36" src="https://avatars.githubusercontent.com/u/802921" alt="Hideyuki Saito" />](https://github.com/hideyukisaito)
124
128
 
125
129
  ## Thanks
126
130
 
@@ -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 { MLResultInfo } from '../types';
2
- import type { APIOptions } 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
- export declare function lint(targetList: Target[], options?: APIOptions): Promise<MLResultInfo[]>;
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,17 +1,23 @@
1
- import type { MLResultInfo } from '../types';
2
- import type { APIOptions, MLEngineEventMap } 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
+ import type { PlainData } from '@markuplint/ml-config';
4
5
  import type { Document, RuleConfigValue } from '@markuplint/ml-core';
5
- import { StrictEventEmitter } from 'strict-event-emitter';
6
+ import { Emitter } from 'strict-event-emitter';
6
7
  type MLEngineOptions = {
7
- debug?: boolean;
8
- watch?: boolean;
8
+ readonly debug?: boolean;
9
+ readonly watch?: boolean;
9
10
  };
10
- export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
11
+ export type FromCodeOptions = APIOptions & MLEngineOptions & {
12
+ readonly name?: string;
13
+ readonly dirname?: string;
14
+ };
15
+ export default class MLEngine extends Emitter<MLEngineEventMap> {
11
16
  #private;
12
- static toMLFile(target: Target): Promise<MLFile>;
13
- constructor(file: MLFile, options?: APIOptions & MLEngineOptions);
14
- get document(): Document<RuleConfigValue, unknown> | null;
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;
15
21
  close(): Promise<void>;
16
22
  exec(): Promise<MLResultInfo | null>;
17
23
  setCode(code: string): Promise<void>;
@@ -1,66 +1,75 @@
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
- class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
11
+ const configLog = log.extend('config');
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
+ const engine = new MLEngine(file, options);
23
+ await engine.setup();
24
+ return engine;
25
+ }
14
26
  static async toMLFile(target) {
15
- const files = await (0, file_resolver_1.resolveFiles)([target]);
27
+ const files = await resolveFiles([target]);
16
28
  return files[0];
17
29
  }
18
30
  constructor(file, options) {
19
- var _a, _b;
20
31
  super();
21
32
  _MLEngine_configProvider.set(this, void 0);
22
33
  _MLEngine_core.set(this, null);
23
34
  _MLEngine_file.set(this, void 0);
24
35
  _MLEngine_options.set(this, void 0);
25
- _MLEngine_watcher.set(this, new chokidar_1.FSWatcher());
26
- tslib_1.__classPrivateFieldSet(this, _MLEngine_file, file, "f");
27
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, options, "f");
28
- tslib_1.__classPrivateFieldSet(this, _MLEngine_configProvider, new file_resolver_1.ConfigProvider(), "f");
29
- this.watchMode(!!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch));
30
- if ((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.debug) {
31
- (0, debug_1.verbosely)();
36
+ _MLEngine_watcher.set(this, new FSWatcher());
37
+ __classPrivateFieldSet(this, _MLEngine_file, file, "f");
38
+ __classPrivateFieldSet(this, _MLEngine_options, options, "f");
39
+ __classPrivateFieldSet(this, _MLEngine_configProvider, new ConfigProvider(), "f");
40
+ this.watchMode(!!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch);
41
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
42
+ verbosely();
32
43
  }
33
44
  }
34
45
  get document() {
35
- var _a, _b, _c;
36
- if (((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _a === void 0 ? void 0 : _a.document) instanceof Error) {
46
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")?.document instanceof Error) {
37
47
  return null;
38
48
  }
39
- return (_c = (_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _b === void 0 ? void 0 : _b.document) !== null && _c !== void 0 ? _c : null;
49
+ return __classPrivateFieldGet(this, _MLEngine_core, "f")?.document ?? null;
40
50
  }
41
51
  async close() {
42
52
  this.removeAllListeners();
43
- await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
53
+ await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
44
54
  }
45
55
  async exec() {
46
- var _a, _b;
47
56
  log('exec: start');
48
57
  const core = await this.setup();
49
58
  if (!core) {
50
59
  log('exec: cancel (unsetuped yet)');
51
60
  return null;
52
61
  }
53
- const violations = await core.verify((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.fix).catch(e => {
62
+ const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(e => {
54
63
  if (e instanceof Error) {
55
64
  return e;
56
65
  }
57
66
  throw e;
58
67
  });
59
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
68
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
60
69
  const fixedCode = core.document.toString();
61
70
  if (violations instanceof Error) {
62
- this.emit('lint-error', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
63
- const errMessage = (_b = violations.stack) !== null && _b !== void 0 ? _b : violations.message;
71
+ this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
72
+ const errMessage = violations.stack ?? violations.message;
64
73
  log('exec: error %O', errMessage);
65
74
  return {
66
75
  violations: [
@@ -73,17 +82,17 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
73
82
  raw: '',
74
83
  },
75
84
  ],
76
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
85
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
77
86
  sourceCode,
78
87
  fixedCode,
79
88
  };
80
89
  }
81
- const debugMap = ('debugMap' in core.document && core.document.debugMap()) || null;
82
- this.emit('lint', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
90
+ const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
91
+ this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
83
92
  log('exec: end');
84
93
  return {
85
94
  violations,
86
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
95
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
87
96
  sourceCode,
88
97
  fixedCode,
89
98
  };
@@ -93,47 +102,44 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
93
102
  if (!core) {
94
103
  return;
95
104
  }
96
- tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
105
+ __classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
97
106
  core.setCode(code);
98
107
  }
99
108
  watchMode(enable) {
100
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
101
- ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
109
+ __classPrivateFieldSet(this, _MLEngine_options, {
110
+ ...__classPrivateFieldGet(this, _MLEngine_options, "f"),
102
111
  watch: enable,
103
112
  }, "f");
104
113
  if (enable) {
105
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
114
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
106
115
  }
107
116
  else {
108
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
117
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
109
118
  }
110
119
  }
111
120
  async createCore(fabric) {
112
- var _a;
113
121
  fileLog('Get source code');
114
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
115
- fileLog('Source code path: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
122
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
123
+ fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
116
124
  // cspell: disable-next-line
117
125
  fileLog('Source code size: %dbyte', sourceCode.length);
118
- this.emit('code', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
119
- const core = new ml_core_1.MLCore({
126
+ this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
127
+ const core = new MLCore({
120
128
  sourceCode,
121
- filename: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
122
- debug: (_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.debug,
129
+ filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
130
+ debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
123
131
  ...fabric,
124
132
  });
125
- tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
133
+ __classPrivateFieldSet(this, _MLEngine_core, core, "f");
126
134
  return core;
127
135
  }
128
136
  async i18n() {
129
- var _a;
130
- const i18nSettings = await (0, i18n_1.i18n)((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.locale);
131
- this.emit('i18n', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
137
+ const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
138
+ this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
132
139
  return i18nSettings;
133
140
  }
134
141
  async onChange(filePath) {
135
- var _a, _b;
136
- if (!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch)) {
142
+ if (!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
137
143
  return;
138
144
  }
139
145
  this.emit('log', 'watch:onChange', filePath);
@@ -142,45 +148,57 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
142
148
  return;
143
149
  }
144
150
  if (fabric.configErrors) {
145
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
151
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
146
152
  }
147
- this.emit('log', 'update:core', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
148
- (_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _b === void 0 ? void 0 : _b.update(fabric);
153
+ this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
154
+ __classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
149
155
  await this.exec();
150
156
  }
151
157
  async provide(cache = true) {
152
- var _a, _b, _c;
153
- const configSet = await this.resolveConfig(cache);
158
+ let configSet;
159
+ try {
160
+ configSet = await this.resolveConfig(cache);
161
+ }
162
+ catch (error) {
163
+ if (error instanceof Error) {
164
+ configSet = {
165
+ config: {},
166
+ plugins: [],
167
+ files: new Set(),
168
+ errs: [error],
169
+ };
170
+ }
171
+ else {
172
+ throw error;
173
+ }
174
+ }
154
175
  fileLog('Fetched Config files: %O', configSet.files);
155
176
  fileLog('Resolved Config: %O', configSet.config);
156
177
  fileLog('Resolved Plugins: %O', configSet.plugins);
157
178
  fileLog('Resolve Errors: %O', configSet.errs);
158
- if (!(await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
159
- 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}`);
160
- fileLog("The file doesn't exist or it is not a file: %s", tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
179
+ if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
180
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
181
+ fileLog("The file doesn't exist or it is not a file: %s", __classPrivateFieldGet(this, _MLEngine_file, "f").path);
161
182
  return null;
162
183
  }
163
184
  // Exclude
164
- const excludeFiles = configSet.config.excludeFiles || [];
165
- for (const excludeFile of excludeFiles) {
166
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").matches(excludeFile)) {
167
- this.emit('exclude', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, excludeFile);
168
- fileLog('Excludes the file: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
169
- return null;
170
- }
185
+ const excludeFiles = configSet.config.excludeFiles ?? [];
186
+ if (__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
187
+ fileLog('Excludes the file: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
188
+ return null;
171
189
  }
172
190
  const { parser, parserOptions, matched } = await this.resolveParser(configSet);
173
- const checkingExt = !((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.ignoreExt);
191
+ const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
174
192
  if (checkingExt && !matched) {
175
- this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
176
- fileLog('Avoided linting because a file is unmatched by the extension: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
193
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
194
+ fileLog('Avoided linting because a file is unmatched by the extension: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
177
195
  return null;
178
196
  }
179
197
  const ruleset = this.resolveRuleset(configSet);
180
198
  fileLog('Resolved ruleset: %O', ruleset);
181
199
  const schemas = await this.resolveSchemas(configSet);
182
200
  if (fileLog.enabled) {
183
- if (schemas[0].cites.length) {
201
+ if (schemas[0].cites.length > 0) {
184
202
  const [, ...additionalSpecs] = schemas;
185
203
  fileLog('Resolved schemas: HTML Standard');
186
204
  for (const additionalSpec of additionalSpecs) {
@@ -193,14 +211,14 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
193
211
  }
194
212
  const rules = await this.resolveRules(configSet.plugins, ruleset);
195
213
  fileLog('Resolved rules: %O', rules);
196
- const locale = await (0, i18n_1.i18n)((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.locale);
214
+ const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
197
215
  if (fileLog.enabled) {
198
216
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
199
217
  }
200
218
  return {
201
219
  parser,
202
220
  parserOptions,
203
- pretenders: (_c = configSet.config.pretenders) !== null && _c !== void 0 ? _c : [],
221
+ pretenders: configSet.config.pretenders ?? [],
204
222
  ruleset,
205
223
  schemas,
206
224
  rules,
@@ -209,60 +227,76 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
209
227
  };
210
228
  }
211
229
  async resolveConfig(cache) {
212
- var _a, _b, _c, _d, _e, _f;
213
- 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);
214
- const configFilePathsFromTarget = ((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.noSearchConfig)
215
- ? defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : null
216
- : (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"))) || defaultConfigKey;
217
- this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget || 'null');
218
- const configKey = ((_d = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _d === void 0 ? void 0 : _d.config) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").config);
219
- this.emit('log', 'configKey', configKey || 'null');
220
- const configSet = await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, (_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.configFile, configKey], cache);
221
- this.emit('config', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
222
- if ((_f = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _f === void 0 ? void 0 : _f.watch) {
230
+ const defaultConfigKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig);
231
+ configLog('defaultConfigKey: %s', defaultConfigKey ?? 'N/A');
232
+ this.emit('log', 'defaultConfigKey', defaultConfigKey ?? 'N/A');
233
+ const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
234
+ ? defaultConfigKey ?? null
235
+ : (await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(__classPrivateFieldGet(this, _MLEngine_file, "f"))) ?? defaultConfigKey;
236
+ configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget ?? 'N/A');
237
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget ?? 'N/A');
238
+ const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
239
+ configLog('option.config: %s', configKey ?? 'N/A');
240
+ this.emit('log', 'option.config', configFilePathsFromTarget ?? 'N/A');
241
+ let defaultRecommended = null;
242
+ if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
243
+ // No configured
244
+ // Default: set recommended
245
+ defaultRecommended = __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
246
+ }
247
+ configLog('defaultRecommended: %s', defaultRecommended ?? 'N/A');
248
+ this.emit('log', 'defaultRecommended', defaultRecommended ?? 'N/A');
249
+ const configSet = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey, defaultRecommended], cache);
250
+ this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
251
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
223
252
  // It doesn't watch the main HTML file because it may is watched and managed by a language server or text editor or more.
224
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
253
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
225
254
  }
226
255
  return configSet;
227
256
  }
228
- async resolveParser(configSet) {
229
- const parser = await (0, file_resolver_1.resolveParser)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
230
- this.emit('parser', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
257
+ async resolveParser(
258
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
259
+ configSet) {
260
+ const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
261
+ this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
231
262
  fileLog('Fetched Parser module: %s', parser.parserModName);
232
263
  return parser;
233
264
  }
234
265
  async resolveRules(plugins, ruleset) {
235
- var _a, _b, _c, _d, _e;
236
- 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);
237
- if ((_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.rules) {
238
- rules.push(...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
266
+ const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
267
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
268
+ rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
239
269
  }
240
- this.emit('rules', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
270
+ this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
241
271
  return rules;
242
272
  }
243
- resolveRuleset(configSet) {
244
- const ruleset = (0, ml_core_1.convertRuleset)(configSet.config);
245
- this.emit('ruleset', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
273
+ resolveRuleset(
274
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
275
+ configSet) {
276
+ const ruleset = convertRuleset(configSet.config);
277
+ this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
246
278
  return ruleset;
247
279
  }
248
- async resolveSchemas(configSet) {
249
- const { schemas } = await (0, file_resolver_1.resolveSpecs)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
250
- this.emit('schemas', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
280
+ async resolveSchemas(
281
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
282
+ configSet) {
283
+ const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
284
+ this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
251
285
  return schemas;
252
286
  }
253
287
  async setup() {
254
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
255
- return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
288
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
289
+ return __classPrivateFieldGet(this, _MLEngine_core, "f");
256
290
  }
257
291
  const fabric = await this.provide();
258
292
  if (!fabric) {
259
293
  return null;
260
294
  }
261
295
  if (fabric.configErrors) {
262
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
296
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
263
297
  }
264
298
  return this.createCore(fabric);
265
299
  }
266
300
  }
267
- exports.default = MLEngine;
268
301
  _MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
302
+ export default MLEngine;
@@ -1,44 +1,40 @@
1
1
  import type { ConfigSet } from '@markuplint/file-resolver';
2
2
  import type { LocaleSet } from '@markuplint/i18n';
3
- import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
4
- import type { Config, Pretender, Violation } from '@markuplint/ml-config';
3
+ import type { Config, Violation } from '@markuplint/ml-config';
5
4
  import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
6
5
  export type APIOptions = {
7
- configFile?: string;
8
- config?: Config;
9
- defaultConfig?: Config;
10
- noSearchConfig?: boolean;
11
- locale?: string;
12
- fix?: boolean;
13
- ignoreExt?: boolean;
14
- rules?: AnyMLRule[];
15
- importPresetRules?: 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;
16
15
  /**
17
16
  * @deprecated
18
17
  */
19
- autoLoad?: boolean;
20
- };
21
- export type MLFabric = {
22
- ruleset: Ruleset;
23
- rules: AnyMLRule[];
24
- schemas: MLSchema;
25
- parser: MLMarkupLanguageParser;
26
- parserOptions: ParserOptions;
27
- pretenders: Pretender[];
28
- locale: LocaleSet;
29
- configErrors?: Error[];
18
+ readonly autoLoad?: boolean;
30
19
  };
31
20
  export type MLEngineEventMap = {
32
- log: (phase: string, message: string) => void;
33
- config: (filePath: string, config: ConfigSet, message?: string) => void;
34
- exclude: (filePath: string, setting: string, message?: string) => void;
35
- parser: (filePath: string, parser: string, message?: string) => void;
36
- ruleset: (filePath: string, ruleset: Ruleset, message?: string) => void;
37
- schemas: (filePath: string, schemas: MLSchema, message?: string) => void;
38
- rules: (filePath: string, rules: AnyMLRule[], message?: string) => void;
39
- i18n: (filePath: string, locale: LocaleSet, message?: string) => void;
40
- code: (filePath: string, sourceCode: string, message?: string) => void;
41
- lint: (filePath: string, sourceCode: string, violations: Violation[], fixedCode: string, debug: string[] | null, message?: string) => void;
42
- 'lint-error': (filePath: string, sourceCode: string, error: Error) => void;
43
- 'config-errors': (filePath: string, errors: Error[]) => void;
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>[]];
44
40
  };
package/lib/api/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};