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.
- package/README.md +87 -30
- package/lib/api/index.d.mts +2 -0
- package/lib/api/index.mjs +2 -0
- package/lib/api/lint.d.mts +4 -0
- package/lib/api/lint.mjs +15 -0
- package/lib/api/ml-engine.d.mts +27 -0
- package/lib/api/ml-engine.js +7 -3
- package/lib/api/ml-engine.mjs +232 -0
- package/lib/api/types.d.mts +43 -0
- package/lib/api/types.d.ts +1 -1
- package/lib/api/types.mjs +1 -0
- package/lib/api/v1.d.mts +51 -0
- package/lib/api/v1.d.ts +0 -9
- package/lib/api/v1.js +0 -1
- package/lib/api/v1.mjs +39 -0
- package/lib/cli/bootstrap.d.mts +52 -0
- package/lib/cli/bootstrap.d.ts +24 -9
- package/lib/cli/bootstrap.js +39 -20
- package/lib/cli/bootstrap.mjs +81 -0
- package/lib/cli/command.d.mts +3 -0
- package/lib/cli/command.js +15 -2
- package/lib/cli/command.mjs +50 -0
- package/lib/cli/create-rule/index.d.mts +1 -0
- package/lib/cli/create-rule/index.js +4 -1
- package/lib/cli/create-rule/index.mjs +51 -0
- package/lib/cli/index.d.mts +1 -0
- package/lib/cli/index.mjs +64 -0
- package/lib/cli/index.spec.d.mts +1 -0
- package/lib/cli/index.spec.mjs +48 -0
- package/lib/cli/init/index.d.mts +1 -0
- package/lib/cli/init/index.js +92 -55
- package/lib/cli/init/index.mjs +266 -0
- package/lib/cli/init/install-module.d.mts +5 -0
- package/lib/cli/init/install-module.mjs +61 -0
- package/lib/cli/output.d.mts +3 -0
- package/lib/cli/output.mjs +31 -0
- package/lib/cli/prompt.d.mts +18 -0
- package/lib/cli/prompt.mjs +68 -0
- package/lib/debug.d.mts +3 -0
- package/lib/debug.mjs +10 -0
- package/lib/global-settings.d.mts +5 -0
- package/lib/global-settings.mjs +10 -0
- package/lib/i18n.d.mts +6 -0
- package/lib/i18n.mjs +19 -0
- package/lib/index.d.mts +8 -0
- package/lib/index.mjs +8 -0
- package/lib/reporter/index.d.mts +2 -0
- package/lib/reporter/index.mjs +2 -0
- package/lib/reporter/simple-reporter.d.mts +3 -0
- package/lib/reporter/simple-reporter.js +7 -7
- package/lib/reporter/simple-reporter.mjs +30 -0
- package/lib/reporter/standard-reporter.d.mts +3 -0
- package/lib/reporter/standard-reporter.js +10 -10
- package/lib/reporter/standard-reporter.mjs +43 -0
- package/lib/testing-tool/index.d.mts +35 -0
- package/lib/testing-tool/index.js +2 -0
- package/lib/testing-tool/index.mjs +83 -0
- package/lib/types.d.mts +27 -0
- package/lib/types.mjs +1 -0
- package/lib/util.d.mts +19 -0
- package/lib/util.d.ts +16 -0
- package/lib/util.js +75 -1
- package/lib/util.mjs +73 -0
- package/lib/v1.d.mts +4 -0
- package/lib/v1.mjs +4 -0
- package/media/screenshot01.png +0 -0
- package/package.json +14 -14
- package/tsconfig.tsbuildinfo +1 -1
- package/RESOLVE_CONFIG.md +0 -77
- package/lib/reporter/utils.d.ts +0 -6
- package/lib/reporter/utils.js +0 -40
package/README.md
CHANGED
|
@@ -1,26 +1,65 @@
|
|
|
1
1
|
# 
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/markuplint)
|
|
4
|
-
[](https://github.com/markuplint/markuplint/actions?query=workflow%3ATest)
|
|
5
|
+
[](https://coveralls.io/github/markuplint/markuplint?branch=main)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
Peace of mind in your markup - A Linter for All Markup Languages.
|
|
7
8
|
|
|
8
|
-
##
|
|
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
|
+

|
|
18
|
+
|
|
19
|
+
## Instant using
|
|
9
20
|
|
|
10
21
|
```
|
|
11
|
-
$
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
|
34
|
-
--fix,
|
|
35
|
-
--format,
|
|
36
|
-
--no-
|
|
37
|
-
--
|
|
38
|
-
--
|
|
39
|
-
|
|
40
|
-
--
|
|
41
|
-
--
|
|
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 --
|
|
90
|
+
$ markuplint verifyee.html --config path/to/.markuplintrc
|
|
45
91
|
$ cat verifyee.html | markuplint
|
|
46
92
|
```
|
|
47
93
|
|
|
48
|
-
|
|
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
|
-
|
|
108
|
+
## License
|
|
51
109
|
|
|
52
|
-
|
|
53
|
-
- [Interface Document](https://api.markuplint.dev) (genereated by [TypeDoc](https://typedoc.org/))
|
|
110
|
+
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmarkuplint%2Fmarkuplint?ref=badge_large)
|
|
54
111
|
|
|
55
|
-
##
|
|
112
|
+
## Sponsors
|
|
56
113
|
|
|
57
|
-
|
|
114
|
+
[:heart: Sponsor](https://github.com/sponsors/markuplint)
|
|
58
115
|
|
|
59
|
-
|
|
116
|
+
### Personal Supporters
|
|
60
117
|
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
125
|
+
- [HTMLHint](http://htmlhint.com/)
|
|
126
|
+
- [ESLint](https://eslint.org/)
|
|
127
|
+
- [stylelint](https://stylelint.io/)
|
|
128
|
+
- [textlint](https://textlint.github.io/)
|
package/lib/api/lint.mjs
ADDED
|
@@ -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 {};
|
package/lib/api/ml-engine.js
CHANGED
|
@@ -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
|
-
|
|
126
|
-
if (
|
|
127
|
-
this.emit('log', '
|
|
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
|
+
};
|
package/lib/api/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/api/v1.d.mts
ADDED
|
@@ -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
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
|
+
}
|