markuplint 2.0.0-rc.3 → 2.1.0

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 (71) hide show
  1. package/README.md +87 -30
  2. package/lib/api/index.d.mts +2 -0
  3. package/lib/api/index.mjs +2 -0
  4. package/lib/api/lint.d.mts +4 -0
  5. package/lib/api/lint.mjs +15 -0
  6. package/lib/api/ml-engine.d.mts +27 -0
  7. package/lib/api/ml-engine.js +7 -3
  8. package/lib/api/ml-engine.mjs +232 -0
  9. package/lib/api/types.d.mts +43 -0
  10. package/lib/api/types.d.ts +1 -1
  11. package/lib/api/types.mjs +1 -0
  12. package/lib/api/v1.d.mts +51 -0
  13. package/lib/api/v1.d.ts +0 -9
  14. package/lib/api/v1.js +0 -1
  15. package/lib/api/v1.mjs +39 -0
  16. package/lib/cli/bootstrap.d.mts +52 -0
  17. package/lib/cli/bootstrap.d.ts +24 -9
  18. package/lib/cli/bootstrap.js +39 -20
  19. package/lib/cli/bootstrap.mjs +81 -0
  20. package/lib/cli/command.d.mts +3 -0
  21. package/lib/cli/command.js +15 -2
  22. package/lib/cli/command.mjs +50 -0
  23. package/lib/cli/create-rule/index.d.mts +1 -0
  24. package/lib/cli/create-rule/index.js +4 -1
  25. package/lib/cli/create-rule/index.mjs +51 -0
  26. package/lib/cli/index.d.mts +1 -0
  27. package/lib/cli/index.mjs +64 -0
  28. package/lib/cli/index.spec.d.mts +1 -0
  29. package/lib/cli/index.spec.mjs +48 -0
  30. package/lib/cli/init/index.d.mts +1 -0
  31. package/lib/cli/init/index.js +92 -55
  32. package/lib/cli/init/index.mjs +266 -0
  33. package/lib/cli/init/install-module.d.mts +5 -0
  34. package/lib/cli/init/install-module.mjs +61 -0
  35. package/lib/cli/output.d.mts +3 -0
  36. package/lib/cli/output.mjs +31 -0
  37. package/lib/cli/prompt.d.mts +18 -0
  38. package/lib/cli/prompt.mjs +68 -0
  39. package/lib/debug.d.mts +3 -0
  40. package/lib/debug.mjs +10 -0
  41. package/lib/global-settings.d.mts +5 -0
  42. package/lib/global-settings.mjs +10 -0
  43. package/lib/i18n.d.mts +6 -0
  44. package/lib/i18n.mjs +19 -0
  45. package/lib/index.d.mts +8 -0
  46. package/lib/index.mjs +8 -0
  47. package/lib/reporter/index.d.mts +2 -0
  48. package/lib/reporter/index.mjs +2 -0
  49. package/lib/reporter/simple-reporter.d.mts +3 -0
  50. package/lib/reporter/simple-reporter.js +7 -7
  51. package/lib/reporter/simple-reporter.mjs +30 -0
  52. package/lib/reporter/standard-reporter.d.mts +3 -0
  53. package/lib/reporter/standard-reporter.js +10 -10
  54. package/lib/reporter/standard-reporter.mjs +43 -0
  55. package/lib/testing-tool/index.d.mts +35 -0
  56. package/lib/testing-tool/index.js +2 -0
  57. package/lib/testing-tool/index.mjs +83 -0
  58. package/lib/types.d.mts +27 -0
  59. package/lib/types.mjs +1 -0
  60. package/lib/util.d.mts +19 -0
  61. package/lib/util.d.ts +16 -0
  62. package/lib/util.js +75 -1
  63. package/lib/util.mjs +73 -0
  64. package/lib/v1.d.mts +4 -0
  65. package/lib/v1.mjs +4 -0
  66. package/media/screenshot01.png +0 -0
  67. package/package.json +14 -14
  68. package/tsconfig.tsbuildinfo +1 -1
  69. package/RESOLVE_CONFIG.md +0 -77
  70. package/lib/reporter/utils.d.ts +0 -6
  71. package/lib/reporter/utils.js +0 -40
