markuplint 3.0.0-dev.25 → 3.0.0-dev.300

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 +135 -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 +7 -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,74 @@
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
+ return engine;
24
+ }
14
25
  static async toMLFile(target) {
15
- const files = await (0, file_resolver_1.resolveFiles)([target]);
26
+ const files = await resolveFiles([target]);
16
27
  return files[0];
17
28
  }
18
29
  constructor(file, options) {
19
- var _a, _b;
20
30
  super();
21
31
  _MLEngine_configProvider.set(this, void 0);
22
32
  _MLEngine_core.set(this, null);
23
33
  _MLEngine_file.set(this, void 0);
24
34
  _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)();
35
+ _MLEngine_watcher.set(this, new FSWatcher());
36
+ __classPrivateFieldSet(this, _MLEngine_file, file, "f");
37
+ __classPrivateFieldSet(this, _MLEngine_options, options, "f");
38
+ __classPrivateFieldSet(this, _MLEngine_configProvider, new ConfigProvider(), "f");
39
+ this.watchMode(!!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch);
40
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
41
+ verbosely();
32
42
  }
33
43
  }
34
44
  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) {
45
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")?.document instanceof Error) {
37
46
  return null;
38
47
  }
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;
48
+ return __classPrivateFieldGet(this, _MLEngine_core, "f")?.document ?? null;
40
49
  }
41
50
  async close() {
42
51
  this.removeAllListeners();
43
- await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
52
+ await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
44
53
  }
45
54
  async exec() {
46
- var _a, _b;
47
55
  log('exec: start');
48
56
  const core = await this.setup();
49
57
  if (!core) {
50
58
  log('exec: cancel (unsetuped yet)');
51
59
  return null;
52
60
  }
53
- const violations = await core.verify((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.fix).catch(e => {
61
+ const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(e => {
54
62
  if (e instanceof Error) {
55
63
  return e;
56
64
  }
57
65
  throw e;
58
66
  });
59
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
67
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
60
68
  const fixedCode = core.document.toString();
61
69
  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;
70
+ this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
71
+ const errMessage = violations.stack ?? violations.message;
64
72
  log('exec: error %O', errMessage);
65
73
  return {
66
74
  violations: [
@@ -73,17 +81,17 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
73
81
  raw: '',
74
82
  },
75
83
  ],
76
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
84
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
77
85
  sourceCode,
78
86
  fixedCode,
79
87
  };
80
88
  }
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);
89
+ const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
90
+ this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
83
91
  log('exec: end');
84
92
  return {
85
93
  violations,
86
- filePath: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
94
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
87
95
  sourceCode,
88
96
  fixedCode,
89
97
  };
@@ -93,47 +101,44 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
93
101
  if (!core) {
94
102
  return;
95
103
  }
96
- tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
104
+ __classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
97
105
  core.setCode(code);
98
106
  }
99
107
  watchMode(enable) {
100
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
101
- ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
108
+ __classPrivateFieldSet(this, _MLEngine_options, {
109
+ ...__classPrivateFieldGet(this, _MLEngine_options, "f"),
102
110
  watch: enable,
103
111
  }, "f");
104
112
  if (enable) {
105
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
113
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
106
114
  }
107
115
  else {
108
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
116
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
109
117
  }
110
118
  }
111
119
  async createCore(fabric) {
112
- var _a;
113
120
  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);
121
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
122
+ fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
116
123
  // cspell: disable-next-line
117
124
  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({
125
+ this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
126
+ const core = new MLCore({
120
127
  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,
128
+ filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
129
+ debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
123
130
  ...fabric,
124
131
  });
125
- tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
132
+ __classPrivateFieldSet(this, _MLEngine_core, core, "f");
126
133
  return core;
127
134
  }
128
135
  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);
136
+ const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
137
+ this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
132
138
  return i18nSettings;
133
139
  }
134
140
  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)) {
141
+ if (!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
137
142
  return;
138
143
  }
139
144
  this.emit('log', 'watch:onChange', filePath);
@@ -142,45 +147,57 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
142
147
  return;
143
148
  }
144
149
  if (fabric.configErrors) {
145
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
150
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
146
151
  }
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);
152
+ this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
153
+ __classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
149
154
  await this.exec();
150
155
  }
151
156
  async provide(cache = true) {
152
- var _a, _b, _c;
153
- const configSet = await this.resolveConfig(cache);
157
+ let configSet;
158
+ try {
159
+ configSet = await this.resolveConfig(cache);
160
+ }
161
+ catch (error) {
162
+ if (error instanceof Error) {
163
+ configSet = {
164
+ config: {},
165
+ plugins: [],
166
+ files: new Set(),
167
+ errs: [error],
168
+ };
169
+ }
170
+ else {
171
+ throw error;
172
+ }
173
+ }
154
174
  fileLog('Fetched Config files: %O', configSet.files);
155
175
  fileLog('Resolved Config: %O', configSet.config);
156
176
  fileLog('Resolved Plugins: %O', configSet.plugins);
157
177
  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);
