@bhsd/codemirror-mediawiki 2.24.3 → 2.25.1
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 +5 -2
- package/dist/linter.d.ts +5 -2
- package/dist/linter.mjs +41 -12
- package/dist/main.min.js +16 -16
- package/dist/mw.min.js +20 -20
- package/dist/statusBar.d.ts +4 -0
- package/dist/wiki.min.js +20 -20
- 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 +3 -3
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;
|
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;
|
package/dist/linter.mjs
CHANGED
|
@@ -54,24 +54,53 @@ const getJsLinter = async () => {
|
|
|
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
|
-
|
|
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 };
|
|
68
|
+
}
|
|
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;
|
|
79
|
+
};
|
|
80
|
+
return linter;
|
|
66
81
|
};
|
|
67
82
|
const getCssLinter = async () => {
|
|
68
|
-
await loadScript("npm/stylelint-
|
|
69
|
-
|
|
70
|
-
stylelint,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
await loadScript("npm/@bhsd/stylelint-browserify", "stylelint");
|
|
84
|
+
const linter = async (code, opt) => {
|
|
85
|
+
const warnings = await styleLint(stylelint, code, opt);
|
|
86
|
+
if (opt && "rules" in opt) {
|
|
87
|
+
linter.config = opt;
|
|
88
|
+
}
|
|
89
|
+
return warnings;
|
|
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;
|
|
75
104
|
};
|
|
76
105
|
const getLuaLinter = async () => {
|
|
77
106
|
await loadScript("npm/luacheck-browserify/dist/index.min.js", "luacheck");
|