package/README.md CHANGED
@@ -1,26 +1,65 @@
1
1
  # ![markuplint](https://cdn.rawgit.com/YusukeHirao/markuplint/HEAD/media/logo-v.svg)
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/markuplint.svg)](https://badge.fury.io/js/markuplint)
4
- [![Build Status](https://travis-ci.org/markuplint/markuplint.svg?branch=main)](https://travis-ci.org/markuplint/markuplint) [![Coverage Status](https://coveralls.io/repos/github/markuplint/markuplint/badge.svg?branch=main)](https://coveralls.io/github/markuplint/markuplint?branch=main)
4
+ [![Test](https://github.com/markuplint/markuplint/workflows/Test/badge.svg?branch=main)](https://github.com/markuplint/markuplint/actions?query=workflow%3ATest)
5
+ [![Coverage Status](https://coveralls.io/repos/github/markuplint/markuplint/badge.svg?branch=main)](https://coveralls.io/github/markuplint/markuplint?branch=main)
5
6
 
6
- A Linter for All Markup Languages (for legacy/modern HTML, Web Components, SVG, MathML, AMP HTML and more).
7
+ Peace of mind in your markup - A Linter for All Markup Languages.
7
8
 
8
- ## Install
9
+ ## Features
10
+
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.
16
+
17
+ ![Screenshot: Violation Report CLI output](https://raw.githubusercontent.com/markuplint/markuplint/main/packages/markuplint/media/screenshot01.png)
18
+
19
+ ## Instant using
9
20
 
10
21
  ```
11
- $ npm install -D markuplint
12
- $ yarn add -D markuplint
22
+ $ npx markuplint target.html
13
23
  ```
14
24
 
15
25
  Supported for _Node.js_ `v12.4.0` or later.
16
26
 
17
27
  ## Usage
18
28
 
19
- ### CLI
29
+ ### Initialization
30
+
31
+ Create a [configuration](https://markuplint.dev/configuration) file and install dependencies.
32
+
33
+ ```
34
+ $ npx markuplint --init
35
+ # or
36
+ $ yarn run markuplint --init
37
+ ```
38
+
39
+ Answer questions interactively.
40
+ By doing this, needed modules are installed includes `markuplint`.
41
+
42
+ Add a command to the `scripts` option on `package.json`:
20
43
 
44
+ ```json
45
+ {
46
+ "scripts": {
47
+ "html:lint": "markuplint **/*.html"
48
+ }
49
+ }
21
50
  ```
22
- $ npx markuplint verifyee.html
51
+
52
+ If you want to change the target path, you can change it for your project.
53
+
54
+ Execute the script:
55
+
23
56
  ```
57
+ $ npm run html:lint
58
+ # or
59
+ $ yarn html:lint
60
+ ```
61
+
62
+ ### Command line options
24
63
 
25
64
  ```
26
65
  $ npx markuplint --help
@@ -30,42 +69,60 @@ Usage
30
69
  $ <stdout> | markuplint
31
70
 
32
71
  Options
33
- --config-file, -c FILE_PATH Ruleset file path.
34
- --fix, Fix HTML.
35
- --format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
36
- --no-color, Output no color.
37
- --problem-only, -p Output only problems, without passeds.
38
- --verbose Output with detailed information.
39
-
40
- --help, -h Show help.
41
- --version, -v Show version.
72
+ --config, -c FILE_PATH A configuration file path.
73
+ --fix, Fix HTML.
74
+ --format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
75
+ --no-search-config No search a configure file automatically.
76
+ --ignore-ext Evaluate files that are received even though the type of extension.
77
+ --no-import-preset-rules No import preset rules.
78
+ --locale Locale of the message of violation. Default is an OS setting.
79
+ --no-color, Output no color.
80
+ --problem-only, -p Output only problems, without passeds.
81
+ --verbose Output with detailed information.
82
+
83
+ --init Initialize settings interactively.
84
+ --create-rule Add the scaffold of a custom rule.
85
+
86
+ --help, -h Show help.
87
+ --version, -v Show version.
42
88
 
43
89
  Examples
44
- $ markuplint verifyee.html --ruleset path/to/.markuplintrc
90
+ $ markuplint verifyee.html --config path/to/.markuplintrc
45
91
  $ cat verifyee.html | markuplint
46
92
  ```
47
93
 
48
- ![Screen shot](media/screenshot01.png)
94
+ ## Guideline
95
+
96
+ - [Getting Started](https://markuplint.dev/getting-started)
97
+ - [Rules](https://markuplint.dev/rules)
98
+ - [Configuration](https://markuplint.dev/configuration)
99
+ - [API](https://markuplint.dev/api-docs)
100
+ - [Playground](https://playground.markuplint.dev/)
101
+
102
+ ## Editor Extensions
103
+
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) |
49
107
 
50
- ### API
108
+ ## License
51
109
 
52
- - [Functions](https://markuplint.dev/api-docs#Functions)
53
- - [Interface Document](https://api.markuplint.dev) (genereated by [TypeDoc](https://typedoc.org/))
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)
54
111
 
55
- ## Configuration
112
+ ## Sponsors
56
113
 
57
- - [Configuration](https://markuplint.dev/configuration)
114
+ [:heart: Sponsor](https://github.com/sponsors/markuplint)
58
115
 
59
- ## Rules
116
+ ### Personal Supporters
60
117
 
61
- - [Rules](https://markuplint.dev/rules)
62
- - Customizing your rule **🚧 WIP**
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)
63
120
 
64
121
  ## Thanks
65
122
 
66
123
  This linter is inspired by:
67
124
 
68
- - [HTMLHint](http://htmlhint.com/)
69
- - [ESLint](https://eslint.org/)
70
- - [stylelint](https://stylelint.io/)
71
- - [textlint](https://textlint.github.io/)
125
+ - [HTMLHint](http://htmlhint.com/)
126
+ - [ESLint](https://eslint.org/)
127
+ - [stylelint](https://stylelint.io/)
128
+ - [textlint](https://textlint.github.io/)
@@ -0,0 +1,2 @@
1
+ export { default as MLEngine } from './ml-engine.mjs';
2
+ export { lint } from './lint.mjs';
@@ -0,0 +1,2 @@
1
+ export { default as MLEngine } from './ml-engine.mjs';
2
+ export { lint } from './lint.mjs';
@@ -0,0 +1,4 @@
1
+ import type { MLResultInfo } from '../types.mjs';
2
+ import type { APIOptions } from './types.mjs';
3
+ import type { Target } from '@markuplint/file-resolver';
4
+ export declare function lint(targetList: Target[], options?: APIOptions): Promise<MLResultInfo[]>;
@@ -0,0 +1,15 @@
1
+ import { resolveFiles } from '@markuplint/file-resolver';
2
+ import MLEngine from './ml-engine.mjs';
3
+ export async function lint(targetList, options) {
4
+ const res = [];
5
+ const files = await resolveFiles(targetList);
6
+ for (const file of files) {
7
+ const engine = new MLEngine(file, options);
8
+ const result = await engine.exec();
9
+ if (!result) {
10
+ continue;
11
+ }
12
+ res.push(result);
13
+ }
14
+ return res;
15
+ }
@@ -0,0 +1,27 @@
1
+ import type { MLResultInfo } from '../types.mjs';
2
+ import type { APIOptions, MLEngineEventMap } from './types.mjs';
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;
8
+ };
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
+ exec(): Promise<MLResultInfo | null>;
14
+ setCode(code: string): Promise<void>;
15
+ close(): Promise<void>;
16
+ private setup;
17
+ private provide;
18
+ private cretateCore;
19
+ private resolveConfig;
20
+ private resolveParser;
21
+ private resolveRuleset;
22
+ private resolveSchemas;
23
+ private resolveRules;
24
+ private i18n;
25
+ private watch;
26
+ }
27
+ export {};
@@ -113,6 +113,10 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
113
113
  fileLog('Resolved Config: %O', configSet.config);
114
114
  fileLog('Resolved Plugins: %O', configSet.plugins);
115
115
  fileLog('Resolve Errors: %O', configSet.errs);
116
+ if (!(await (0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_file, "f").isFile())) {
117
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${(0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_file, "f").path}`);
118
+ return null;
119
+ }
116
120
  // Exclude
117
121
  const excludeFiles = configSet.config.excludeFiles || [];
118
122
  for (const excludeFile of excludeFiles) {
@@ -122,9 +126,9 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
122
126
  }
123
127
  }
124
128
  const { parser, parserOptions, matched } = await this.resolveParser(configSet);
125
- // Ext Matching
126
- if (((_a = (0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.extMatch) && !matched && !(0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_file, "f").path.match(/\.html?$/i)) {
127
- this.emit('log', 'extension-matching', `${(0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_file, "f").path}`);
129
+ const checkingExt = !((_a = (0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.ignoreExt);
130
+ if (checkingExt && !matched) {
131
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${(0, tslib_1.__classPrivateFieldGet)(this, _MLEngine_file, "f").path}`);
128
132
  return null;
129
133
  }
130
134
  const ruleset = this.resolveRuleset(configSet);
@@ -0,0 +1,232 @@
1
+ var _MLEngine_file, _MLEngine_options, _MLEngine_core, _MLEngine_watcher;
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 { StrictEventEmitter } from 'strict-event-emitter';
7
+ import { log as coreLog, verbosely } from '../debug.mjs';
8
+ import { i18n } from '../i18n.mjs';
9
+ const log = coreLog.extend('ml-engine');
10
+ const fileLog = log.extend('file');
11
+ export default class MLEngine extends StrictEventEmitter {
12
+ constructor(file, options) {
13
+ super();
14
+ _MLEngine_file.set(this, void 0);
15
+ _MLEngine_options.set(this, void 0);
16
+ _MLEngine_core.set(this, null);
17
+ _MLEngine_watcher.set(this, new FSWatcher());
18
+ __classPrivateFieldSet(this, _MLEngine_file, file, "f");
19
+ __classPrivateFieldSet(this, _MLEngine_options, options, "f");
20
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
21
+ verbosely();
22
+ }
23
+ if (options?.watch) {
24
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").on('all', this.watch.bind(this));
25
+ }
26
+ else {
27
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
28
+ }
29
+ }
30
+ static async toMLFile(target) {
31
+ const files = await resolveFiles([target]);
32
+ return files[0];
33
+ }
34
+ async exec() {
35
+ log('exec: start');
36
+ const core = await this.setup();
37
+ if (!core) {
38
+ log('exec: cancel (unsetuped yet)');
39
+ return null;
40
+ }
41
+ const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(e => {
42
+ if (e instanceof Error) {
43
+ return e;
44
+ }
45
+ throw e;
46
+ });
47
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
48
+ const fixedCode = core.document.toString();
49
+ if (violations instanceof Error) {
50
+ this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
51
+ const errMessage = violations.stack ?? violations.message;
52
+ log('exec: error %O', errMessage);
53
+ return {
54
+ violations: [
55
+ {
56
+ severity: 'error',
57
+ message: errMessage,
58
+ ruleId: '@markuplint/ml-core',
59
+ line: 0,
60
+ col: 0,
61
+ raw: '',
62
+ },
63
+ ],
64
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
65
+ sourceCode,
66
+ fixedCode,
67
+ };
68
+ }
69
+ const debugMap = ('debugMap' in core.document && core.document.debugMap()) || null;
70
+ this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
71
+ log('exec: end');
72
+ return {
73
+ violations,
74
+ filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
75
+ sourceCode,
76
+ fixedCode,
77
+ };
78
+ }
79
+ async setCode(code) {
80
+ const core = await this.setup();
81
+ if (!core) {
82
+ return;
83
+ }
84
+ __classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
85
+ core.setCode(code);
86
+ }
87
+ async close() {
88
+ this.removeAllListeners();
89
+ await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
90
+ }
91
+ async setup() {
92
+ if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
93
+ return __classPrivateFieldGet(this, _MLEngine_core, "f");
94
+ }
95
+ const fabric = await this.provide(false);
96
+ if (!fabric) {
97
+ return null;
98
+ }
99
+ if (fabric.configErrors) {
100
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
101
+ }
102
+ const core = this.cretateCore(fabric);
103
+ return core;
104
+ }
105
+ async provide(remerge) {
106
+ const configSet = await this.resolveConfig(remerge);
107
+ fileLog('Fetched Config files: %O', configSet.files);
108
+ fileLog('Resolved Config: %O', configSet.config);
109
+ fileLog('Resolved Plugins: %O', configSet.plugins);
110
+ fileLog('Resolve Errors: %O', configSet.errs);
111
+ if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
112
+ this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
113
+ return null;
114
+ }
115
+ // Exclude
116
+ const excludeFiles = configSet.config.excludeFiles || [];
117
+ for (const excludeFile of excludeFiles) {
118
+ if (__classPrivateFieldGet(this, _MLEngine_file, "f").matches(excludeFile)) {
119
+ this.emit('exclude', __classPrivateFieldGet(this, _MLEngine_file, "f").path, excludeFile);
120
+ return null;
121
+ }
122
+ }
123
+ const { parser, parserOptions, matched } = await this.resolveParser(configSet);
124
+ const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
125
+ if (checkingExt && !matched) {
126
+ this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
127
+ return null;
128
+ }
129
+ const ruleset = this.resolveRuleset(configSet);
130
+ fileLog('Resolved ruleset: %O', ruleset);
131
+ const schemas = await this.resolveSchemas(configSet);
132
+ if (fileLog.enabled) {
133
+ if (schemas[0].cites.length) {
134
+ const [, ...additionalSpecs] = schemas;
135
+ fileLog('Resolved schemas: HTML Standard');
136
+ for (const additionalSpec of additionalSpecs) {
137
+ fileLog('Resolved schemas: %O', additionalSpec);
138
+ }
139
+ }
140
+ else {
141
+ fileLog('Resolved schemas: %O', schemas);
142
+ }
143
+ }
144
+ const rules = await this.resolveRules(configSet.plugins, ruleset);
145
+ fileLog('Resolved rules: %O', rules);
146
+ const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
147
+ if (fileLog.enabled) {
148
+ fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
149
+ }
150
+ return {
151
+ parser,
152
+ parserOptions,
153
+ ruleset,
154
+ schemas,
155
+ rules,
156
+ locale,
157
+ configErrors: configSet.errs,
158
+ };
159
+ }
160
+ async cretateCore(fabric) {
161
+ fileLog('Get source code');
162
+ const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
163
+ fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
164
+ fileLog('Source code size: %dbyte', sourceCode.length);
165
+ this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
166
+ const core = new MLCore({
167
+ sourceCode,
168
+ filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
169
+ debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
170
+ ...fabric,
171
+ });
172
+ __classPrivateFieldSet(this, _MLEngine_core, core, "f");
173
+ return core;
174
+ }
175
+ async resolveConfig(remerge) {
176
+ const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
177
+ ? null
178
+ : await configProvider.search(__classPrivateFieldGet(this, _MLEngine_file, "f"));
179
+ this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget || 'null');
180
+ const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && configProvider.set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
181
+ this.emit('log', 'configKey', configKey || 'null');
182
+ const configSet = await configProvider.resolve([configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey], remerge);
183
+ this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
184
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
185
+ __classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
186
+ }
187
+ return configSet;
188
+ }
189
+ async resolveParser(configSet) {
190
+ const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
191
+ this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
192
+ fileLog('Fetched Parser module: %s', parser.parserModName);
193
+ return parser;
194
+ }
195
+ resolveRuleset(configSet) {
196
+ const ruleset = convertRuleset(configSet.config);
197
+ this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
198
+ return ruleset;
199
+ }
200
+ async resolveSchemas(configSet) {
201
+ const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
202
+ this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
203
+ return schemas;
204
+ }
205
+ async resolveRules(plugins, ruleset) {
206
+ const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
207
+ if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
208
+ rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
209
+ }
210
+ this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
211
+ return rules;
212
+ }
213
+ async i18n() {
214
+ const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
215
+ this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
216
+ return i18nSettings;
217
+ }
218
+ async watch(type, filePath) {
219
+ this.emit('log', `watch:${type}`, filePath);
220
+ const fabric = await this.provide(true);
221
+ if (!fabric) {
222
+ return;
223
+ }
224
+ if (fabric.configErrors) {
225
+ this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
226
+ }
227
+ this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
228
+ __classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
229
+ this.exec();
230
+ }
231
+ }
232
+ _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_watcher = new WeakMap();
@@ -0,0 +1,43 @@
1
+ import type { ConfigSet } from '@markuplint/file-resolver';
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';
5
+ 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;
20
+ };
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;
43
+ };
@@ -10,7 +10,7 @@ export declare type APIOptions = {
10
10
  noSearchConfig?: boolean;
11
11
  locale?: string;
12
12
  fix?: boolean;
13
- extMatch?: boolean;
13
+ ignoreExt?: boolean;
14
14
  rules?: AnyMLRule[];
15
15
  importPresetRules?: boolean;
16
16
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import type { Config, RuleConfigValue } from '@markuplint/ml-config';
2
+ import type { MLRule } from '@markuplint/ml-core';
3
+ /**
4
+ * @deprecated
5
+ * @param options
6
+ * @returns
7
+ */
8
+ export declare function lint_v1(options: {
9
+ /**
10
+ * Glob pattern
11
+ */
12
+ files?: string | string[];
13
+ /**
14
+ * Target source code of evaluation
15
+ */
16
+ sourceCodes?: string | string[];
17
+ /**
18
+ * File names when `sourceCodes`
19
+ */
20
+ names?: string | string[];
21
+ /**
22
+ * Workspace path when `sourceCodes`
23
+ */
24
+ workspace?: string;
25
+ /**
26
+ * Configure file or object
27
+ */
28
+ config?: string | Config;
29
+ /**
30
+ * The config applied when not resolved from files or set it explicitly.
31
+ */
32
+ defaultConfig?: Config;
33
+ /**
34
+ * Rules (default: `@markuplint/rules`)
35
+ */
36
+ rules?: MLRule<RuleConfigValue, unknown>[];
37
+ /**
38
+ * Auto resolve rules
39
+ *
40
+ * Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
41
+ */
42
+ rulesAutoResolve?: boolean;
43
+ /**
44
+ * Auto fix
45
+ */
46
+ fix?: boolean;
47
+ /**
48
+ * Locale
49
+ */
50
+ locale?: string;
51
+ }): Promise<import("../types.mjs").MLResultInfo[]>;
package/lib/api/v1.d.ts CHANGED
@@ -48,13 +48,4 @@ export declare function lint_v1(options: {
48
48
  * Locale
49
49
  */
50
50
  locale?: string;
51
- /**
52
- * Confirm the extension of the target file to the regexp of parser plugins.
53
- * It doesn't run the linting if it doesn't match.
54
- * If you don't set a parser plugin and the target file is HTML, It confirms the regexp as `/\.html?$/i`.
55
- * Default is false.
56
- *
57
- * @default false
58
- */
59
- extMatch?: boolean;
60
51
  }): Promise<import("..").MLResultInfo[]>;
package/lib/api/v1.js CHANGED
@@ -40,7 +40,6 @@ async function lint_v1(options) {
40
40
  noSearchConfig: !options.files,
41
41
  rules: options.rules,
42
42
  autoLoad: (_a = options.rulesAutoResolve) !== null && _a !== void 0 ? _a : true,
43
- extMatch: options.extMatch,
44
43
  locale: options.locale,
45
44
  });
46
45
  return result;
package/lib/api/v1.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { lint } from './lint.mjs';
2
+ /**
3
+ * @deprecated
4
+ * @param options
5
+ * @returns
6
+ */
7
+ export async function lint_v1(options) {
8
+ const filePathList = options.files ? (Array.isArray(options.files) ? options.files : [options.files]) : [];
9
+ const codes = options.sourceCodes
10
+ ? Array.isArray(options.sourceCodes)
11
+ ? options.sourceCodes
12
+ : [options.sourceCodes]
13
+ : [];
14
+ const files = [
15
+ ...filePathList,
16
+ ...codes.map((code, i) => ({
17
+ sourceCode: code,
18
+ name: Array.isArray(options.names) ? options.names?.[i] : options.names,
19
+ workspace: options.workspace?.[i],
20
+ })),
21
+ ];
22
+ let config;
23
+ let configFile;
24
+ if (typeof options.config === 'string') {
25
+ configFile = options.config;
26
+ }
27
+ else if (options.config) {
28
+ config = options.config;
29
+ }
30
+ const result = await lint(files, {
31
+ config,
32
+ configFile,
33
+ noSearchConfig: !options.files,
34
+ rules: options.rules,
35
+ autoLoad: options.rulesAutoResolve ?? true,
36
+ locale: options.locale,
37
+ });
38
+ return result;
39
+ }