178
+ if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
179
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
180
+ fileLog("The file doesn't exist or it is not a file: %s", __classPrivateFieldGet(this, _MLEngine_file, "f").path);
161
181
  return null;
162
182
  }
163
183
  // 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
- }
184
+ const excludeFiles = configSet.config.excludeFiles ?? [];
185
+ if (__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
186
+ fileLog('Excludes the file: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
187
+ return null;
171
188
  }
172
189
  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);
190
+ const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
174
191
  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);
192
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
193
+ fileLog('Avoided linting because a file is unmatched by the extension: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
177
194
  return null;
178
195
  }
179
196
  const ruleset = this.resolveRuleset(configSet);
180
197
  fileLog('Resolved ruleset: %O', ruleset);
181
198
  const schemas = await this.resolveSchemas(configSet);
182
199
  if (fileLog.enabled) {
183
- if (schemas[0].cites.length) {
200
+ if (schemas[0].cites.length > 0) {
184
201
  const [, ...additionalSpecs] = schemas;
185
202
  fileLog('Resolved schemas: HTML Standard');
186
203
  for (const additionalSpec of additionalSpecs) {
@@ -193,14 +210,14 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
193
210
  }
194
211
  const rules = await this.resolveRules(configSet.plugins, ruleset);
195
212
  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);
213
+ const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
197
214
  if (fileLog.enabled) {
198
215
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
199
216
  }
200
217
  return {
201
218
  parser,
202
219
  parserOptions,
203
- pretenders: (_c = configSet.config.pretenders) !== null && _c !== void 0 ? _c : [],
220
+ pretenders: configSet.config.pretenders ?? [],
204
221
  ruleset,
205
222
  schemas,
206
223
  rules,
@@ -209,60 +226,76 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
209
226
  };
210
227
  }
211
228
  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) {
229
+ const defaultConfigKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig);
230
+ configLog('defaultConfigKey: %s', defaultConfigKey ?? 'N/A');
231
+ this.emit('log', 'defaultConfigKey', defaultConfigKey ?? 'N/A');
232
+ const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
233
+ ? defaultConfigKey ?? null
234
+ : (await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(__classPrivateFieldGet(this, _MLEngine_file, "f"))) ?? defaultConfigKey;
235
+ configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget ?? 'N/A');
236
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget ?? 'N/A');
237
+ const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
238
+ configLog('option.config: %s', configKey ?? 'N/A');
239
+ this.emit('log', 'option.config', configFilePathsFromTarget ?? 'N/A');
240
+ let defaultRecommended = null;
241
+ if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
242
+ // No configured
243
+ // Default: set recommended
244
+ defaultRecommended = __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
245
+ }
246
+ configLog('defaultRecommended: %s', defaultRecommended ?? 'N/A');
247
+ this.emit('log', 'defaultRecommended', defaultRecommended ?? 'N/A');
248
+ const configSet = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey, defaultRecommended], cache);
249
+ this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
250
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
223
251
  // 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));
252
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
225
253
  }
226
254
  return configSet;
227
255
  }
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);
256
+ async resolveParser(
257
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
258
+ configSet) {
259
+ const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
260
+ this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
231
261
  fileLog('Fetched Parser module: %s', parser.parserModName);
232
262
  return parser;
233
263
  }
234
264
  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);
265
+ const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
266
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
267
+ rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
239
268
  }
240
- this.emit('rules', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
269
+ this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
241
270
  return rules;
242
271
  }
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);
272
+ resolveRuleset(
273
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
274
+ configSet) {
275
+ const ruleset = convertRuleset(configSet.config);
276
+ this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
246
277
  return ruleset;
247
278
  }
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);
279
+ async resolveSchemas(
280
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
281
+ configSet) {
282
+ const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
283
+ this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
251
284
  return schemas;
252
285
  }
253
286
  async setup() {
254
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
255
- return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
287
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
288
+ return __classPrivateFieldGet(this, _MLEngine_core, "f");
256
289
  }
257
290
  const fabric = await this.provide();
258
291
  if (!fabric) {
259
292
  return null;
260
293
  }
261
294
  if (fabric.configErrors) {
262
- this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
295
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
263
296
  }
264
297
  return this.createCore(fabric);
265
298
  }
266
299
  }
267
- exports.default = MLEngine;
268
300
  _MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
301
+ 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 {};