markuplint 3.0.0-alpha.66 → 3.0.0-dev.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +29 -24
  2. package/lib/api/lint.d.ts +2 -2
  3. package/lib/api/ml-engine.d.ts +26 -23
  4. package/lib/api/ml-engine.js +114 -83
  5. package/lib/api/types.d.ts +35 -38
  6. package/lib/api/v1.d.ts +44 -44
  7. package/lib/api/v1.js +4 -7
  8. package/lib/cli/bootstrap.d.ts +3 -2
  9. package/lib/cli/bootstrap.js +2 -2
  10. package/lib/cli/command.d.ts +6 -2
  11. package/lib/cli/command.js +17 -3
  12. package/lib/cli/create-rule/index.js +48 -19
  13. package/lib/cli/index.js +5 -2
  14. package/lib/cli/init/create-config.d.ts +8 -0
  15. package/lib/cli/init/create-config.js +95 -0
  16. package/lib/cli/init/get-default-rules.d.ts +3 -0
  17. package/lib/cli/init/get-default-rules.js +57 -0
  18. package/lib/cli/init/index.js +23 -199
  19. package/lib/cli/init/install-module.d.ts +6 -4
  20. package/lib/cli/init/install-module.js +16 -2
  21. package/lib/cli/init/types.d.ts +20 -0
  22. package/lib/cli/init/types.js +2 -0
  23. package/lib/cli/output.d.ts +1 -1
  24. package/lib/cli/output.js +6 -3
  25. package/lib/cli/prompt.d.ts +19 -14
  26. package/lib/cli/search/index.d.ts +1 -1
  27. package/lib/cli/search/index.js +2 -1
  28. package/lib/global-settings.d.ts +2 -2
  29. package/lib/i18n.d.ts +2 -6
  30. package/lib/i18n.js +8 -6
  31. package/lib/reporter/github-reporter.d.ts +2 -0
  32. package/lib/reporter/github-reporter.js +23 -0
  33. package/lib/reporter/index.d.ts +1 -0
  34. package/lib/reporter/index.js +1 -0
  35. package/lib/reporter/simple-reporter.js +1 -1
  36. package/lib/reporter/standard-reporter.js +5 -4
  37. package/lib/testing-tool/index.d.ts +44 -26
  38. package/lib/types.d.ts +18 -19
  39. package/lib/util.d.ts +4 -6
  40. package/lib/util.js +12 -10
  41. package/package.json +27 -23
  42. package/.markuplintrc +0 -19
  43. package/media/screenshot01.png +0 -0
  44. package/test/plugin001.js +0 -24
  45. package/tsconfig.test.json +0 -3
  46. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,18 +1,21 @@
1
- # ![markuplint](https://cdn.rawgit.com/YusukeHirao/markuplint/HEAD/media/logo-v.svg)
1
+ # ![markuplint](https://cdn.jsdelivr.net/gh/markuplint/markuplint@main/media/logo-v.svg)
2
2
 
