markuplint 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/index.d.mts +2 -0
- package/lib/api/index.mjs +2 -0
- package/lib/api/lint.d.mts +4 -0
- package/lib/api/lint.mjs +15 -0
- package/lib/api/ml-engine.d.mts +27 -0
- package/lib/api/ml-engine.d.ts +18 -18
- package/lib/api/ml-engine.mjs +232 -0
- package/lib/api/types.d.mts +43 -0
- package/lib/api/types.d.ts +32 -39
- package/lib/api/types.mjs +1 -0
- package/lib/api/v1.d.mts +51 -0
- package/lib/api/v1.d.ts +43 -43
- package/lib/api/v1.mjs +39 -0
- package/lib/cli/bootstrap.d.mts +52 -0
- package/lib/cli/bootstrap.d.ts +49 -50
- package/lib/cli/bootstrap.mjs +81 -0
- package/lib/cli/command.d.mts +3 -0
- package/lib/cli/command.mjs +50 -0
- package/lib/cli/create-rule/index.d.mts +1 -0
- package/lib/cli/create-rule/index.mjs +51 -0
- package/lib/cli/index.d.mts +1 -0
- package/lib/cli/index.mjs +64 -0
- package/lib/cli/index.spec.d.mts +1 -0
- package/lib/cli/index.spec.mjs +48 -0
- package/lib/cli/init/index.d.mts +1 -0
- package/lib/cli/init/index.mjs +266 -0
- package/lib/cli/init/install-module.d.mts +5 -0
- package/lib/cli/init/install-module.d.ts +2 -2
- package/lib/cli/init/install-module.mjs +61 -0
- package/lib/cli/output.d.mts +3 -0
- package/lib/cli/output.mjs +31 -0
- package/lib/cli/prompt.d.mts +18 -0
- package/lib/cli/prompt.d.ts +12 -17
- package/lib/cli/prompt.mjs +68 -0
- package/lib/debug.d.mts +3 -0
- package/lib/debug.mjs +10 -0
- package/lib/global-settings.d.mts +5 -0
- package/lib/global-settings.d.ts +1 -1
- package/lib/global-settings.mjs +10 -0
- package/lib/i18n.d.mts +6 -0
- package/lib/i18n.d.ts +4 -4
- package/lib/i18n.mjs +19 -0
- package/lib/index.d.mts +8 -0
- package/lib/index.mjs +8 -0
- package/lib/reporter/index.d.mts +2 -0
- package/lib/reporter/index.mjs +2 -0
- package/lib/reporter/simple-reporter.d.mts +3 -0
- package/lib/reporter/simple-reporter.mjs +30 -0
- package/lib/reporter/standard-reporter.d.mts +3 -0
- package/lib/reporter/standard-reporter.mjs +43 -0
- package/lib/testing-tool/index.d.mts +35 -0
- package/lib/testing-tool/index.d.ts +25 -43
- package/lib/testing-tool/index.mjs +83 -0
- package/lib/types.d.mts +27 -0
- package/lib/types.d.ts +17 -17
- package/lib/types.mjs +1 -0
- package/lib/util.d.mts +19 -0
- package/lib/util.d.ts +3 -3
- package/lib/util.mjs +73 -0
- package/lib/v1.d.mts +4 -0
- package/lib/v1.mjs +4 -0
- package/package.json +4 -4
- package/lib/cli/head.d.ts +0 -1
- package/lib/cli/head.js +0 -31
- package/lib/reporter/utils.d.ts +0 -6
- package/lib/reporter/utils.js +0 -40
package/lib/api/lint.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { resolveFiles } from '@markuplint/file-resolver';
|
|
2
|
+
import MLEngine from './ml-engine.mjs';
|
|
3
|
+
export async function lint(targetList, options) {
|
|
4
|
+
const res = [];
|
|
5
|
+
const files = await resolveFiles(targetList);
|
|
6
|
+
for (const file of files) {
|
|
7
|
+
const engine = new MLEngine(file, options);
|
|
8
|
+
const result = await engine.exec();
|
|
9
|
+
if (!result) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
res.push(result);
|
|
13
|
+
}
|
|
14
|
+
return res;
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MLResultInfo } from '../types.mjs';
|
|
2
|
+
import type { APIOptions, MLEngineEventMap } from './types.mjs';
|
|
3
|
+
import type { MLFile, Target } from '@markuplint/file-resolver';
|
|
4
|
+
import { StrictEventEmitter } from 'strict-event-emitter';
|
|
5
|
+
declare type MLEngineOptions = {
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
|
|
10
|
+
#private;
|
|
11
|
+
static toMLFile(target: Target): Promise<MLFile>;
|
|
12
|
+
constructor(file: MLFile, options?: APIOptions & MLEngineOptions);
|
|
13
|
+
exec(): Promise<MLResultInfo | null>;
|
|
14
|
+
setCode(code: string): Promise<void>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
private setup;
|
|
17
|
+
private provide;
|
|
18
|
+
private cretateCore;
|
|
19
|
+
private resolveConfig;
|
|
20
|
+
private resolveParser;
|
|
21
|
+
private resolveRuleset;
|
|
22
|
+
private resolveSchemas;
|
|
23
|
+
private resolveRules;
|
|
24
|
+
private i18n;
|
|
25
|
+
private watch;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
package/lib/api/ml-engine.d.ts
CHANGED
|
@@ -3,25 +3,25 @@ import type { APIOptions, MLEngineEventMap } from './types';
|
|
|
3
3
|
import type { MLFile, Target } from '@markuplint/file-resolver';
|
|
4
4
|
import { StrictEventEmitter } from 'strict-event-emitter';
|
|
5
5
|
declare type MLEngineOptions = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
watch?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
#private;
|
|
11
|
+
static toMLFile(target: Target): Promise<MLFile>;
|
|
12
|
+
constructor(file: MLFile, options?: APIOptions & MLEngineOptions);
|
|
13
|
+
exec(): Promise<MLResultInfo | null>;
|
|
14
|
+
setCode(code: string): Promise<void>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
private setup;
|
|
17
|
+
private provide;
|
|
18
|
+
private cretateCore;
|
|
19
|
+
private resolveConfig;
|
|
20
|
+
private resolveParser;
|
|
21
|
+
private resolveRuleset;
|
|
22
|
+
private resolveSchemas;
|
|
23
|
+
private resolveRules;
|
|
24
|
+
private i18n;
|
|
25
|
+
private watch;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
var _MLEngine_file, _MLEngine_options, _MLEngine_core, _MLEngine_watcher;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { configProvider, resolveFiles, resolveParser, resolveRules, resolveSpecs } from '@markuplint/file-resolver';
|
|
4
|
+
import { MLCore, convertRuleset } from '@markuplint/ml-core';
|
|
5
|
+
import { FSWatcher } from 'chokidar';
|
|
6
|
+
import { StrictEventEmitter } from 'strict-event-emitter';
|
|
7
|
+
import { log as coreLog, verbosely } from '../debug.mjs';
|
|
8
|
+
import { i18n } from '../i18n.mjs';
|
|
9
|
+
const log = coreLog.extend('ml-engine');
|
|
10
|
+
const fileLog = log.extend('file');
|
|
11
|
+
export default class MLEngine extends StrictEventEmitter {
|
|
12
|
+
constructor(file, options) {
|
|
13
|
+
super();
|
|
14
|
+
_MLEngine_file.set(this, void 0);
|
|
15
|
+
_MLEngine_options.set(this, void 0);
|
|
16
|
+
_MLEngine_core.set(this, null);
|
|
17
|
+
_MLEngine_watcher.set(this, new FSWatcher());
|
|
18
|
+
__classPrivateFieldSet(this, _MLEngine_file, file, "f");
|
|
19
|
+
__classPrivateFieldSet(this, _MLEngine_options, options, "f");
|
|
20
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.debug) {
|
|
21
|
+
verbosely();
|
|
22
|
+
}
|
|
23
|
+
if (options?.watch) {
|
|
24
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").on('all', this.watch.bind(this));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static async toMLFile(target) {
|
|
31
|
+
const files = await resolveFiles([target]);
|
|
32
|
+
return files[0];
|
|
33
|
+
}
|
|
34
|
+
async exec() {
|
|
35
|
+
log('exec: start');
|
|
36
|
+
const core = await this.setup();
|
|
37
|
+
if (!core) {
|
|
38
|
+
log('exec: cancel (unsetuped yet)');
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const violations = await core.verify(__classPrivateFieldGet(this, _MLEngine_options, "f")?.fix).catch(e => {
|
|
42
|
+
if (e instanceof Error) {
|
|
43
|
+
return e;
|
|
44
|
+
}
|
|
45
|
+
throw e;
|
|
46
|
+
});
|
|
47
|
+
const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
|
|
48
|
+
const fixedCode = core.document.toString();
|
|
49
|
+
if (violations instanceof Error) {
|
|
50
|
+
this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
|
|
51
|
+
const errMessage = violations.stack ?? violations.message;
|
|
52
|
+
log('exec: error %O', errMessage);
|
|
53
|
+
return {
|
|
54
|
+
violations: [
|
|
55
|
+
{
|
|
56
|
+
severity: 'error',
|
|
57
|
+
message: errMessage,
|
|
58
|
+
ruleId: '@markuplint/ml-core',
|
|
59
|
+
line: 0,
|
|
60
|
+
col: 0,
|
|
61
|
+
raw: '',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
65
|
+
sourceCode,
|
|
66
|
+
fixedCode,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const debugMap = ('debugMap' in core.document && core.document.debugMap()) || null;
|
|
70
|
+
this.emit('lint', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
|
|
71
|
+
log('exec: end');
|
|
72
|
+
return {
|
|
73
|
+
violations,
|
|
74
|
+
filePath: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
75
|
+
sourceCode,
|
|
76
|
+
fixedCode,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async setCode(code) {
|
|
80
|
+
const core = await this.setup();
|
|
81
|
+
if (!core) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
__classPrivateFieldGet(this, _MLEngine_file, "f").setCode(code);
|
|
85
|
+
core.setCode(code);
|
|
86
|
+
}
|
|
87
|
+
async close() {
|
|
88
|
+
this.removeAllListeners();
|
|
89
|
+
await __classPrivateFieldGet(this, _MLEngine_watcher, "f").close();
|
|
90
|
+
}
|
|
91
|
+
async setup() {
|
|
92
|
+
if (__classPrivateFieldGet(this, _MLEngine_core, "f")) {
|
|
93
|
+
return __classPrivateFieldGet(this, _MLEngine_core, "f");
|
|
94
|
+
}
|
|
95
|
+
const fabric = await this.provide(false);
|
|
96
|
+
if (!fabric) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (fabric.configErrors) {
|
|
100
|
+
this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
|
|
101
|
+
}
|
|
102
|
+
const core = this.cretateCore(fabric);
|
|
103
|
+
return core;
|
|
104
|
+
}
|
|
105
|
+
async provide(remerge) {
|
|
106
|
+
const configSet = await this.resolveConfig(remerge);
|
|
107
|
+
fileLog('Fetched Config files: %O', configSet.files);
|
|
108
|
+
fileLog('Resolved Config: %O', configSet.config);
|
|
109
|
+
fileLog('Resolved Plugins: %O', configSet.plugins);
|
|
110
|
+
fileLog('Resolve Errors: %O', configSet.errs);
|
|
111
|
+
if (!(await __classPrivateFieldGet(this, _MLEngine_file, "f").isFile())) {
|
|
112
|
+
this.emit('log', 'file-no-exists', `The file doesn't exist or it is not a file: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
// Exclude
|
|
116
|
+
const excludeFiles = configSet.config.excludeFiles || [];
|
|
117
|
+
for (const excludeFile of excludeFiles) {
|
|
118
|
+
if (__classPrivateFieldGet(this, _MLEngine_file, "f").matches(excludeFile)) {
|
|
119
|
+
this.emit('exclude', __classPrivateFieldGet(this, _MLEngine_file, "f").path, excludeFile);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const { parser, parserOptions, matched } = await this.resolveParser(configSet);
|
|
124
|
+
const checkingExt = !__classPrivateFieldGet(this, _MLEngine_options, "f")?.ignoreExt;
|
|
125
|
+
if (checkingExt && !matched) {
|
|
126
|
+
this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const ruleset = this.resolveRuleset(configSet);
|
|
130
|
+
fileLog('Resolved ruleset: %O', ruleset);
|
|
131
|
+
const schemas = await this.resolveSchemas(configSet);
|
|
132
|
+
if (fileLog.enabled) {
|
|
133
|
+
if (schemas[0].cites.length) {
|
|
134
|
+
const [, ...additionalSpecs] = schemas;
|
|
135
|
+
fileLog('Resolved schemas: HTML Standard');
|
|
136
|
+
for (const additionalSpec of additionalSpecs) {
|
|
137
|
+
fileLog('Resolved schemas: %O', additionalSpec);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
fileLog('Resolved schemas: %O', schemas);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const rules = await this.resolveRules(configSet.plugins, ruleset);
|
|
145
|
+
fileLog('Resolved rules: %O', rules);
|
|
146
|
+
const locale = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
|
|
147
|
+
if (fileLog.enabled) {
|
|
148
|
+
fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
parser,
|
|
152
|
+
parserOptions,
|
|
153
|
+
ruleset,
|
|
154
|
+
schemas,
|
|
155
|
+
rules,
|
|
156
|
+
locale,
|
|
157
|
+
configErrors: configSet.errs,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async cretateCore(fabric) {
|
|
161
|
+
fileLog('Get source code');
|
|
162
|
+
const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
|
|
163
|
+
fileLog('Source code path: %s', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
164
|
+
fileLog('Source code size: %dbyte', sourceCode.length);
|
|
165
|
+
this.emit('code', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode);
|
|
166
|
+
const core = new MLCore({
|
|
167
|
+
sourceCode,
|
|
168
|
+
filename: __classPrivateFieldGet(this, _MLEngine_file, "f").path,
|
|
169
|
+
debug: __classPrivateFieldGet(this, _MLEngine_options, "f")?.debug,
|
|
170
|
+
...fabric,
|
|
171
|
+
});
|
|
172
|
+
__classPrivateFieldSet(this, _MLEngine_core, core, "f");
|
|
173
|
+
return core;
|
|
174
|
+
}
|
|
175
|
+
async resolveConfig(remerge) {
|
|
176
|
+
const configFilePathsFromTarget = __classPrivateFieldGet(this, _MLEngine_options, "f")?.noSearchConfig
|
|
177
|
+
? null
|
|
178
|
+
: await configProvider.search(__classPrivateFieldGet(this, _MLEngine_file, "f"));
|
|
179
|
+
this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget || 'null');
|
|
180
|
+
const configKey = __classPrivateFieldGet(this, _MLEngine_options, "f")?.config && configProvider.set(__classPrivateFieldGet(this, _MLEngine_options, "f").config);
|
|
181
|
+
this.emit('log', 'configKey', configKey || 'null');
|
|
182
|
+
const configSet = await configProvider.resolve([configFilePathsFromTarget, __classPrivateFieldGet(this, _MLEngine_options, "f")?.configFile, configKey], remerge);
|
|
183
|
+
this.emit('config', __classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
|
|
184
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.watch) {
|
|
185
|
+
__classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
|
|
186
|
+
}
|
|
187
|
+
return configSet;
|
|
188
|
+
}
|
|
189
|
+
async resolveParser(configSet) {
|
|
190
|
+
const parser = await resolveParser(__classPrivateFieldGet(this, _MLEngine_file, "f"), configSet.config.parser, configSet.config.parserOptions);
|
|
191
|
+
this.emit('parser', __classPrivateFieldGet(this, _MLEngine_file, "f").path, parser.parserModName);
|
|
192
|
+
fileLog('Fetched Parser module: %s', parser.parserModName);
|
|
193
|
+
return parser;
|
|
194
|
+
}
|
|
195
|
+
resolveRuleset(configSet) {
|
|
196
|
+
const ruleset = convertRuleset(configSet.config);
|
|
197
|
+
this.emit('ruleset', __classPrivateFieldGet(this, _MLEngine_file, "f").path, ruleset);
|
|
198
|
+
return ruleset;
|
|
199
|
+
}
|
|
200
|
+
async resolveSchemas(configSet) {
|
|
201
|
+
const { schemas } = await resolveSpecs(__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet.config.specs);
|
|
202
|
+
this.emit('schemas', __classPrivateFieldGet(this, _MLEngine_file, "f").path, schemas);
|
|
203
|
+
return schemas;
|
|
204
|
+
}
|
|
205
|
+
async resolveRules(plugins, ruleset) {
|
|
206
|
+
const rules = await resolveRules(plugins, ruleset, __classPrivateFieldGet(this, _MLEngine_options, "f")?.importPresetRules ?? true, __classPrivateFieldGet(this, _MLEngine_options, "f")?.autoLoad ?? true);
|
|
207
|
+
if (__classPrivateFieldGet(this, _MLEngine_options, "f")?.rules) {
|
|
208
|
+
rules.push(...__classPrivateFieldGet(this, _MLEngine_options, "f").rules);
|
|
209
|
+
}
|
|
210
|
+
this.emit('rules', __classPrivateFieldGet(this, _MLEngine_file, "f").path, rules);
|
|
211
|
+
return rules;
|
|
212
|
+
}
|
|
213
|
+
async i18n() {
|
|
214
|
+
const i18nSettings = await i18n(__classPrivateFieldGet(this, _MLEngine_options, "f")?.locale);
|
|
215
|
+
this.emit('i18n', __classPrivateFieldGet(this, _MLEngine_file, "f").path, i18nSettings);
|
|
216
|
+
return i18nSettings;
|
|
217
|
+
}
|
|
218
|
+
async watch(type, filePath) {
|
|
219
|
+
this.emit('log', `watch:${type}`, filePath);
|
|
220
|
+
const fabric = await this.provide(true);
|
|
221
|
+
if (!fabric) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (fabric.configErrors) {
|
|
225
|
+
this.emit('config-errors', __classPrivateFieldGet(this, _MLEngine_file, "f").path, fabric.configErrors);
|
|
226
|
+
}
|
|
227
|
+
this.emit('log', 'update:core', __classPrivateFieldGet(this, _MLEngine_file, "f").path);
|
|
228
|
+
__classPrivateFieldGet(this, _MLEngine_core, "f")?.update(fabric);
|
|
229
|
+
this.exec();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
_MLEngine_file = new WeakMap(), _MLEngine_options = new WeakMap(), _MLEngine_core = new WeakMap(), _MLEngine_watcher = new WeakMap();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ConfigSet } from '@markuplint/file-resolver';
|
|
2
|
+
import type { LocaleSet } from '@markuplint/i18n';
|
|
3
|
+
import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
|
|
4
|
+
import type { Config, Violation, ParserOptions } from '@markuplint/ml-config';
|
|
5
|
+
import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
|
|
6
|
+
export declare type APIOptions = {
|
|
7
|
+
configFile?: string;
|
|
8
|
+
config?: Config;
|
|
9
|
+
defaultConfig?: Config;
|
|
10
|
+
noSearchConfig?: boolean;
|
|
11
|
+
locale?: string;
|
|
12
|
+
fix?: boolean;
|
|
13
|
+
ignoreExt?: boolean;
|
|
14
|
+
rules?: AnyMLRule[];
|
|
15
|
+
importPresetRules?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
19
|
+
autoLoad?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare type MLFabric = {
|
|
22
|
+
ruleset: Ruleset;
|
|
23
|
+
rules: AnyMLRule[];
|
|
24
|
+
schemas: MLSchema;
|
|
25
|
+
parser: MLMarkupLanguageParser;
|
|
26
|
+
parserOptions: ParserOptions;
|
|
27
|
+
locale: LocaleSet;
|
|
28
|
+
configErrors?: Error[];
|
|
29
|
+
};
|
|
30
|
+
export declare type MLEngineEventMap = {
|
|
31
|
+
log: (phase: string, message: string) => void;
|
|
32
|
+
config: (filePath: string, config: ConfigSet, message?: string) => void;
|
|
33
|
+
exclude: (filePath: string, setting: string, message?: string) => void;
|
|
34
|
+
parser: (filePath: string, parser: string, message?: string) => void;
|
|
35
|
+
ruleset: (filePath: string, ruleset: Ruleset, message?: string) => void;
|
|
36
|
+
schemas: (filePath: string, schemas: MLSchema, message?: string) => void;
|
|
37
|
+
rules: (filePath: string, rules: AnyMLRule[], message?: string) => void;
|
|
38
|
+
i18n: (filePath: string, locale: LocaleSet, message?: string) => void;
|
|
39
|
+
code: (filePath: string, sourceCode: string, message?: string) => void;
|
|
40
|
+
lint: (filePath: string, sourceCode: string, violations: Violation[], fixedCode: string, debug: string[] | null, message?: string) => void;
|
|
41
|
+
'lint-error': (filePath: string, sourceCode: string, error: Error) => void;
|
|
42
|
+
'config-errors': (filePath: string, errors: Error[]) => void;
|
|
43
|
+
};
|
package/lib/api/types.d.ts
CHANGED
|
@@ -4,47 +4,40 @@ import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
|
|
|
4
4
|
import type { Config, Violation, ParserOptions } from '@markuplint/ml-config';
|
|
5
5
|
import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
|
|
6
6
|
export declare type APIOptions = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
configFile?: string;
|
|
8
|
+
config?: Config;
|
|
9
|
+
defaultConfig?: Config;
|
|
10
|
+
noSearchConfig?: boolean;
|
|
11
|
+
locale?: string;
|
|
12
|
+
fix?: boolean;
|
|
13
|
+
ignoreExt?: boolean;
|
|
14
|
+
rules?: AnyMLRule[];
|
|
15
|
+
importPresetRules?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
19
|
+
autoLoad?: boolean;
|
|
20
20
|
};
|
|
21
21
|
export declare type MLFabric = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
ruleset: Ruleset;
|
|
23
|
+
rules: AnyMLRule[];
|
|
24
|
+
schemas: MLSchema;
|
|
25
|
+
parser: MLMarkupLanguageParser;
|
|
26
|
+
parserOptions: ParserOptions;
|
|
27
|
+
locale: LocaleSet;
|
|
28
|
+
configErrors?: Error[];
|
|
29
29
|
};
|
|
30
30
|
export declare type MLEngineEventMap = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
violations: Violation[],
|
|
44
|
-
fixedCode: string,
|
|
45
|
-
debug: string[] | null,
|
|
46
|
-
message?: string,
|
|
47
|
-
) => void;
|
|
48
|
-
'lint-error': (filePath: string, sourceCode: string, error: Error) => void;
|
|
49
|
-
'config-errors': (filePath: string, errors: Error[]) => void;
|
|
31
|
+
log: (phase: string, message: string) => void;
|
|
32
|
+
config: (filePath: string, config: ConfigSet, message?: string) => void;
|
|
33
|
+
exclude: (filePath: string, setting: string, message?: string) => void;
|
|
34
|
+
parser: (filePath: string, parser: string, message?: string) => void;
|
|
35
|
+
ruleset: (filePath: string, ruleset: Ruleset, message?: string) => void;
|
|
36
|
+
schemas: (filePath: string, schemas: MLSchema, message?: string) => void;
|
|
37
|
+
rules: (filePath: string, rules: AnyMLRule[], message?: string) => void;
|
|
38
|
+
i18n: (filePath: string, locale: LocaleSet, message?: string) => void;
|
|
39
|
+
code: (filePath: string, sourceCode: string, message?: string) => void;
|
|
40
|
+
lint: (filePath: string, sourceCode: string, violations: Violation[], fixedCode: string, debug: string[] | null, message?: string) => void;
|
|
41
|
+
'lint-error': (filePath: string, sourceCode: string, error: Error) => void;
|
|
42
|
+
'config-errors': (filePath: string, errors: Error[]) => void;
|
|
50
43
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/api/v1.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Config, RuleConfigValue } from '@markuplint/ml-config';
|
|
2
|
+
import type { MLRule } from '@markuplint/ml-core';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function lint_v1(options: {
|
|
9
|
+
/**
|
|
10
|
+
* Glob pattern
|
|
11
|
+
*/
|
|
12
|
+
files?: string | string[];
|
|
13
|
+
/**
|
|
14
|
+
* Target source code of evaluation
|
|
15
|
+
*/
|
|
16
|
+
sourceCodes?: string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* File names when `sourceCodes`
|
|
19
|
+
*/
|
|
20
|
+
names?: string | string[];
|
|
21
|
+
/**
|
|
22
|
+
* Workspace path when `sourceCodes`
|
|
23
|
+
*/
|
|
24
|
+
workspace?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Configure file or object
|
|
27
|
+
*/
|
|
28
|
+
config?: string | Config;
|
|
29
|
+
/**
|
|
30
|
+
* The config applied when not resolved from files or set it explicitly.
|
|
31
|
+
*/
|
|
32
|
+
defaultConfig?: Config;
|
|
33
|
+
/**
|
|
34
|
+
* Rules (default: `@markuplint/rules`)
|
|
35
|
+
*/
|
|
36
|
+
rules?: MLRule<RuleConfigValue, unknown>[];
|
|
37
|
+
/**
|
|
38
|
+
* Auto resolve rules
|
|
39
|
+
*
|
|
40
|
+
* Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
|
|
41
|
+
*/
|
|
42
|
+
rulesAutoResolve?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Auto fix
|
|
45
|
+
*/
|
|
46
|
+
fix?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Locale
|
|
49
|
+
*/
|
|
50
|
+
locale?: string;
|
|
51
|
+
}): Promise<import("../types.mjs").MLResultInfo[]>;
|
package/lib/api/v1.d.ts
CHANGED
|
@@ -6,46 +6,46 @@ import type { MLRule } from '@markuplint/ml-core';
|
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
8
|
export declare function lint_v1(options: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}): Promise<import(
|
|
9
|
+
/**
|
|
10
|
+
* Glob pattern
|
|
11
|
+
*/
|
|
12
|
+
files?: string | string[];
|
|
13
|
+
/**
|
|
14
|
+
* Target source code of evaluation
|
|
15
|
+
*/
|
|
16
|
+
sourceCodes?: string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* File names when `sourceCodes`
|
|
19
|
+
*/
|
|
20
|
+
names?: string | string[];
|
|
21
|
+
/**
|
|
22
|
+
* Workspace path when `sourceCodes`
|
|
23
|
+
*/
|
|
24
|
+
workspace?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Configure file or object
|
|
27
|
+
*/
|
|
28
|
+
config?: string | Config;
|
|
29
|
+
/**
|
|
30
|
+
* The config applied when not resolved from files or set it explicitly.
|
|
31
|
+
*/
|
|
32
|
+
defaultConfig?: Config;
|
|
33
|
+
/**
|
|
34
|
+
* Rules (default: `@markuplint/rules`)
|
|
35
|
+
*/
|
|
36
|
+
rules?: MLRule<RuleConfigValue, unknown>[];
|
|
37
|
+
/**
|
|
38
|
+
* Auto resolve rules
|
|
39
|
+
*
|
|
40
|
+
* Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
|
|
41
|
+
*/
|
|
42
|
+
rulesAutoResolve?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Auto fix
|
|
45
|
+
*/
|
|
46
|
+
fix?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Locale
|
|
49
|
+
*/
|
|
50
|
+
locale?: string;
|
|
51
|
+
}): Promise<import("..").MLResultInfo[]>;
|
package/lib/api/v1.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { lint } from './lint.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
* @param options
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export async function lint_v1(options) {
|
|
8
|
+
const filePathList = options.files ? (Array.isArray(options.files) ? options.files : [options.files]) : [];
|
|
9
|
+
const codes = options.sourceCodes
|
|
10
|
+
? Array.isArray(options.sourceCodes)
|
|
11
|
+
? options.sourceCodes
|
|
12
|
+
: [options.sourceCodes]
|
|
13
|
+
: [];
|
|
14
|
+
const files = [
|
|
15
|
+
...filePathList,
|
|
16
|
+
...codes.map((code, i) => ({
|
|
17
|
+
sourceCode: code,
|
|
18
|
+
name: Array.isArray(options.names) ? options.names?.[i] : options.names,
|
|
19
|
+
workspace: options.workspace?.[i],
|
|
20
|
+
})),
|
|
21
|
+
];
|
|
22
|
+
let config;
|
|
23
|
+
let configFile;
|
|
24
|
+
if (typeof options.config === 'string') {
|
|
25
|
+
configFile = options.config;
|
|
26
|
+
}
|
|
27
|
+
else if (options.config) {
|
|
28
|
+
config = options.config;
|
|
29
|
+
}
|
|
30
|
+
const result = await lint(files, {
|
|
31
|
+
config,
|
|
32
|
+
configFile,
|
|
33
|
+
noSearchConfig: !options.files,
|
|
34
|
+
rules: options.rules,
|
|
35
|
+
autoLoad: options.rulesAutoResolve ?? true,
|
|
36
|
+
locale: options.locale,
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|