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