@bhsd/codemirror-mediawiki 2.24.3 → 2.25.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/dist/linter.d.mts CHANGED
@@ -22,10 +22,16 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
22
22
  * @param obj 对象
23
23
  */
24
24
  export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
25
- /** 获取 ESLint */
26
- export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
27
- /** 获取 Stylelint */
28
- export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
25
+ /**
26
+ * 获取 ESLint
27
+ * @param fix 是否修正
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>;
29
35
  /** 获取 Luacheck */
30
36
  export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
31
37
  declare interface JsonError {
package/dist/linter.d.ts CHANGED
@@ -22,10 +22,16 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
22
22
  * @param obj 对象
23
23
  */
24
24
  export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
25
- /** 获取 ESLint */
26
- export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
27
- /** 获取 Stylelint */
28
- export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
25
+ /**
26
+ * 获取 ESLint
27
+ * @param fix 是否修正
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>;
29
35
  /** 获取 Luacheck */
30
36
  export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
31
37
  declare interface JsonError {
package/dist/linter.mjs CHANGED
@@ -49,7 +49,7 @@ ${sanitizeInlineStyle(childNodes[1].childNodes[0].data).replace(/\n/gu, " ")}
49
49
  ];
50
50
  };
51
51
  };
52
- const getJsLinter = async () => {
52
+ const getJsLinter = async (fix) => {
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 = {
@@ -62,16 +62,41 @@ const getJsLinter = async () => {
62
62
  conf.rules[name] = 2;
63
63
  }
64
64
  }
65
- return (text, opt) => esLinter.verify(text, { ...conf, ...opt });
65
+ return (text, opt) => {
66
+ const config = { ...conf, ...opt }, warnings = esLinter.verify(text, config);
67
+ if (fix) {
68
+ const { fixed, output } = esLinter.verifyAndFix(text, config);
69
+ if (fixed) {
70
+ warnings.push({
71
+ line: 1,
72
+ column: 1,
73
+ ruleId: null,
74
+ severity: 0,
75
+ message: output
76
+ });
77
+ }
78
+ }
79
+ return warnings;
80
+ };
66
81
  };
67
- const getCssLinter = async () => {
68
- await loadScript("npm/stylelint-bundle", "stylelint");
69
- return (code, opt) => styleLint(
70
- stylelint,
71
- code,
72
- opt == null ? void 0 : opt["rules"],
73
- true
74
- );
82
+ const getCssLinter = async (fix) => {
83
+ await loadScript("npm/@bhsd/stylelint-browserify", "stylelint");
84
+ return async (code, opt) => {
85
+ const rules = opt == null ? void 0 : opt["rules"], warnings = await styleLint(stylelint, code, rules);
86
+ if (fix) {
87
+ const text = await styleLint(stylelint, code, rules, true);
88
+ if (text !== code) {
89
+ warnings.push({
90
+ line: 1,
91
+ column: 1,
92
+ rule: "fix",
93
+ severity: "custom",
94
+ text
95
+ });
96
+ }
97
+ }
98
+ return warnings;
99
+ };
75
100
  };
76
101
  const getLuaLinter = async () => {
77
102
  await loadScript("npm/luacheck-browserify/dist/index.min.js", "luacheck");