markuplint 4.0.0-dev.20 → 4.0.0-dev.23
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/lib/api/ml-engine.js +1 -1
- package/lib/cli/command.js +8 -11
- package/lib/cli/init/create-config.js +11 -1
- package/lib/cli/init/get-default-rules.d.ts +2 -2
- package/lib/cli/init/get-default-rules.js +12 -48
- package/lib/cli/init/index.js +1 -4
- package/lib/cli/init/types.d.ts +3 -2
- package/package.json +15 -17
package/LICENSE
CHANGED
package/lib/api/ml-engine.js
CHANGED
|
@@ -81,7 +81,7 @@ export class MLEngine extends Emitter {
|
|
|
81
81
|
throw error;
|
|
82
82
|
});
|
|
83
83
|
const sourceCode = await __classPrivateFieldGet(this, _MLEngine_file, "f").getCode();
|
|
84
|
-
const fixedCode = core.document.toString();
|
|
84
|
+
const fixedCode = core.document.toString(true);
|
|
85
85
|
if (violations instanceof Error) {
|
|
86
86
|
this.emit('lint-error', __classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations);
|
|
87
87
|
const errMessage = violations.stack ?? violations.message;
|
package/lib/cli/command.js
CHANGED
|
@@ -50,19 +50,16 @@ export async function command(files, options, apiOptions) {
|
|
|
50
50
|
if (fix) {
|
|
51
51
|
log('Overwrite file: %s', result.filePath);
|
|
52
52
|
await fs.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
|
|
53
|
-
process.stdout.write(`markuplint: Fix "${result.filePath}"\n`);
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
log('Output reports');
|
|
64
|
-
output(result, options);
|
|
54
|
+
if (format === 'json') {
|
|
55
|
+
jsonOutput.push(...result.violations.map(v => ({
|
|
56
|
+
...v,
|
|
57
|
+
filePath: result.filePath,
|
|
58
|
+
})));
|
|
59
|
+
continue;
|
|
65
60
|
}
|
|
61
|
+
log('Output reports');
|
|
62
|
+
output(result, options);
|
|
66
63
|
}
|
|
67
64
|
if (format === 'json') {
|
|
68
65
|
process.stdout.write(JSON.stringify(jsonOutput, null, 2) + '\n');
|
|
@@ -2,6 +2,7 @@ const extRExp = {
|
|
|
2
2
|
jsx: '\\.[jt]sx?$',
|
|
3
3
|
vue: '\\.vue$',
|
|
4
4
|
svelte: '\\.svelte$',
|
|
5
|
+
sveltekit: '\\.html$',
|
|
5
6
|
astro: '\\.astro$',
|
|
6
7
|
pug: '\\.pug$',
|
|
7
8
|
php: '\\.php$',
|
|
@@ -16,6 +17,7 @@ export const langs = {
|
|
|
16
17
|
jsx: 'React (JSX)',
|
|
17
18
|
vue: 'Vue',
|
|
18
19
|
svelte: 'Svelte',
|
|
20
|
+
sveltekit: 'SvelteKit',
|
|
19
21
|
astro: 'Astro',
|
|
20
22
|
pug: 'Pug',
|
|
21
23
|
php: 'PHP',
|
|
@@ -34,7 +36,15 @@ export function createConfig(langs, mode, defaultRules) {
|
|
|
34
36
|
if (!ext) {
|
|
35
37
|
continue;
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
switch (lang) {
|
|
40
|
+
case 'sveltekit': {
|
|
41
|
+
parser[ext] = '@markuplint/svelte-parser/kit';
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
parser[ext] = `@markuplint/${lang}-parser`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
38
48
|
if (lang === 'vue') {
|
|
39
49
|
config = {
|
|
40
50
|
...config,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function getDefaultRules(
|
|
1
|
+
export declare function getDefaultRules(): {
|
|
2
2
|
[x: string]: import("./types.js").Rule;
|
|
3
|
-
}
|
|
3
|
+
};
|
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const RULES_SCHEMA_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/schema.json';
|
|
4
|
-
const RULES_README_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/src/[NAME]/README.md';
|
|
5
|
-
export async function getDefaultRules(version) {
|
|
6
|
-
const json = await safeFetch(RULES_SCHEMA_URL, version);
|
|
1
|
+
import builtinRules from '@markuplint/rules';
|
|
2
|
+
export function getDefaultRules() {
|
|
7
3
|
const rules = {};
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
for (const [ruleName, rule] of Object.entries(builtinRules)) {
|
|
5
|
+
const defaultSeverity = rule.defaultSeverity;
|
|
6
|
+
const defaultValue = defaultSeverity === 'warning' ? false : rule.defaultValue ?? true;
|
|
7
|
+
const category = rule.meta?.category;
|
|
8
|
+
if (category) {
|
|
9
|
+
rules[ruleName] = {
|
|
10
|
+
defaultValue,
|
|
11
|
+
category,
|
|
12
|
+
};
|
|
17
13
|
}
|
|
18
|
-
const defaultValue = severity === 'warning' ? false : json.definitions.value.default ?? true;
|
|
19
|
-
rules[name] = {
|
|
20
|
-
defaultValue,
|
|
21
|
-
category,
|
|
22
|
-
};
|
|
23
|
-
}));
|
|
24
|
-
return rules;
|
|
25
|
-
}
|
|
26
|
-
async function safeFetch(baseUrl, version, type = 'json') {
|
|
27
|
-
const url = baseUrl.replace('[VERSION]', `v${version}`);
|
|
28
|
-
const res = await fetch(url);
|
|
29
|
-
if (!res.ok) {
|
|
30
|
-
return safeFetch(baseUrl, '3.0.0', type);
|
|
31
|
-
}
|
|
32
|
-
if (type === 'json') {
|
|
33
|
-
return (await res.json());
|
|
34
14
|
}
|
|
35
|
-
|
|
36
|
-
const { data } = matter(md);
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Fallback fetching until 3.0.x
|
|
41
|
-
*
|
|
42
|
-
* @param version
|
|
43
|
-
* @param name
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
async function getCatAndSeverityFromLegacy(version, name) {
|
|
47
|
-
const data = await safeFetch(RULES_README_URL.replace('[NAME]', name), version, 'md');
|
|
48
|
-
return {
|
|
49
|
-
category: data.category,
|
|
50
|
-
severity: data.severity,
|
|
51
|
-
};
|
|
15
|
+
return rules;
|
|
52
16
|
}
|
package/lib/cli/init/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import module from 'node:module';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { installModule, multiSelect, confirm, confirmSequence, header } from '@markuplint/cli-utils';
|
|
5
4
|
import { createConfig, langs } from './create-config.js';
|
|
6
5
|
import { getDefaultRules } from './get-default-rules.js';
|
|
7
6
|
import { selectModules } from './select-modules.js';
|
|
8
|
-
const require = module.createRequire(import.meta.url);
|
|
9
7
|
const ruleCategories = {
|
|
10
8
|
validation: {
|
|
11
9
|
message: 'Are you going to conformance check according to HTML standard?',
|
|
@@ -52,8 +50,7 @@ export async function initialize() {
|
|
|
52
50
|
}
|
|
53
51
|
let defaultRules = {};
|
|
54
52
|
if (ruleSettingMode !== 'recommended') {
|
|
55
|
-
|
|
56
|
-
defaultRules = await getDefaultRules(rulesVersion);
|
|
53
|
+
defaultRules = getDefaultRules();
|
|
57
54
|
}
|
|
58
55
|
const config = createConfig(selectedLangs, ruleSettingMode, defaultRules);
|
|
59
56
|
const filePath = path.resolve(process.cwd(), '.markuplintrc');
|
package/lib/cli/init/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
2
|
+
export type Langs = 'jsx' | 'vue' | 'svelte' | 'sveltekit' | 'astro' | 'pug' | 'php' | 'smarty' | 'erb' | 'ejs' | 'mustache' | 'nunjucks' | 'liquid';
|
|
2
3
|
export type Category = 'validation' | 'a11y' | 'naming-convention' | 'style' | 'maintainability';
|
|
3
4
|
export type RuleSettingMode = readonly Category[] | 'recommended' | 'none';
|
|
4
5
|
export type DefaultRules = Readonly<Record<string, Rule>>;
|
|
5
6
|
export type Rule = {
|
|
6
7
|
readonly category: Category;
|
|
7
|
-
readonly defaultValue:
|
|
8
|
+
readonly defaultValue: RuleConfigValue;
|
|
8
9
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markuplint",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.23+d6f2aa9bc",
|
|
4
4
|
"description": "An HTML linter for all markup developers",
|
|
5
5
|
"author": "Yusuke Hirao",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,28 +25,26 @@
|
|
|
25
25
|
"clean": "tsc --build --clean"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@markuplint/cli-utils": "4.0.0-dev.
|
|
29
|
-
"@markuplint/file-resolver": "4.0.0-dev.
|
|
30
|
-
"@markuplint/html-parser": "4.0.0-dev.
|
|
31
|
-
"@markuplint/html-spec": "4.0.0-dev.
|
|
32
|
-
"@markuplint/i18n": "4.0.0-dev.
|
|
33
|
-
"@markuplint/ml-ast": "4.0.0-dev.
|
|
34
|
-
"@markuplint/ml-config": "4.0.0-dev.
|
|
35
|
-
"@markuplint/ml-core": "4.0.0-dev.
|
|
36
|
-
"@markuplint/ml-spec": "4.0.0-dev.
|
|
37
|
-
"@markuplint/rules": "4.0.0-dev.
|
|
38
|
-
"@markuplint/shared": "4.0.0-dev.
|
|
28
|
+
"@markuplint/cli-utils": "4.0.0-dev.23+d6f2aa9bc",
|
|
29
|
+
"@markuplint/file-resolver": "4.0.0-dev.23+d6f2aa9bc",
|
|
30
|
+
"@markuplint/html-parser": "4.0.0-dev.23+d6f2aa9bc",
|
|
31
|
+
"@markuplint/html-spec": "4.0.0-dev.23+d6f2aa9bc",
|
|
32
|
+
"@markuplint/i18n": "4.0.0-dev.23+d6f2aa9bc",
|
|
33
|
+
"@markuplint/ml-ast": "4.0.0-dev.23+d6f2aa9bc",
|
|
34
|
+
"@markuplint/ml-config": "4.0.0-dev.23+d6f2aa9bc",
|
|
35
|
+
"@markuplint/ml-core": "4.0.0-dev.23+d6f2aa9bc",
|
|
36
|
+
"@markuplint/ml-spec": "4.0.0-dev.23+d6f2aa9bc",
|
|
37
|
+
"@markuplint/rules": "4.0.0-dev.23+d6f2aa9bc",
|
|
38
|
+
"@markuplint/shared": "4.0.0-dev.23+d6f2aa9bc",
|
|
39
39
|
"@types/debug": "^4.1.12",
|
|
40
40
|
"chokidar": "^3.5.3",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"get-stdin": "^9.0.0",
|
|
43
|
-
"
|
|
44
|
-
"meow": "^13.0.0",
|
|
45
|
-
"node-fetch": "^3.3.2",
|
|
43
|
+
"meow": "^13.1.0",
|
|
46
44
|
"os-locale": "^6.0.2",
|
|
47
45
|
"strict-event-emitter": "^0.5.1",
|
|
48
46
|
"strip-ansi": "^7.1.0",
|
|
49
|
-
"type-fest": "^4.
|
|
47
|
+
"type-fest": "^4.9.0"
|
|
50
48
|
},
|
|
51
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d6f2aa9bc287768466f23b5340e4e0eecfa30d59"
|
|
52
50
|
}
|