3
- [![npm version](https://badge.fury.io/js/markuplint.svg)](https://badge.fury.io/js/markuplint)
3
+ [![npm version](https://img.shields.io/npm/v/markuplint.svg)](https://www.npmjs.com/package/markuplint)
4
+ [![Downloads](https://img.shields.io/npm/dm/markuplint.svg)](https://www.npmjs.com/package/markuplint)
4
5
  [![Test](https://github.com/markuplint/markuplint/workflows/Test/badge.svg?branch=main)](https://github.com/markuplint/markuplint/actions?query=workflow%3ATest)
5
6
  [![Coverage Status](https://coveralls.io/repos/github/markuplint/markuplint/badge.svg?branch=main)](https://coveralls.io/github/markuplint/markuplint?branch=main)
7
+ [![GitHub Stars](https://img.shields.io/github/stars/markuplint.svg)](https://github.com/markuplint/markuplint)
8
+ [![Follow us on Twitter](https://img.shields.io/twitter/follow/markuplint?label=Follow)](https://twitter.com/intent/user?screen_name=markuplint)
6
9
 
7
- Peace of mind in your markup - A Linter for All Markup Languages.
10
+ **Peace of mind in your markup** - An HTML linter for all markup developers.
8
11
 
9
12
  ## Features
10
13
 
11
- - Conformance checking that according to HTML Living Standard, WAI-ARIA, and ARIA in HTML.
12
- - Supports SVG and CSS Values.
13
- - Supports React, Vue, Svelte, Pug, PHP, and more.
14
- - Possible to specify the rule to each element if you use the selector.
15
- - Possible to create a custom rule.
14
+ - Conformance checking according to _HTML Standard_, _WAI-ARIA_, _ARIA in HTML_, etc.
15
+ - Supports _CSS_ and _SVG_ values.
16
+ - Supports _React_, _Vue_, _Svelte_, _Pug_, _PHP_, and more.
17
+ - Possible to specify the rule for each element if you use _CSS Selector_.
18
+ - Potential to create a custom rule.
16
19
 
17
20
  ![Screenshot: Violation Report CLI output](https://raw.githubusercontent.com/markuplint/markuplint/main/packages/markuplint/media/screenshot01.png)
18
21
 
@@ -22,7 +25,7 @@ Peace of mind in your markup - A Linter for All Markup Languages.
22
25
  $ npx markuplint target.html
23
26
  ```
24
27
 
25
- Supported for _Node.js_ `v12.4.0` or later.
28
+ Supported for _Node.js_ `v14.6.0` or later.
26
29
 
27
30
  ## Usage
28
31
 
@@ -37,14 +40,14 @@ $ yarn run markuplint --init
37
40
  ```
38
41
 
39
42
  Answer questions interactively.
40
- By doing this, needed modules are installed includes `markuplint`.
43
+ By doing this, needed modules are installed, including `markuplint`.
41
44
 
42
45
  Add a command to the `scripts` option on `package.json`:
43
46
 
44
47
  ```json
45
48
  {
46
49
  "scripts": {
47
- "html:lint": "markuplint **/*.html"
50
+ "lint:html": "markuplint **/*.html"
48
51
  }
49
52
  }
50
53
  ```
@@ -54,9 +57,9 @@ If you want to change the target path, you can change it for your project.
54
57
  Execute the script:
55
58
 
56
59
  ```
57
- $ npm run html:lint
60
+ $ npm run lint:html
58
61
  # or
59
- $ yarn html:lint
62
+ $ yarn lint:html
60
63
  ```
61
64
 
62
65
  ### Command line options
@@ -65,13 +68,13 @@ $ yarn html:lint
65
68
  $ npx markuplint --help
66
69
 
67
70
  Usage
68
- $ markuplint <HTML file pathes (glob format)>
71
+ $ markuplint <HTML file paths (glob format)>
69
72
  $ <stdout> | markuplint
70
73
 
71
74
  Options
72
75
  --config, -c FILE_PATH A configuration file path.
73
76
  --fix, Fix HTML.
74
- --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".
75
78
  --no-search-config No search a configure file automatically.
76
79
  --ignore-ext Evaluate files that are received even though the type of extension.
77
80
  --no-import-preset-rules No import preset rules.
@@ -91,32 +94,34 @@ Examples
91
94
  $ cat verifyee.html | markuplint
92
95
  ```
93
96
 
94
- ## Guideline
97
+ ## Documentation
95
98
 
96
99
  - [Getting Started](https://markuplint.dev/getting-started)
97
100
  - [Rules](https://markuplint.dev/rules)
98
101
  - [Configuration](https://markuplint.dev/configuration)
99
102
  - [API](https://markuplint.dev/api-docs)
103
+
104
+ ## Playground
105
+
100
106
  - [Playground](https://playground.markuplint.dev/)
101
107
 
102
108
  ## Editor Extensions
103
109
 
104
- | Editor | Installation Page | Author |
105
- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
106
- | <a href="https://marketplace.visualstudio.com/items?itemName=yusukehirao.vscode-markuplint"><img src="https://raw.githubusercontent.com/markuplint/markuplint/main/media/vscode.png" width="75" height="82" alt="Visual Studio Code: markuplint extension"></a> | [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=yusukehirao.vscode-markuplint) | [@YusukeHirao](https://github.com/YusukeHirao) |
110
+ - [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=yusukehirao.vscode-markuplint)
107
111
 
108
112
  ## License
109
113
 
110
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmarkuplint%2Fmarkuplint.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmarkuplint%2Fmarkuplint?ref=badge_large)
114
+ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarkuplint%2Fmarkuplint.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarkuplint%2Fmarkuplint?ref=badge_large)
111
115
 
112
116
  ## Sponsors
113
117
 
114
- [:heart: Sponsor](https://github.com/sponsors/markuplint)
118
+ Need [Sponsors❤️‍🔥](https://github.com/sponsors/markuplint)
115
119
 
116
120
  ### Personal Supporters
117
121
 
118
- [<img width="36" src="https://avatars.githubusercontent.com/u/6581173?v=4" alt="mikimhk"/>](https://github.com/mikimhk)
119
- [<img width="36" src="https://avatars.githubusercontent.com/u/91733847?v=4" alt="Tokitake" />](https://github.com/Tokitake)
122
+ [<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/6581173" alt="miita" />](https://github.com/mikimhk)
120
125
 
121
126
  ## Thanks
122
127
 
@@ -124,5 +129,5 @@ This linter is inspired by:
124
129
 
125
130
  - [HTMLHint](http://htmlhint.com/)
126
131
  - [ESLint](https://eslint.org/)
127
- - [stylelint](https://stylelint.io/)
132
+ - [Stylelint](https://stylelint.io/)
128
133
  - [textlint](https://textlint.github.io/)
package/lib/api/lint.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MLResultInfo } from '../types';
2
1
  import type { APIOptions } from './types';
2
+ import type { MLResultInfo } from '../types';
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[]>;
@@ -1,28 +1,31 @@
1
- import type { MLResultInfo } from '../types';
2
1
  import type { APIOptions, MLEngineEventMap } from './types';
2
+ import type { MLResultInfo } from '../types';
3
3
  import type { MLFile, Target } from '@markuplint/file-resolver';
4
- import { StrictEventEmitter } from 'strict-event-emitter';
5
- declare type MLEngineOptions = {
6
- debug?: boolean;
7
- watch?: boolean;
4
+ import type { PlainData } from '@markuplint/ml-config';
5
+ import type { Document, RuleConfigValue } from '@markuplint/ml-core';
6
+ import { Emitter } from 'strict-event-emitter';
7
+ type MLEngineOptions = {
8
+ readonly debug?: boolean;
9
+ readonly watch?: boolean;
8
10
  };
9
- export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
10
- #private;
11
- static toMLFile(target: Target): Promise<MLFile>;
12
- constructor(file: MLFile, options?: APIOptions & MLEngineOptions);
13
- watchMode(enable: boolean): void;
14
- exec(): Promise<MLResultInfo | null>;
15
- setCode(code: string): Promise<void>;
16
- close(): Promise<void>;
17
- private setup;
18
- private provide;
19
- private cretateCore;
20
- private resolveConfig;
21
- private resolveParser;
22
- private resolveRuleset;
23
- private resolveSchemas;
24
- private resolveRules;
25
- private i18n;
26
- private onChange;
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;
27
30
  }
28
31
  export {};
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var _MLEngine_file, _MLEngine_options, _MLEngine_core, _MLEngine_watcher, _MLEngine_configProvider;
2
+ var _MLEngine_configProvider, _MLEngine_core, _MLEngine_file, _MLEngine_options, _MLEngine_watcher;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const file_resolver_1 = require("@markuplint/file-resolver");
@@ -10,15 +10,20 @@ const debug_1 = require("../debug");
10
10
  const i18n_1 = require("../i18n");
11
11
  const log = debug_1.log.extend('ml-engine');
12
12
  const fileLog = log.extend('file');
13
- class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
13
+ const configLog = log.extend('config');
14
+ class MLEngine extends strict_event_emitter_1.Emitter {
15
+ static async toMLFile(target) {
16
+ const files = await (0, file_resolver_1.resolveFiles)([target]);
17
+ return files[0];
18
+ }
14
19
  constructor(file, options) {
15
20
  var _a, _b;
16
21
  super();
22
+ _MLEngine_configProvider.set(this, void 0);
23
+ _MLEngine_core.set(this, null);
17
24
  _MLEngine_file.set(this, void 0);
18
25
  _MLEngine_options.set(this, void 0);
19
- _MLEngine_core.set(this, null);
20
26
  _MLEngine_watcher.set(this, new chokidar_1.FSWatcher());
21
- _MLEngine_configProvider.set(this, void 0);
22
27
  tslib_1.__classPrivateFieldSet(this, _MLEngine_file, file, "f");
23
28
  tslib_1.__classPrivateFieldSet(this, _MLEngine_options, options, "f");
24
29
  tslib_1.__classPrivateFieldSet(this, _MLEngine_configProvider, new file_resolver_1.ConfigProvider(), "f");
@@ -27,21 +32,16 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
27
32
  (0, debug_1.verbosely)();
28
33
  }
29
34
  }
30
- static async toMLFile(target) {
31
- const files = await (0, file_resolver_1.resolveFiles)([target]);
32
- return files[0];
33
- }
34
- watchMode(enable) {
35
- tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
36
- ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
37
- watch: enable,
38
- }, "f");
39
- if (enable) {
40
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
41
- }
42
- else {
43
- tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
35
+ 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) {
38
+ return null;
44
39
  }
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;
41
+ }
42
+ async close() {
43
+ this.removeAllListeners();
44
+ await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
45
45
  }
46
46
  async exec() {
47
47
  var _a, _b;
@@ -79,7 +79,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
79
79
  fixedCode,
80
80
  };
81
81
  }
82
- const debugMap = ('debugMap' in core.document && core.document.debugMap()) || null;
82
+ const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
83
83
  this.emit('lint', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
84
84
  log('exec: end');
85
85
  return {
@@ -97,25 +97,60 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
97
97
  tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
98
98
  core.setCode(code);
99
99
  }
100
- async close() {
101
- this.removeAllListeners();
102
- await tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
100
+ watchMode(enable) {
101
+ tslib_1.__classPrivateFieldSet(this, _MLEngine_options, {
102
+ ...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f"),
103
+ watch: enable,
104
+ }, "f");
105
+ if (enable) {
106
+ tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
107
+ }
108
+ else {
109
+ tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
110
+ }
103
111
  }
104
- async setup() {
105
- if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
106
- return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
112
+ async createCore(fabric) {
113
+ var _a;
114
+ 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);
117
+ // cspell: disable-next-line
118
+ 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({
121
+ 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,
124
+ ...fabric,
125
+ });
126
+ tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
127
+ return core;
128
+ }
129
+ 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);
133
+ return i18nSettings;
134
+ }
135
+ 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)) {
138
+ return;
107
139
  }
108
- const fabric = await this.provide();
140
+ this.emit('log', 'watch:onChange', filePath);
141
+ const fabric = await this.provide(false);
109
142
  if (!fabric) {
110
- return null;
143
+ return;
111
144
  }
112
145
  if (fabric.configErrors) {
113
146
  this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
114
147
  }
115
- return this.cretateCore(fabric);
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);
150
+ await this.exec();
116
151
  }
117
152
  async provide(cache = true) {
118
- var _a, _b;
153
+ var _a, _b, _c, _d;
119
154
  const configSet = await this.resolveConfig(cache);
120
155
  fileLog('Fetched Config files: %O', configSet.files);
121
156
  fileLog('Resolved Config: %O', configSet.config);
@@ -123,27 +158,30 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
123
158
  fileLog('Resolve Errors: %O', configSet.errs);
124
159
  if (!(await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
125
160
  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}`);
161
+ fileLog("The file doesn't exist or it is not a file: %s", tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
126
162
  return null;
127
163
  }
128
164
  // Exclude
129
- const excludeFiles = configSet.config.excludeFiles || [];
165
+ const excludeFiles = (_a = configSet.config.excludeFiles) !== null && _a !== void 0 ? _a : [];
130
166
  for (const excludeFile of excludeFiles) {
131
167
  if (tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").matches(excludeFile)) {
132
168
  this.emit('exclude', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, excludeFile);
169
+ fileLog('Excludes the file: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
133
170
  return null;
134
171
  }
135
172
  }
136
173
  const { parser, parserOptions, matched } = await this.resolveParser(configSet);
137
- const checkingExt = !((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.ignoreExt);
174
+ const checkingExt = !((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.ignoreExt);
138
175
  if (checkingExt && !matched) {
139
176
  this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
177
+ fileLog('Avoided linting because a file is unmatched by the extension: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
140
178
  return null;
141
179
  }
142
180
  const ruleset = this.resolveRuleset(configSet);
143
181
  fileLog('Resolved ruleset: %O', ruleset);
144
182
  const schemas = await this.resolveSchemas(configSet);
145
183
  if (fileLog.enabled) {
146
- if (schemas[0].cites.length) {
184
+ if (schemas[0].cites.length > 0) {
147
185
  const [, ...additionalSpecs] = schemas;
148
186
  fileLog('Resolved schemas: HTML Standard');
149
187
  for (const additionalSpec of additionalSpecs) {
@@ -156,13 +194,14 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
156
194
  }
157
195
  const rules = await this.resolveRules(configSet.plugins, ruleset);
158
196
  fileLog('Resolved rules: %O', rules);
159
- const locale = await (0, i18n_1.i18n)((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.locale);
197
+ const locale = await (0, i18n_1.i18n)((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.locale);
160
198
  if (fileLog.enabled) {
161
199
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
162
200
  }
163
201
  return {
164
202
  parser,
165
203
  parserOptions,
204
+ pretenders: (_d = configSet.config.pretenders) !== null && _d !== void 0 ? _d : [],
166
205
  ruleset,
167
206
  schemas,
168
207
  rules,
@@ -170,55 +209,43 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
170
209
  configErrors: configSet.errs,
171
210
  };
172
211
  }
173
- async cretateCore(fabric) {
174
- var _a;
175
- fileLog('Get source code');
176
- const sourceCode = await tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
177
- fileLog('Source code path: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
178
- fileLog('Source code size: %dbyte', sourceCode.length);
179
- this.emit('code', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
180
- const core = new ml_core_1.MLCore({
181
- sourceCode,
182
- filename: tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path,
183
- debug: (_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.debug,
184
- ...fabric,
185
- });
186
- tslib_1.__classPrivateFieldSet(this, _MLEngine_core, core, "f");
187
- return core;
188
- }
189
212
  async resolveConfig(cache) {
190
- var _a, _b, _c, _d, _e, _f;
213
+ var _a, _b, _c, _d, _e, _f, _g;
191
214
  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);
215
+ configLog('defaultConfigKey: %s', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
216
+ this.emit('log', 'defaultConfigKey', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
192
217
  const configFilePathsFromTarget = ((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.noSearchConfig)
193
218
  ? defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : null
194
- : (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"))) || defaultConfigKey;
195
- this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget || 'null');
196
- 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);
197
- this.emit('log', 'configKey', configKey || 'null');
198
- 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);
219
+ : (_d = (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f")))) !== null && _d !== void 0 ? _d : defaultConfigKey;
220
+ configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
221
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
222
+ 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);
223
+ configLog('option.config: %s', configKey !== null && configKey !== void 0 ? configKey : 'N/A');
224
+ this.emit('log', 'option.config', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
225
+ let defaultRecommended = null;
226
+ if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
227
+ // No configured
228
+ // Default: set recommended
229
+ defaultRecommended = tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
230
+ }
231
+ configLog('defaultRecommended: %s', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
232
+ this.emit('log', 'defaultRecommended', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
233
+ 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);
199
234
  this.emit('config', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
200
- if ((_f = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _f === void 0 ? void 0 : _f.watch) {
235
+ if ((_g = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _g === void 0 ? void 0 : _g.watch) {
201
236
  // It doesn't watch the main HTML file because it may is watched and managed by a language server or text editor or more.
202
237
  tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
203
238
  }
204
239
  return configSet;
205
240
  }
206
- async resolveParser(configSet) {
241
+ async resolveParser(
242
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
243
+ configSet) {
207
244
  const parser = await (0, file_resolver_1.resolveParser)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
208
245
  this.emit('parser', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
209
246
  fileLog('Fetched Parser module: %s', parser.parserModName);
210
247
  return parser;
211
248
  }
212
- resolveRuleset(configSet) {
213
- const ruleset = (0, ml_core_1.convertRuleset)(configSet.config);
214
- this.emit('ruleset', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
215
- return ruleset;
216
- }
217
- async resolveSchemas(configSet) {
218
- const { schemas } = await (0, file_resolver_1.resolveSpecs)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
219
- this.emit('schemas', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
220
- return schemas;
221
- }
222
249
  async resolveRules(plugins, ruleset) {
223
250
  var _a, _b, _c, _d, _e;
224
251
  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);
@@ -228,29 +255,33 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
228
255
  this.emit('rules', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
229
256
  return rules;
230
257
  }
231
- async i18n() {
232
- var _a;
233
- const i18nSettings = await (0, i18n_1.i18n)((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.locale);
234
- this.emit('i18n', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
235
- return i18nSettings;
258
+ resolveRuleset(
259
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
260
+ configSet) {
261
+ const ruleset = (0, ml_core_1.convertRuleset)(configSet.config);
262
+ this.emit('ruleset', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
263
+ return ruleset;
236
264
  }
237
- async onChange(filePath) {
238
- var _a, _b;
239
- if (!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch)) {
240
- return;
265
+ async resolveSchemas(
266
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
267
+ configSet) {
268
+ const { schemas } = await (0, file_resolver_1.resolveSpecs)(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
269
+ this.emit('schemas', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
270
+ return schemas;
271
+ }
272
+ async setup() {
273
+ if (tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) {
274
+ return tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f");
241
275
  }
242
- this.emit('log', 'watch:onChange', filePath);
243
- const fabric = await this.provide(false);
276
+ const fabric = await this.provide();
244
277
  if (!fabric) {
245
- return;
278
+ return null;
246
279
  }
247
280
  if (fabric.configErrors) {
248
281
  this.emit('config-errors', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
249
282
  }
250
- this.emit('log', 'update:core', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
251
- (_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _b === void 0 ? void 0 : _b.update(fabric);
252
- await this.exec();
283
+ return this.createCore(fabric);
253
284
  }
254
285
  }
255
286
  exports.default = MLEngine;
256
- _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_watcher = new WeakMap(), _MLEngine_configProvider = new WeakMap();
287
+ _MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
@@ -1,43 +1,40 @@
1
1
  import type { ConfigSet } from '@markuplint/file-resolver';
2
2
  import type { LocaleSet } from '@markuplint/i18n';
3
- import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
4
- import type { Config, Violation, ParserOptions } 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
- export declare 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;
16
- /**
17
- * @deprecated
18
- */
19
- autoLoad?: boolean;
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;
20
19
  };
21
- export declare type MLFabric = {
22
- ruleset: Ruleset;
23
- rules: AnyMLRule[];
24
- schemas: MLSchema;
25
- parser: MLMarkupLanguageParser;
26
- parserOptions: ParserOptions;
27
- locale: LocaleSet;
28
- configErrors?: Error[];
29
- };
30
- export declare type MLEngineEventMap = {
31
- log: (phase: string, message: string) => void;
32
- config: (filePath: string, config: ConfigSet, message?: string) => void;
33
- exclude: (filePath: string, setting: string, message?: string) => void;
34
- parser: (filePath: string, parser: string, message?: string) => void;
35
- ruleset: (filePath: string, ruleset: Ruleset, message?: string) => void;
36
- schemas: (filePath: string, schemas: MLSchema, message?: string) => void;
37
- rules: (filePath: string, rules: AnyMLRule[], message?: string) => void;
38
- i18n: (filePath: string, locale: LocaleSet, message?: string) => void;
39
- code: (filePath: string, sourceCode: string, message?: string) => void;
40
- lint: (filePath: string, sourceCode: string, violations: Violation[], fixedCode: string, debug: string[] | null, message?: string) => void;
41
- 'lint-error': (filePath: string, sourceCode: string, error: Error) => void;
42
- 'config-errors': (filePath: string, errors: Error[]) => void;
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>[]];
43
40
  };