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