markuplint 2.1.1 → 2.2.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/cli/bootstrap.d.ts +4 -1
- package/lib/cli/bootstrap.js +4 -0
- package/lib/cli/command.d.ts +2 -1
- package/lib/cli/command.js +2 -1
- package/lib/cli/index.js +8 -0
- package/lib/cli/search/index.d.ts +2 -0
- package/lib/cli/search/index.js +40 -0
- package/package.json +7 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/api/index.d.mts +0 -2
- package/lib/api/index.mjs +0 -2
- package/lib/api/lint.d.mts +0 -4
- package/lib/api/lint.mjs +0 -15
- package/lib/api/ml-engine.d.mts +0 -27
- package/lib/api/ml-engine.mjs +0 -232
- package/lib/api/types.d.mts +0 -43
- package/lib/api/types.mjs +0 -1
- package/lib/api/v1.d.mts +0 -51
- package/lib/api/v1.mjs +0 -39
- package/lib/cli/bootstrap.d.mts +0 -52
- package/lib/cli/bootstrap.mjs +0 -81
- package/lib/cli/command.d.mts +0 -3
- package/lib/cli/command.mjs +0 -50
- package/lib/cli/create-rule/index.d.mts +0 -1
- package/lib/cli/create-rule/index.mjs +0 -51
- package/lib/cli/index.d.mts +0 -1
- package/lib/cli/index.mjs +0 -64
- package/lib/cli/index.spec.d.mts +0 -1
- package/lib/cli/index.spec.mjs +0 -48
- package/lib/cli/init/index.d.mts +0 -1
- package/lib/cli/init/index.mjs +0 -266
- package/lib/cli/init/install-module.d.mts +0 -5
- package/lib/cli/init/install-module.mjs +0 -61
- package/lib/cli/output.d.mts +0 -3
- package/lib/cli/output.mjs +0 -31
- package/lib/cli/prompt.d.mts +0 -18
- package/lib/cli/prompt.mjs +0 -68
- package/lib/debug.d.mts +0 -3
- package/lib/debug.mjs +0 -10
- package/lib/global-settings.d.mts +0 -5
- package/lib/global-settings.mjs +0 -10
- package/lib/i18n.d.mts +0 -6
- package/lib/i18n.mjs +0 -19
- package/lib/index.d.mts +0 -8
- package/lib/index.mjs +0 -8
- package/lib/reporter/index.d.mts +0 -2
- package/lib/reporter/index.mjs +0 -2
- package/lib/reporter/simple-reporter.d.mts +0 -3
- package/lib/reporter/simple-reporter.mjs +0 -30
- package/lib/reporter/standard-reporter.d.mts +0 -3
- package/lib/reporter/standard-reporter.mjs +0 -43
- package/lib/testing-tool/index.d.mts +0 -35
- package/lib/testing-tool/index.mjs +0 -83
- package/lib/types.d.mts +0 -27
- package/lib/types.mjs +0 -1
- package/lib/util.d.mts +0 -19
- package/lib/util.mjs +0 -73
- package/lib/v1.d.mts +0 -4
- package/lib/v1.mjs +0 -4
package/lib/api/ml-engine.mjs
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
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();
|
package/lib/api/types.d.mts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/api/v1.d.mts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/cli/bootstrap.d.mts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export declare const help = "\nUsage\n\t$ markuplint <HTML file pathes (glob format)>\n\t$ <stdout> | markuplint\n\nOptions\n\t--config, -c FILE_PATH A configuration file path.\n\t--fix, Fix HTML.\n\t--format, -f FORMAT Output format. Support \"JSON\", \"Simple\" and \"Standard\". Default: \"Standard\".\n\t--no-search-config No search a configure file automatically.\n\t--ignore-ext Evaluate files that are received even though the type of extension.\n\t--no-import-preset-rules No import preset rules.\n\t--locale Locale of the message of violation. Default is an OS setting.\n\t--no-color, Output no color.\n\t--problem-only, -p Output only problems, without passeds.\n\t--verbose Output with detailed information.\n\n\t--init Initialize settings interactively.\n\t--create-rule Add the scaffold of a custom rule.\n\n\t--help, -h Show help.\n\t--version, -v Show version.\n\nExamples\n\t$ markuplint verifyee.html --config path/to/.markuplintrc\n\t$ cat verifyee.html | markuplint\n";
|
|
2
|
-
export declare const cli: import("meow").Result<{
|
|
3
|
-
config: {
|
|
4
|
-
type: "string";
|
|
5
|
-
alias: string;
|
|
6
|
-
};
|
|
7
|
-
fix: {
|
|
8
|
-
type: "boolean";
|
|
9
|
-
default: false;
|
|
10
|
-
};
|
|
11
|
-
format: {
|
|
12
|
-
type: "string";
|
|
13
|
-
alias: string;
|
|
14
|
-
};
|
|
15
|
-
searchConfig: {
|
|
16
|
-
type: "boolean";
|
|
17
|
-
default: true;
|
|
18
|
-
};
|
|
19
|
-
ignoreExt: {
|
|
20
|
-
type: "boolean";
|
|
21
|
-
default: false;
|
|
22
|
-
};
|
|
23
|
-
importPresetRules: {
|
|
24
|
-
type: "boolean";
|
|
25
|
-
default: true;
|
|
26
|
-
};
|
|
27
|
-
locale: {
|
|
28
|
-
type: "string";
|
|
29
|
-
};
|
|
30
|
-
color: {
|
|
31
|
-
type: "boolean";
|
|
32
|
-
default: true;
|
|
33
|
-
};
|
|
34
|
-
problemOnly: {
|
|
35
|
-
type: "boolean";
|
|
36
|
-
alias: string;
|
|
37
|
-
default: false;
|
|
38
|
-
};
|
|
39
|
-
verbose: {
|
|
40
|
-
type: "boolean";
|
|
41
|
-
default: false;
|
|
42
|
-
};
|
|
43
|
-
init: {
|
|
44
|
-
type: "boolean";
|
|
45
|
-
default: false;
|
|
46
|
-
};
|
|
47
|
-
createRule: {
|
|
48
|
-
type: "boolean";
|
|
49
|
-
default: false;
|
|
50
|
-
};
|
|
51
|
-
}>;
|
|
52
|
-
export declare type CLIOptions = typeof cli.flags;
|
package/lib/cli/bootstrap.mjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import meow from 'meow';
|
|
2
|
-
export const help = `
|
|
3
|
-
Usage
|
|
4
|
-
$ markuplint <HTML file pathes (glob format)>
|
|
5
|
-
$ <stdout> | markuplint
|
|
6
|
-
|
|
7
|
-
Options
|
|
8
|
-
--config, -c FILE_PATH A configuration file path.
|
|
9
|
-
--fix, Fix HTML.
|
|
10
|
-
--format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
|
|
11
|
-
--no-search-config No search a configure file automatically.
|
|
12
|
-
--ignore-ext Evaluate files that are received even though the type of extension.
|
|
13
|
-
--no-import-preset-rules No import preset rules.
|
|
14
|
-
--locale Locale of the message of violation. Default is an OS setting.
|
|
15
|
-
--no-color, Output no color.
|
|
16
|
-
--problem-only, -p Output only problems, without passeds.
|
|
17
|
-
--verbose Output with detailed information.
|
|
18
|
-
|
|
19
|
-
--init Initialize settings interactively.
|
|
20
|
-
--create-rule Add the scaffold of a custom rule.
|
|
21
|
-
|
|
22
|
-
--help, -h Show help.
|
|
23
|
-
--version, -v Show version.
|
|
24
|
-
|
|
25
|
-
Examples
|
|
26
|
-
$ markuplint verifyee.html --config path/to/.markuplintrc
|
|
27
|
-
$ cat verifyee.html | markuplint
|
|
28
|
-
`;
|
|
29
|
-
export const cli = meow(help, {
|
|
30
|
-
importMeta: import.meta,
|
|
31
|
-
flags: {
|
|
32
|
-
config: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
alias: 'c',
|
|
35
|
-
},
|
|
36
|
-
fix: {
|
|
37
|
-
type: 'boolean',
|
|
38
|
-
default: false,
|
|
39
|
-
},
|
|
40
|
-
format: {
|
|
41
|
-
type: 'string',
|
|
42
|
-
alias: 'f',
|
|
43
|
-
},
|
|
44
|
-
searchConfig: {
|
|
45
|
-
type: 'boolean',
|
|
46
|
-
default: true,
|
|
47
|
-
},
|
|
48
|
-
ignoreExt: {
|
|
49
|
-
type: 'boolean',
|
|
50
|
-
default: false,
|
|
51
|
-
},
|
|
52
|
-
importPresetRules: {
|
|
53
|
-
type: 'boolean',
|
|
54
|
-
default: true,
|
|
55
|
-
},
|
|
56
|
-
locale: {
|
|
57
|
-
type: 'string',
|
|
58
|
-
},
|
|
59
|
-
color: {
|
|
60
|
-
type: 'boolean',
|
|
61
|
-
default: true,
|
|
62
|
-
},
|
|
63
|
-
problemOnly: {
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
alias: 'p',
|
|
66
|
-
default: false,
|
|
67
|
-
},
|
|
68
|
-
verbose: {
|
|
69
|
-
type: 'boolean',
|
|
70
|
-
default: false,
|
|
71
|
-
},
|
|
72
|
-
init: {
|
|
73
|
-
type: 'boolean',
|
|
74
|
-
default: false,
|
|
75
|
-
},
|
|
76
|
-
createRule: {
|
|
77
|
-
type: 'boolean',
|
|
78
|
-
default: false,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
package/lib/cli/command.d.mts
DELETED
package/lib/cli/command.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { resolveFiles } from '@markuplint/file-resolver';
|
|
4
|
-
import { MLEngine } from '../api/index.mjs';
|
|
5
|
-
import { log } from '../debug.mjs';
|
|
6
|
-
import { output } from './output.mjs';
|
|
7
|
-
export async function command(files, options) {
|
|
8
|
-
const fix = options.fix;
|
|
9
|
-
const configFile = options.config && path.join(process.cwd(), options.config);
|
|
10
|
-
const locale = options.locale;
|
|
11
|
-
const searchConfig = options.searchConfig;
|
|
12
|
-
const ignoreExt = options.ignoreExt;
|
|
13
|
-
const importPresetRules = options.importPresetRules;
|
|
14
|
-
const verbose = options.verbose;
|
|
15
|
-
const fileList = await resolveFiles(files);
|
|
16
|
-
if (log.enabled) {
|
|
17
|
-
log('File list: %O', fileList.map(f => f.path));
|
|
18
|
-
log('Config: %s', configFile || 'N/A');
|
|
19
|
-
log('Fix option: %s', fix);
|
|
20
|
-
}
|
|
21
|
-
let hasError = false;
|
|
22
|
-
for (const file of fileList) {
|
|
23
|
-
const engine = new MLEngine(file, {
|
|
24
|
-
configFile,
|
|
25
|
-
fix,
|
|
26
|
-
locale,
|
|
27
|
-
noSearchConfig: !searchConfig,
|
|
28
|
-
ignoreExt,
|
|
29
|
-
importPresetRules,
|
|
30
|
-
debug: verbose,
|
|
31
|
-
});
|
|
32
|
-
const result = await engine.exec();
|
|
33
|
-
if (!result) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (!hasError && result.violations.length) {
|
|
37
|
-
hasError = true;
|
|
38
|
-
}
|
|
39
|
-
if (fix) {
|
|
40
|
-
log('Overwrite file: %s', result.filePath);
|
|
41
|
-
await fs.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
|
|
42
|
-
process.stdout.write(`markuplint: Fix "${result.filePath}"\n`);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
log('Output reports');
|
|
46
|
-
await output(result, options);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return hasError;
|
|
50
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createRule(): Promise<void>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as createRuleHelper from '@markuplint/create-rule-helper';
|
|
2
|
-
import c from 'cli-color';
|
|
3
|
-
import { write, head } from '../../util.mjs';
|
|
4
|
-
import { installModule } from '../init/install-module.mjs';
|
|
5
|
-
import { input, select, confirm } from '../prompt.mjs';
|
|
6
|
-
export async function createRule() {
|
|
7
|
-
write(head('Create a rule'));
|
|
8
|
-
write.break();
|
|
9
|
-
const purpose = await select({
|
|
10
|
-
message: 'What purpose do you create the rule for?',
|
|
11
|
-
choices: [
|
|
12
|
-
{ name: 'Add the rule to this project', value: 'ADD_TO_PROJECT' },
|
|
13
|
-
{ name: 'Create the rule and publish it as a package', value: 'PUBLISH_AS_PACKAGE' },
|
|
14
|
-
{ name: 'Contribute the new rule to markuplint core rules', value: 'CONTRIBUTE_TO_CORE' },
|
|
15
|
-
],
|
|
16
|
-
});
|
|
17
|
-
const name = await input('What is the name?', /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
|
|
18
|
-
const lang = purpose === 'CONTRIBUTE_TO_CORE'
|
|
19
|
-
? 'TYPESCRIPT'
|
|
20
|
-
: await select({
|
|
21
|
-
message: 'Which language will you implement?',
|
|
22
|
-
choices: [
|
|
23
|
-
{ name: 'TypeScript', value: 'TYPESCRIPT' },
|
|
24
|
-
{ name: 'JavaScript', value: 'JAVASCRIPT' },
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
const needTest = purpose === 'CONTRIBUTE_TO_CORE' ? true : await confirm('Do you need the test?', { initial: true });
|
|
28
|
-
const result = await createRuleHelper.createRuleHelper({ purpose, name, lang, needTest });
|
|
29
|
-
output(name, '📝', 'README.md', result.readme);
|
|
30
|
-
output(name, '📜', 'index', result.main);
|
|
31
|
-
if (result.test) {
|
|
32
|
-
output(name, '🖍 ', 'index.spec', result.test);
|
|
33
|
-
}
|
|
34
|
-
if (result.schemaJson) {
|
|
35
|
-
output(name, '⚙️ ', 'schema.json', result.schemaJson);
|
|
36
|
-
}
|
|
37
|
-
if (result.packageJson) {
|
|
38
|
-
output(name, '🎁 ', 'package.json', result.packageJson);
|
|
39
|
-
if (result.tsConfig) {
|
|
40
|
-
output(name, '💎 ', 'tsconfig.json', result.tsConfig);
|
|
41
|
-
}
|
|
42
|
-
await installModule(result.dependencies);
|
|
43
|
-
await installModule(result.devDependencies, true);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function output(name, icon, title, path) {
|
|
47
|
-
const _marker = c.xterm(39)('✔') + ' ';
|
|
48
|
-
const _title = (icon, title) => `${icon} ` + c.bold(`${name}/${title}`);
|
|
49
|
-
const _file = (path) => ' ' + c.cyanBright(path);
|
|
50
|
-
write(_marker + _title(icon, title) + _file(path));
|
|
51
|
-
}
|
package/lib/cli/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/cli/index.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import getStdin from 'get-stdin';
|
|
2
|
-
import { verbosely } from '../debug.mjs';
|
|
3
|
-
import { cli } from './bootstrap.mjs';
|
|
4
|
-
import { command } from './command.mjs';
|
|
5
|
-
import { createRule } from './create-rule/index.mjs';
|
|
6
|
-
import { initialize } from './init/index.mjs';
|
|
7
|
-
(async () => {
|
|
8
|
-
if (cli.flags.v) {
|
|
9
|
-
cli.showVersion(); // And exit successfully.
|
|
10
|
-
}
|
|
11
|
-
if (cli.flags.h) {
|
|
12
|
-
cli.showHelp(0); // And exit successfully.
|
|
13
|
-
}
|
|
14
|
-
if (cli.flags.verbose) {
|
|
15
|
-
verbosely();
|
|
16
|
-
}
|
|
17
|
-
if (cli.flags.init) {
|
|
18
|
-
await initialize().catch(err => {
|
|
19
|
-
process.stderr.write(err + '\n');
|
|
20
|
-
process.exit(1);
|
|
21
|
-
});
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (cli.flags.createRule) {
|
|
25
|
-
await createRule().catch(err => {
|
|
26
|
-
process.stderr.write(err + '\n');
|
|
27
|
-
process.exit(1);
|
|
28
|
-
});
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const files = cli.input;
|
|
32
|
-
if (files.length) {
|
|
33
|
-
const hasError = await command(files, cli.flags).catch(err => {
|
|
34
|
-
throw err;
|
|
35
|
-
// process.exit(1);
|
|
36
|
-
});
|
|
37
|
-
process.exit(hasError ? 1 : 0);
|
|
38
|
-
}
|
|
39
|
-
if (usePipe()) {
|
|
40
|
-
getStdin()
|
|
41
|
-
.then(async (stdin) => {
|
|
42
|
-
if (stdin) {
|
|
43
|
-
const hasError = await command([{ sourceCode: stdin }], cli.flags).catch(err => {
|
|
44
|
-
process.stderr.write(err + '\n');
|
|
45
|
-
process.exit(1);
|
|
46
|
-
});
|
|
47
|
-
process.exit(hasError ? 1 : 0);
|
|
48
|
-
}
|
|
49
|
-
// result is empty
|
|
50
|
-
cli.showHelp(1);
|
|
51
|
-
})
|
|
52
|
-
.catch(reason => {
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.warn(reason);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
cli.showHelp(1);
|
|
60
|
-
}
|
|
61
|
-
})();
|
|
62
|
-
function usePipe() {
|
|
63
|
-
return !process.stdin.isTTY && process.stdout.isTTY;
|
|
64
|
-
}
|