@bhsd/codemirror-mediawiki 2.25.0 → 2.25.2
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/dist/codemirror.d.ts +3 -1
- package/dist/linter.d.mts +9 -12
- package/dist/linter.d.ts +9 -12
- package/dist/linter.mjs +37 -33
- package/dist/main.min.js +14 -14
- package/dist/mw.min.js +16 -16
- package/dist/statusBar.d.ts +3 -1
- package/dist/wiki.min.js +16 -16
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/mediawiki.css +1 -1
- package/package.json +2 -2
package/dist/codemirror.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ import type { MwConfig } from './token';
|
|
|
8
8
|
import type { DocRange } from './fold';
|
|
9
9
|
import type { Option, LiveOption } from './linter';
|
|
10
10
|
export type { MwConfig };
|
|
11
|
-
export type LintSource = (doc: Text) => Diagnostic[] | Promise<Diagnostic[]
|
|
11
|
+
export type LintSource = ((doc: Text) => Diagnostic[] | Promise<Diagnostic[]>) & {
|
|
12
|
+
fixer?: (doc: Text, rule?: string) => string | Promise<string>;
|
|
13
|
+
};
|
|
12
14
|
export type Addon<T> = [(config?: T, cm?: CodeMirror6) => Extension, Record<string, T>];
|
|
13
15
|
/** CodeMirror 6 编辑器 */
|
|
14
16
|
export declare class CodeMirror6 {
|
package/dist/linter.d.mts
CHANGED
|
@@ -5,12 +5,15 @@ import type { Diagnostic } from 'luacheck-browserify';
|
|
|
5
5
|
export type Option = Record<string, unknown> | null | undefined;
|
|
6
6
|
export type LiveOption = (runtime?: true) => Option;
|
|
7
7
|
declare type getLinter<T> = () => (text: string) => T;
|
|
8
|
+
declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
|
|
9
|
+
config?: S;
|
|
10
|
+
fixer?: (code: string, rule?: string) => string | Promise<string>;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* @param opt 初始化选项
|
|
10
14
|
* @param obj 仅用于wikiparse.LanguageService
|
|
11
|
-
* @param config runtime设置
|
|
12
15
|
*/
|
|
13
|
-
declare type getAsyncLinter<T, S = never, R = never> = (opt?: S, obj?: R) => Promise<
|
|
16
|
+
declare type getAsyncLinter<T, S = never, R = never> = (opt?: S, obj?: R) => Promise<asyncLinter<T>>;
|
|
14
17
|
declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
15
18
|
range?: Range;
|
|
16
19
|
from?: number;
|
|
@@ -22,16 +25,10 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
|
22
25
|
* @param obj 对象
|
|
23
26
|
*/
|
|
24
27
|
export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[], boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* 获取 Stylelint
|
|
32
|
-
* @param fix 是否修正
|
|
33
|
-
*/
|
|
34
|
-
export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>, boolean>;
|
|
28
|
+
/** 获取 ESLint */
|
|
29
|
+
export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
|
|
30
|
+
/** 获取 Stylelint */
|
|
31
|
+
export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
|
|
35
32
|
/** 获取 Luacheck */
|
|
36
33
|
export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
|
|
37
34
|
declare interface JsonError {
|
package/dist/linter.d.ts
CHANGED
|
@@ -5,12 +5,15 @@ import type { Diagnostic } from 'luacheck-browserify';
|
|
|
5
5
|
export type Option = Record<string, unknown> | null | undefined;
|
|
6
6
|
export type LiveOption = (runtime?: true) => Option;
|
|
7
7
|
declare type getLinter<T> = () => (text: string) => T;
|
|
8
|
+
declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
|
|
9
|
+
config?: S;
|
|
10
|
+
fixer?: (code: string, rule?: string) => string | Promise<string>;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* @param opt 初始化选项
|
|
10
14
|
* @param obj 仅用于wikiparse.LanguageService
|
|
11
|
-
* @param config runtime设置
|
|
12
15
|
*/
|
|
13
|
-
declare type getAsyncLinter<T, S = never, R = never> = (opt?: S, obj?: R) => Promise<
|
|
16
|
+
declare type getAsyncLinter<T, S = never, R = never> = (opt?: S, obj?: R) => Promise<asyncLinter<T>>;
|
|
14
17
|
declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
15
18
|
range?: Range;
|
|
16
19
|
from?: number;
|
|
@@ -22,16 +25,10 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
|
22
25
|
* @param obj 对象
|
|
23
26
|
*/
|
|
24
27
|
export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[], boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* 获取 Stylelint
|
|
32
|
-
* @param fix 是否修正
|
|
33
|
-
*/
|
|
34
|
-
export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>, boolean>;
|
|
28
|
+
/** 获取 ESLint */
|
|
29
|
+
export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
|
|
30
|
+
/** 获取 Stylelint */
|
|
31
|
+
export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
|
|
35
32
|
/** 获取 Luacheck */
|
|
36
33
|
export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
|
|
37
34
|
declare interface JsonError {
|
package/dist/linter.mjs
CHANGED
|
@@ -49,54 +49,58 @@ ${sanitizeInlineStyle(childNodes[1].childNodes[0].data).replace(/\n/gu, " ")}
|
|
|
49
49
|
];
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
-
const getJsLinter = async (
|
|
52
|
+
const getJsLinter = async () => {
|
|
53
53
|
var _a;
|
|
54
54
|
await loadScript("npm/eslint-linter-browserify@8.57.0/linter.min.js", "eslint", true);
|
|
55
55
|
const esLinter = new eslint.Linter(), conf = {
|
|
56
56
|
env: { browser: true, es2024: true },
|
|
57
|
-
parserOptions: { ecmaVersion: 15, sourceType: "module" }
|
|
58
|
-
|
|
59
|
-
};
|
|
57
|
+
parserOptions: { ecmaVersion: 15, sourceType: "module" }
|
|
58
|
+
}, recommended = {};
|
|
60
59
|
for (const [name, { meta }] of esLinter.getRules()) {
|
|
61
60
|
if ((_a = meta == null ? void 0 : meta.docs) == null ? void 0 : _a.recommended) {
|
|
62
|
-
|
|
61
|
+
recommended[name] = 2;
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
const config = { ...conf, ...opt }
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
if (fixed) {
|
|
70
|
-
warnings.push({
|
|
71
|
-
line: 1,
|
|
72
|
-
column: 1,
|
|
73
|
-
ruleId: null,
|
|
74
|
-
severity: 0,
|
|
75
|
-
message: output
|
|
76
|
-
});
|
|
77
|
-
}
|
|
64
|
+
const linter = (text, opt) => {
|
|
65
|
+
const config = { ...conf, ...opt };
|
|
66
|
+
if (!("rules" in config) || config.extends === "eslint:recommended" || Array.isArray(config.extends) && config.extends.includes("eslint:recommended")) {
|
|
67
|
+
config.rules = { ...recommended, ...config.rules };
|
|
78
68
|
}
|
|
79
|
-
|
|
69
|
+
delete config.extends;
|
|
70
|
+
linter.config = config;
|
|
71
|
+
return esLinter.verify(text, config);
|
|
72
|
+
};
|
|
73
|
+
linter.fixer = (code, rule) => {
|
|
74
|
+
var _a2, _b;
|
|
75
|
+
return esLinter.verifyAndFix(
|
|
76
|
+
code,
|
|
77
|
+
rule ? { ...linter.config, rules: { [rule]: (_b = (_a2 = linter.config.rules) == null ? void 0 : _a2[rule]) != null ? _b : 2 } } : linter.config
|
|
78
|
+
).output;
|
|
80
79
|
};
|
|
80
|
+
return linter;
|
|
81
81
|
};
|
|
82
|
-
const getCssLinter = async (
|
|
82
|
+
const getCssLinter = async () => {
|
|
83
83
|
await loadScript("npm/@bhsd/stylelint-browserify", "stylelint");
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
if (text !== code) {
|
|
89
|
-
warnings.push({
|
|
90
|
-
line: 1,
|
|
91
|
-
column: 1,
|
|
92
|
-
rule: "fix",
|
|
93
|
-
severity: "custom",
|
|
94
|
-
text
|
|
95
|
-
});
|
|
96
|
-
}
|
|
84
|
+
const linter = async (code, opt) => {
|
|
85
|
+
const warnings = await styleLint(stylelint, code, opt);
|
|
86
|
+
if (opt && "rules" in opt) {
|
|
87
|
+
linter.config = opt;
|
|
97
88
|
}
|
|
98
89
|
return warnings;
|
|
99
90
|
};
|
|
91
|
+
linter.fixer = (code, rule) => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (!linter.config) {
|
|
94
|
+
throw new Error("Fixer unavailable!");
|
|
95
|
+
}
|
|
96
|
+
return styleLint(
|
|
97
|
+
stylelint,
|
|
98
|
+
code,
|
|
99
|
+
rule ? { extends: [], rules: { [rule]: (_b = (_a = linter.config.rules) == null ? void 0 : _a[rule]) != null ? _b : true } } : linter.config,
|
|
100
|
+
true
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
return linter;
|
|
100
104
|
};
|
|
101
105
|
const getLuaLinter = async () => {
|
|
102
106
|
await loadScript("npm/luacheck-browserify/dist/index.min.js", "luacheck");
|