markuplint 3.15.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/README.md +4 -2
- 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 +2 -2
- package/lib/api/lint.js +5 -10
- package/lib/api/ml-engine.d.ts +28 -23
- package/lib/api/ml-engine.js +123 -103
- package/lib/api/types.d.ts +32 -32
- package/lib/api/types.js +1 -2
- package/lib/api/v1.d.ts +43 -43
- package/lib/api/v1.js +12 -20
- package/lib/cli/bootstrap.d.ts +65 -63
- package/lib/cli/bootstrap.js +12 -11
- package/lib/cli/command.d.ts +3 -7
- package/lib/cli/command.js +26 -34
- package/lib/cli/index.js +59 -71
- package/lib/cli/init/create-config.d.ts +2 -6
- package/lib/cli/init/create-config.js +14 -12
- package/lib/cli/init/get-default-rules.d.ts +3 -3
- package/lib/cli/init/get-default-rules.js +12 -53
- package/lib/cli/init/index.js +28 -37
- package/lib/cli/init/select-modules.d.ts +2 -0
- package/lib/cli/init/select-modules.js +10 -0
- package/lib/cli/init/types.d.ts +4 -15
- package/lib/cli/init/types.js +1 -2
- package/lib/cli/output.d.ts +2 -2
- package/lib/cli/output.js +8 -14
- package/lib/cli/search/index.d.ts +2 -2
- package/lib/cli/search/index.js +10 -14
- package/lib/debug.js +9 -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 +8 -15
- package/lib/index.d.ts +7 -5
- package/lib/index.js +6 -10
- package/lib/reporter/github-reporter.d.ts +1 -1
- package/lib/reporter/github-reporter.js +7 -9
- package/lib/reporter/index.d.ts +3 -3
- package/lib/reporter/index.js +3 -6
- package/lib/reporter/simple-reporter.d.ts +2 -2
- package/lib/reporter/simple-reporter.js +11 -16
- package/lib/reporter/standard-reporter.d.ts +2 -2
- package/lib/reporter/standard-reporter.js +37 -28
- package/lib/testing-tool/index.d.ts +23 -41
- package/lib/testing-tool/index.js +41 -47
- package/lib/types.d.ts +17 -17
- package/lib/types.js +1 -2
- 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 +26 -34
- package/bin/markuplint +0 -3
- package/lib/cli/create-rule/index.d.ts +0 -1
- package/lib/cli/create-rule/index.js +0 -85
- package/lib/cli/init/install-module.d.ts +0 -7
- package/lib/cli/init/install-module.js +0 -80
- package/lib/cli/prompt.d.ts +0 -23
- package/lib/cli/prompt.js +0 -77
- package/lib/util.d.ts +0 -17
- package/lib/util.js +0 -88
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
$ npx markuplint target.html
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Supported for _Node.js_ `
|
|
28
|
+
Supported for _Node.js_ `v18.18.0` or later.
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
@@ -83,9 +83,9 @@ Options
|
|
|
83
83
|
--no-color, Output no color.
|
|
84
84
|
--problem-only, -p Output only problems, without passeds.
|
|
85
85
|
--verbose Output with detailed information.
|
|
86
|
+
--include-node-modules Include files in node_modules directory. Default: false.
|
|
86
87
|
|
|
87
88
|
--init Initialize settings interactively.
|
|
88
|
-
--create-rule Add the scaffold of a custom rule.
|
|
89
89
|
|
|
90
90
|
--help, -h Show help.
|
|
91
91
|
--version, -v Show version.
|
|
@@ -125,6 +125,8 @@ Need [Sponsors❤️🔥](https://github.com/sponsors/markuplint)
|
|
|
125
125
|
[<img width="36" src="https://avatars.githubusercontent.com/u/6581173" alt="miita" />](https://github.com/mikimhk)
|
|
126
126
|
[<img width="36" src="https://avatars.githubusercontent.com/u/111797" alt="Yasuo Fukuda" />](https://github.com/sigwyg)
|
|
127
127
|
[<img width="36" src="https://avatars.githubusercontent.com/u/802921" alt="Hideyuki Saito" />](https://github.com/hideyukisaito)
|
|
128
|
+
[<img width="36" src="https://avatars.githubusercontent.com/u/3056064" alt="tamshow" />](https://github.com/tamshow)
|
|
129
|
+
[<img width="36" src="https://avatars.githubusercontent.com/u/91047157" alt="shamokit" />](https://github.com/shamokit)
|
|
128
130
|
|
|
129
131
|
## Thanks
|
|
130
132
|
|
package/lib/api/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { lint } from './lint';
|
|
1
|
+
export { 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 { 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 { APIOptions } from './types';
|
|
2
|
-
import type { MLResultInfo } from '../types';
|
|
1
|
+
import type { APIOptions } from './types.js';
|
|
2
|
+
import type { MLResultInfo } from '../types.js';
|
|
3
3
|
import type { Target } from '@markuplint/file-resolver';
|
|
4
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,31 +1,36 @@
|
|
|
1
|
-
import type { APIOptions, MLEngineEventMap } from './types';
|
|
2
|
-
import type { MLResultInfo } from '../types';
|
|
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
4
|
import type { PlainData } from '@markuplint/ml-config';
|
|
5
5
|
import type { Document, RuleConfigValue } from '@markuplint/ml-core';
|
|
6
6
|
import { Emitter } from 'strict-event-emitter';
|
|
7
7
|
type MLEngineOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
readonly debug?: boolean;
|
|
9
|
+
readonly watch?: boolean;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
export type FromCodeOptions = APIOptions & MLEngineOptions & {
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
readonly dirname?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class MLEngine extends Emitter<MLEngineEventMap> {
|
|
16
|
+
#private;
|
|
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;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
exec(): Promise<MLResultInfo | null>;
|
|
23
|
+
setCode(code: string): Promise<void>;
|
|
24
|
+
watchMode(enable: boolean): void;
|
|
25
|
+
private createCore;
|
|
26
|
+
private i18n;
|
|
27
|
+
private onChange;
|
|
28
|
+
private provide;
|
|
29
|
+
private resolveConfig;
|
|
30
|
+
private resolveParser;
|
|
31
|
+
private resolveRules;
|
|
32
|
+
private resolveRuleset;
|
|
33
|
+
private resolveSchemas;
|
|
34
|
+
private setup;
|
|
30
35
|
}
|
|
31
36
|
export {};
|
package/lib/api/ml-engine.js
CHANGED
|
@@ -1,67 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
2
12
|
var _MLEngine_configProvider, _MLEngine_core, _MLEngine_file, _MLEngine_options, _MLEngine_watcher;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const i18n_1 = require("../i18n");
|
|
11
|
-
const log = debug_1.log.extend('ml-engine');
|
|
13
|
+
import { ConfigProvider, resolveFiles, resolveParser, resolveRules, resolveSpecs } from '@markuplint/file-resolver';
|
|
14
|
+
import { MLCore, convertRuleset } from '@markuplint/ml-core';
|
|
15
|
+
import { FSWatcher } from 'chokidar';
|
|
16
|
+
import { Emitter } from 'strict-event-emitter';
|
|
17
|
+
import { log as coreLog, verbosely } from '../debug.js';
|
|
18
|
+
import { i18n } from '../i18n.js';
|
|
19
|
+
const log = coreLog.extend('ml-engine');
|
|
12
20
|
const fileLog = log.extend('file');
|
|
13
21
|
const configLog = log.extend('config');
|
|
14
|
-
class MLEngine extends
|
|
22
|
+
export class MLEngine extends Emitter {
|
|
23
|
+
static async fromCode(sourceCode, options) {
|
|
24
|
+
if (options?.debug) {
|
|
25
|
+
verbosely();
|
|
26
|
+
}
|
|
27
|
+
log('[fromCode] Creates: %O', options);
|
|
28
|
+
const file = await MLEngine.toMLFile({
|
|
29
|
+
sourceCode,
|
|
30
|
+
name: options?.name,
|
|
31
|
+
workspace: options?.dirname,
|
|
32
|
+
});
|
|
33
|
+
if (!file) {
|
|
34
|
+
throw new Error('Never reach error');
|
|
35
|
+
}
|
|
36
|
+
log('[fromCode] Created file: %s', file.path);
|
|
37
|
+
const engine = new MLEngine(file, options);
|
|
38
|
+
return engine;
|
|
39
|
+
}
|
|
15
40
|
static async toMLFile(target) {
|
|
16
|
-
const files = await
|
|
41
|
+
const files = await resolveFiles([target]);
|
|
17
42
|
return files[0];
|
|
18
43
|
}
|
|
19
44
|
constructor(file, options) {
|
|
20
|
-
var _a, _b;
|
|
21
45
|
super();
|
|
22
46
|
_MLEngine_configProvider.set(this, void 0);
|
|
23
47
|
_MLEngine_core.set(this, null);
|
|
24
48
|
_MLEngine_file.set(this, void 0);
|
|
25
49
|
_MLEngine_options.set(this, void 0);
|
|
26
|
-
_MLEngine_watcher.set(this, new
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tslib_1.__classPrivateFieldSet(this, _MLEngine_configProvider, new file_resolver_1.ConfigProvider(), "f");
|
|
30
|
-
this.watchMode(!!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch));
|
|
31
|
-
if ((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.debug) {
|
|
32
|
-
(0, debug_1.verbosely)();
|
|
50
|
+
_MLEngine_watcher.set(this, new FSWatcher());
|
|
51
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
|
|
52
|
+
verbosely();
|
|
33
53
|
}
|
|
54
|
+
__classPrivateFieldSet(this, _MLEngine_file, file, "f");
|
|
55
|
+
__classPrivateFieldSet(this, _MLEngine_options, options, "f");
|
|
56
|
+
__classPrivateFieldSet(this, _MLEngine_configProvider, new ConfigProvider(), "f");
|
|
57
|
+
this.watchMode(!!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch);
|
|
58
|
+
log('[MLEngine] Initialized: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
34
59
|
}
|
|
35
60
|
get document() {
|
|
36
|
-
|
|
37
|
-
if (((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_core, "f")) === null || _a === void 0 ? void 0 : _a.document) instanceof Error) {
|
|
61
|
+
if (__classPrivateFieldGet(this, _MLEngine_core, "f")?.document instanceof Error) {
|
|
38
62
|
return null;
|
|
39
63
|
}
|
|
40
|
-
return
|
|
64
|
+
return __classPrivateFieldGet(this, _MLEngine_core, "f")?.document ?? null;
|
|
41
65
|
}
|
|
42
66
|
async close() {
|
|
43
67
|
this.removeAllListeners();
|
|
44
|
-
await
|
|
68
|
+
await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
|
|
45
69
|
}
|
|
46
70
|
async exec() {
|
|
47
|
-
var _a, _b;
|
|
48
71
|
log('exec: start');
|
|
49
72
|
const core = await this.setup();
|
|
50
73
|
if (!core) {
|
|
51
74
|
log('exec: cancel (unsetuped yet)');
|
|
52
75
|
return null;
|
|
53
76
|
}
|
|
54
|
-
const violations = await core.verify(
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
77
|
+
const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(error => {
|
|
78
|
+
if (error instanceof Error) {
|
|
79
|
+
return error;
|
|
57
80
|
}
|
|
58
|
-
throw
|
|
81
|
+
throw error;
|
|
59
82
|
});
|
|
60
|
-
const sourceCode = await
|
|
61
|
-
const fixedCode = core.document.toString();
|
|
83
|
+
const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
|
|
84
|
+
const fixedCode = core.document.toString(true);
|
|
62
85
|
if (violations instanceof Error) {
|
|
63
|
-
this.emit('lint-error',
|
|
64
|
-
const errMessage =
|
|
86
|
+
this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
|
|
87
|
+
const errMessage = violations.stack ?? violations.message;
|
|
65
88
|
log('exec: error %O', errMessage);
|
|
66
89
|
return {
|
|
67
90
|
violations: [
|
|
@@ -74,17 +97,17 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
74
97
|
raw: '',
|
|
75
98
|
},
|
|
76
99
|
],
|
|
77
|
-
filePath:
|
|
100
|
+
filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
78
101
|
sourceCode,
|
|
79
102
|
fixedCode,
|
|
80
103
|
};
|
|
81
104
|
}
|
|
82
105
|
const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
|
|
83
|
-
this.emit('lint',
|
|
106
|
+
this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
|
|
84
107
|
log('exec: end');
|
|
85
108
|
return {
|
|
86
109
|
violations,
|
|
87
|
-
filePath:
|
|
110
|
+
filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
88
111
|
sourceCode,
|
|
89
112
|
fixedCode,
|
|
90
113
|
};
|
|
@@ -94,47 +117,44 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
94
117
|
if (!core) {
|
|
95
118
|
return;
|
|
96
119
|
}
|
|
97
|
-
|
|
120
|
+
__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
|
|
98
121
|
core.setCode(code);
|
|
99
122
|
}
|
|
100
123
|
watchMode(enable) {
|
|
101
|
-
|
|
102
|
-
...
|
|
124
|
+
__classPrivateFieldSet(this, _MLEngine_options, {
|
|
125
|
+
...__classPrivateFieldGet(this, _MLEngine_options, "f"),
|
|
103
126
|
watch: enable,
|
|
104
127
|
}, "f");
|
|
105
128
|
if (enable) {
|
|
106
|
-
|
|
129
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('change', this.onChange.bind(this));
|
|
107
130
|
}
|
|
108
131
|
else {
|
|
109
|
-
|
|
132
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").removeAllListeners();
|
|
110
133
|
}
|
|
111
134
|
}
|
|
112
135
|
async createCore(fabric) {
|
|
113
|
-
var _a;
|
|
114
136
|
fileLog('Get source code');
|
|
115
|
-
const sourceCode = await
|
|
116
|
-
fileLog('Source code path: %s',
|
|
137
|
+
const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
|
|
138
|
+
fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
117
139
|
// cspell: disable-next-line
|
|
118
140
|
fileLog('Source code size: %dbyte', sourceCode.length);
|
|
119
|
-
this.emit('code',
|
|
120
|
-
const core = new
|
|
141
|
+
this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
|
|
142
|
+
const core = new MLCore({
|
|
121
143
|
sourceCode,
|
|
122
|
-
filename:
|
|
123
|
-
debug:
|
|
144
|
+
filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
145
|
+
debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
|
|
124
146
|
...fabric,
|
|
125
147
|
});
|
|
126
|
-
|
|
148
|
+
__classPrivateFieldSet(this, _MLEngine_core, core, "f");
|
|
127
149
|
return core;
|
|
128
150
|
}
|
|
129
151
|
async i18n() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.emit('i18n', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
|
|
152
|
+
const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
|
|
153
|
+
this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
|
|
133
154
|
return i18nSettings;
|
|
134
155
|
}
|
|
135
156
|
async onChange(filePath) {
|
|
136
|
-
|
|
137
|
-
if (!((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.watch)) {
|
|
157
|
+
if (!__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
|
|
138
158
|
return;
|
|
139
159
|
}
|
|
140
160
|
this.emit('log', 'watch:onChange', filePath);
|
|
@@ -143,14 +163,13 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
143
163
|
return;
|
|
144
164
|
}
|
|
145
165
|
if (fabric.configErrors) {
|
|
146
|
-
this.emit('config-errors',
|
|
166
|
+
this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
|
|
147
167
|
}
|
|
148
|
-
this.emit('log', 'update:core',
|
|
149
|
-
|
|
168
|
+
this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
169
|
+
__classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
|
|
150
170
|
await this.exec();
|
|
151
171
|
}
|
|
152
172
|
async provide(cache = true) {
|
|
153
|
-
var _a, _b, _c, _d;
|
|
154
173
|
let configSet;
|
|
155
174
|
try {
|
|
156
175
|
configSet = await this.resolveConfig(cache);
|
|
@@ -172,22 +191,22 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
172
191
|
fileLog('Resolved Config: %O', configSet.config);
|
|
173
192
|
fileLog('Resolved Plugins: %O', configSet.plugins);
|
|
174
193
|
fileLog('Resolve Errors: %O', configSet.errs);
|
|
175
|
-
if (!(await
|
|
176
|
-
this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${
|
|
177
|
-
fileLog("The file doesn't exist or it is not a file: %s",
|
|
194
|
+
if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
|
|
195
|
+
this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
|
|
196
|
+
fileLog("The file doesn't exist or it is not a file: %s", __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
178
197
|
return null;
|
|
179
198
|
}
|
|
180
199
|
// Exclude
|
|
181
|
-
const excludeFiles =
|
|
182
|
-
if (
|
|
183
|
-
fileLog('Excludes the file: %s',
|
|
200
|
+
const excludeFiles = configSet.config.excludeFiles ?? [];
|
|
201
|
+
if (__classPrivateFieldGet(this, _MLEngine_file, "f").ignored(excludeFiles)) {
|
|
202
|
+
fileLog('Excludes the file: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
184
203
|
return null;
|
|
185
204
|
}
|
|
186
205
|
const { parser, parserOptions, matched } = await this.resolveParser(configSet);
|
|
187
|
-
const checkingExt = !
|
|
206
|
+
const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
|
|
188
207
|
if (checkingExt && !matched) {
|
|
189
|
-
this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${
|
|
190
|
-
fileLog('Avoided linting because a file is unmatched by the extension: %s',
|
|
208
|
+
this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
|
|
209
|
+
fileLog('Avoided linting because a file is unmatched by the extension: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
191
210
|
return null;
|
|
192
211
|
}
|
|
193
212
|
const ruleset = this.resolveRuleset(configSet);
|
|
@@ -207,14 +226,14 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
207
226
|
}
|
|
208
227
|
const rules = await this.resolveRules(configSet.plugins, ruleset);
|
|
209
228
|
fileLog('Resolved rules: %O', rules);
|
|
210
|
-
const locale = await
|
|
229
|
+
const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
|
|
211
230
|
if (fileLog.enabled) {
|
|
212
231
|
fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
|
|
213
232
|
}
|
|
214
233
|
return {
|
|
215
234
|
parser,
|
|
216
235
|
parserOptions,
|
|
217
|
-
pretenders:
|
|
236
|
+
pretenders: configSet.config.pretenders ?? [],
|
|
218
237
|
ruleset,
|
|
219
238
|
schemas,
|
|
220
239
|
rules,
|
|
@@ -223,78 +242,79 @@ class MLEngine extends strict_event_emitter_1.Emitter {
|
|
|
223
242
|
};
|
|
224
243
|
}
|
|
225
244
|
async resolveConfig(cache) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
configLog('
|
|
237
|
-
this.emit('log', '
|
|
245
|
+
this.emit('log', 'resolveConfig', JSON.stringify(__classPrivateFieldGet(this, _MLEngine_configProvider, "f"), null, 2));
|
|
246
|
+
configLog('configProvider: %s', __classPrivateFieldGet(this, _MLEngine_configProvider, "f"));
|
|
247
|
+
const defaultConfigKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f")?.defaultConfig);
|
|
248
|
+
configLog('defaultConfigKey: %s', defaultConfigKey ?? 'N/A');
|
|
249
|
+
this.emit('log', 'defaultConfigKey', defaultConfigKey ?? 'N/A');
|
|
250
|
+
const targetConfig = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(__classPrivateFieldGet(this, _MLEngine_file, "f"));
|
|
251
|
+
this.emit('log', 'targetConfig', targetConfig ?? 'N/A');
|
|
252
|
+
const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
|
|
253
|
+
? defaultConfigKey ?? null
|
|
254
|
+
: targetConfig ?? defaultConfigKey;
|
|
255
|
+
configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget ?? 'N/A');
|
|
256
|
+
this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget ?? 'N/A');
|
|
257
|
+
const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
|
|
258
|
+
configLog('option.config: %s', configKey ?? 'N/A');
|
|
259
|
+
this.emit('log', 'option.config', configFilePathsFromTarget ?? 'N/A');
|
|
238
260
|
let defaultRecommended = null;
|
|
239
261
|
if (!defaultConfigKey && !configFilePathsFromTarget && !configKey) {
|
|
240
262
|
// No configured
|
|
241
263
|
// Default: set recommended
|
|
242
|
-
defaultRecommended =
|
|
264
|
+
defaultRecommended = __classPrivateFieldGet(this, _MLEngine_configProvider, "f").set({ extends: ['markuplint:recommended'] });
|
|
243
265
|
}
|
|
244
|
-
configLog('defaultRecommended: %s', defaultRecommended
|
|
245
|
-
this.emit('log', 'defaultRecommended', defaultRecommended
|
|
246
|
-
const configSet = await
|
|
247
|
-
this.emit('config',
|
|
248
|
-
if (
|
|
266
|
+
configLog('defaultRecommended: %s', defaultRecommended ?? 'N/A');
|
|
267
|
+
this.emit('log', 'defaultRecommended', defaultRecommended ?? 'N/A');
|
|
268
|
+
const configSet = await __classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey, defaultRecommended], cache);
|
|
269
|
+
this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
|
|
270
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
|
|
249
271
|
// It doesn't watch the main HTML file because it may is watched and managed by a language server or text editor or more.
|
|
250
|
-
|
|
272
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").add([...configSet.files]);
|
|
251
273
|
}
|
|
252
274
|
return configSet;
|
|
253
275
|
}
|
|
254
276
|
async resolveParser(
|
|
255
277
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
256
278
|
configSet) {
|
|
257
|
-
const parser = await
|
|
258
|
-
this.emit('parser',
|
|
279
|
+
const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
|
|
280
|
+
this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
|
|
259
281
|
fileLog('Fetched Parser module: %s', parser.parserModName);
|
|
260
282
|
return parser;
|
|
261
283
|
}
|
|
262
284
|
async resolveRules(plugins, ruleset) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
rules.push(...tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
|
|
285
|
+
const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
|
|
286
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
|
|
287
|
+
rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
|
|
267
288
|
}
|
|
268
|
-
this.emit('rules',
|
|
289
|
+
this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
|
|
269
290
|
return rules;
|
|
270
291
|
}
|
|
271
292
|
resolveRuleset(
|
|
272
293
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
273
294
|
configSet) {
|
|
274
|
-
const ruleset =
|
|
275
|
-
this.emit('ruleset',
|
|
295
|
+
const ruleset = convertRuleset(configSet.config);
|
|
296
|
+
this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
|
|
276
297
|
return ruleset;
|
|
277
298
|
}
|
|
278
299
|
async resolveSchemas(
|
|
279
300
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
280
301
|
configSet) {
|
|
281
|
-
const { schemas } = await
|
|
282
|
-
this.emit('schemas',
|
|
302
|
+
const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
|
|
303
|
+
this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
|
|
283
304
|
return schemas;
|
|
284
305
|
}
|
|
285
306
|
async setup() {
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
307
|
+
if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
|
|
308
|
+
return __classPrivateFieldGet(this, _MLEngine_core, "f");
|
|
288
309
|
}
|
|
289
310
|
const fabric = await this.provide();
|
|
290
311
|
if (!fabric) {
|
|
291
312
|
return null;
|
|
292
313
|
}
|
|
293
314
|
if (fabric.configErrors) {
|
|
294
|
-
this.emit('config-errors',
|
|
315
|
+
this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
|
|
295
316
|
}
|
|
296
317
|
return this.createCore(fabric);
|
|
297
318
|
}
|
|
298
319
|
}
|
|
299
320
|
_MLEngine_configProvider = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_watcher = new WeakMap();
|
|
300
|
-
exports.default = MLEngine;
|
package/lib/api/types.d.ts
CHANGED
|
@@ -3,38 +3,38 @@ import type { LocaleSet } from '@markuplint/i18n';
|
|
|
3
3
|
import type { Config, Violation } from '@markuplint/ml-config';
|
|
4
4
|
import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
|
|
5
5
|
export type APIOptions = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
readonly configFile?: string;
|
|
7
|
+
readonly config?: Config;
|
|
8
|
+
readonly defaultConfig?: Config;
|
|
9
|
+
readonly noSearchConfig?: boolean;
|
|
10
|
+
readonly locale?: string;
|
|
11
|
+
readonly fix?: boolean;
|
|
12
|
+
readonly ignoreExt?: boolean;
|
|
13
|
+
readonly rules?: readonly Readonly<AnyMLRule>[];
|
|
14
|
+
readonly importPresetRules?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated
|
|
17
|
+
*/
|
|
18
|
+
readonly autoLoad?: boolean;
|
|
19
19
|
};
|
|
20
20
|
export type MLEngineEventMap = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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>[]];
|
|
40
40
|
};
|