eslint
This commit is contained in:
parent
c7763227d0
commit
2a0286e47d
@ -26,6 +26,7 @@
|
|||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"dexie": "^4.0.10",
|
"dexie": "^4.0.10",
|
||||||
|
"eslint-linter-browserify": "^7.32.0",
|
||||||
"eventemitter3": "^5.0.1",
|
"eventemitter3": "^5.0.1",
|
||||||
"i18next": "^23.16.4",
|
"i18next": "^23.16.4",
|
||||||
"monaco-editor": "^0.52.2",
|
"monaco-editor": "^0.52.2",
|
||||||
@ -64,12 +65,13 @@
|
|||||||
"eslint": "^9.24.0",
|
"eslint": "^9.24.0",
|
||||||
"eslint-plugin-react": "^7.37.4",
|
"eslint-plugin-react": "^7.37.4",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-userscripts": "^0.5.6",
|
"eslint-plugin-userscripts": "^0.2.12",
|
||||||
"fake-indexeddb": "^6.0.0",
|
"fake-indexeddb": "^6.0.0",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
"jsdom": "^25.0.1",
|
"jsdom": "^25.0.1",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"mock-xmlhttprequest": "^8.4.1",
|
"mock-xmlhttprequest": "^8.4.1",
|
||||||
|
"node-polyfill-webpack-plugin": "^3.0.0",
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"postcss-loader": "^8.1.1",
|
"postcss-loader": "^8.1.1",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.3",
|
||||||
|
@ -14,6 +14,7 @@ const compatMap = {
|
|||||||
GM_addElement: [
|
GM_addElement: [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.11.6113" },
|
{ type: "tampermonkey", versionConstraint: ">=4.11.6113" },
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.13.0-beta.3" },
|
{ type: "violentmonkey", versionConstraint: ">=2.13.0-beta.3" },
|
||||||
|
{ type: "scriptcat", versionConstraint: "*" },
|
||||||
],
|
],
|
||||||
"GM.addStyle": [
|
"GM.addStyle": [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
||||||
@ -24,15 +25,19 @@ const compatMap = {
|
|||||||
{ type: "violentmonkey", versionConstraint: "*" },
|
{ type: "violentmonkey", versionConstraint: "*" },
|
||||||
{ type: "greasemonkey", versionConstraint: ">=0.6.1.4 <4" },
|
{ type: "greasemonkey", versionConstraint: ">=0.6.1.4 <4" },
|
||||||
],
|
],
|
||||||
"GM.addValueChangeListener": [
|
"GM.addValueChangeListener": [{ type: "tampermonkey", versionConstraint: ">=4.5" }],
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
|
||||||
],
|
|
||||||
GM_addValueChangeListener: [
|
GM_addValueChangeListener: [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=2.3.2607" },
|
{ type: "tampermonkey", versionConstraint: ">=2.3.2607" },
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
||||||
],
|
],
|
||||||
"GM.cookie": [{ type: "tampermonkey", versionConstraint: ">=4.8" }],
|
"GM.cookie": [
|
||||||
GM_cookie: [{ type: "tampermonkey", versionConstraint: ">=4.8" }],
|
{ type: "tampermonkey", versionConstraint: ">=4.8" },
|
||||||
|
{ type: "scriptcat", versionConstraint: "*" },
|
||||||
|
],
|
||||||
|
GM_cookie: [
|
||||||
|
{ type: "tampermonkey", versionConstraint: ">=4.8" },
|
||||||
|
{ type: "scriptcat", versionConstraint: "*" },
|
||||||
|
],
|
||||||
"GM.deleteValue": [
|
"GM.deleteValue": [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
||||||
@ -54,9 +59,7 @@ const compatMap = {
|
|||||||
{ type: "violentmonkey", versionConstraint: "*" },
|
{ type: "violentmonkey", versionConstraint: "*" },
|
||||||
{ type: "greasemonkey", versionConstraint: ">=0.8.20080609.0 <4" },
|
{ type: "greasemonkey", versionConstraint: ">=0.8.20080609.0 <4" },
|
||||||
],
|
],
|
||||||
"GM.getResourceURL": [
|
"GM.getResourceURL": [{ type: "violentmonkey", versionConstraint: ">=2.12.0 <2.13.0.10" }],
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.12.0 <2.13.0.10" },
|
|
||||||
],
|
|
||||||
GM_getResourceURL: [
|
GM_getResourceURL: [
|
||||||
{ type: "tampermonkey", versionConstraint: "*" },
|
{ type: "tampermonkey", versionConstraint: "*" },
|
||||||
{ type: "violentmonkey", versionConstraint: "*" },
|
{ type: "violentmonkey", versionConstraint: "*" },
|
||||||
@ -139,9 +142,7 @@ const compatMap = {
|
|||||||
{ type: "violentmonkey", versionConstraint: "*" },
|
{ type: "violentmonkey", versionConstraint: "*" },
|
||||||
{ type: "greasemonkey", versionConstraint: ">=0.2.5 <4" },
|
{ type: "greasemonkey", versionConstraint: ">=0.2.5 <4" },
|
||||||
],
|
],
|
||||||
"GM.removeValueChangeListener": [
|
"GM.removeValueChangeListener": [{ type: "tampermonkey", versionConstraint: ">=4.5" }],
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
|
||||||
],
|
|
||||||
GM_removeValueChangeListener: [
|
GM_removeValueChangeListener: [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=2.3.2607" },
|
{ type: "tampermonkey", versionConstraint: ">=2.3.2607" },
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
{ type: "violentmonkey", versionConstraint: ">=2.12.0" },
|
||||||
@ -168,9 +169,7 @@ const compatMap = {
|
|||||||
{ type: "violentmonkey", versionConstraint: "*" },
|
{ type: "violentmonkey", versionConstraint: "*" },
|
||||||
{ type: "greasemonkey", versionConstraint: ">=0.3-beta <4" },
|
{ type: "greasemonkey", versionConstraint: ">=0.3-beta <4" },
|
||||||
],
|
],
|
||||||
"GM.unregisterMenuCommand": [
|
"GM.unregisterMenuCommand": [{ type: "tampermonkey", versionConstraint: ">=4.5" }],
|
||||||
{ type: "tampermonkey", versionConstraint: ">=4.5" },
|
|
||||||
],
|
|
||||||
GM_unregisterMenuCommand: [
|
GM_unregisterMenuCommand: [
|
||||||
{ type: "tampermonkey", versionConstraint: ">=3.6.3737" },
|
{ type: "tampermonkey", versionConstraint: ">=3.6.3737" },
|
||||||
{ type: "violentmonkey", versionConstraint: ">=2.9.4" },
|
{ type: "violentmonkey", versionConstraint: ">=2.9.4" },
|
@ -195,6 +195,7 @@ const compatMap = {
|
|||||||
exportValue: [],
|
exportValue: [],
|
||||||
exportCookie: [],
|
exportCookie: [],
|
||||||
scriptUrl: [],
|
scriptUrl: [],
|
||||||
|
storageName: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -19,26 +19,26 @@ const userscriptsConfig = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// const userscriptsRules = Object.fromEntries(
|
const userscriptsRules = Object.fromEntries(
|
||||||
// Object.keys(userscriptsConfig.rules).map((name) => {
|
Object.keys(userscriptsConfig.rules).map((name) => {
|
||||||
// const ruleName = name.split("/")[1];
|
const ruleName = name.split("/")[1];
|
||||||
// // eslint-disable-next-line import/no-dynamic-require, global-require
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||||
// const ruleMeta = require(`eslint-plugin-userscripts/lib/rules/${ruleName}.js`);
|
const ruleMeta = require(`eslint-plugin-userscripts/lib/rules/${ruleName}.js`);
|
||||||
// return [
|
return [
|
||||||
// name,
|
name,
|
||||||
// {
|
{
|
||||||
// ...ruleMeta,
|
...ruleMeta,
|
||||||
// meta: {
|
meta: {
|
||||||
// ...ruleMeta.meta,
|
...ruleMeta.meta,
|
||||||
// docs: {
|
docs: {
|
||||||
// ...ruleMeta.meta.docs,
|
...ruleMeta.meta.docs,
|
||||||
// url: `https://yash-singh1.github.io/eslint-plugin-userscripts/#/rules/${ruleName}`,
|
url: `https://yash-singh1.github.io/eslint-plugin-userscripts/#/rules/${ruleName}`,
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// ];
|
];
|
||||||
// })
|
})
|
||||||
// );
|
);
|
||||||
|
|
||||||
// 默认规则
|
// 默认规则
|
||||||
const config = {
|
const config = {
|
||||||
@ -126,6 +126,6 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 以文本形式导出默认规则
|
// 以文本形式导出默认规则
|
||||||
const defaultConfig = JSON.stringify(config);
|
const defaultConfig = JSON.stringify(config, null, 2);
|
||||||
|
|
||||||
export { defaultConfig, userscriptsConfig };
|
export { defaultConfig, userscriptsConfig, userscriptsRules };
|
664
pnpm-lock.yaml
generated
664
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,8 @@ import { defineConfig } from "@rspack/cli";
|
|||||||
import { rspack } from "@rspack/core";
|
import { rspack } from "@rspack/core";
|
||||||
import { version } from "./package.json";
|
import { version } from "./package.json";
|
||||||
|
|
||||||
|
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === "development";
|
const isDev = process.env.NODE_ENV === "development";
|
||||||
const isBeta = version.includes("-");
|
const isBeta = version.includes("-");
|
||||||
|
|
||||||
@ -36,6 +38,7 @@ export default defineConfig({
|
|||||||
options: `${src}/pages/options/main.tsx`,
|
options: `${src}/pages/options/main.tsx`,
|
||||||
"editor.worker": "monaco-editor/esm/vs/editor/editor.worker.js",
|
"editor.worker": "monaco-editor/esm/vs/editor/editor.worker.js",
|
||||||
"ts.worker": "monaco-editor/esm/vs/language/typescript/ts.worker.js",
|
"ts.worker": "monaco-editor/esm/vs/language/typescript/ts.worker.js",
|
||||||
|
"linter.worker": `${src}/linter.worker.ts`,
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: `${dist}/ext/src`,
|
path: `${dist}/ext/src`,
|
||||||
@ -47,6 +50,9 @@ export default defineConfig({
|
|||||||
alias: {
|
alias: {
|
||||||
"@App": path.resolve(__dirname, "src/"),
|
"@App": path.resolve(__dirname, "src/"),
|
||||||
"@Packages": path.resolve(__dirname, "packages/"),
|
"@Packages": path.resolve(__dirname, "packages/"),
|
||||||
|
// 改写eslint-plugin-userscripts以适配脚本猫,打包时重定义模块路径
|
||||||
|
"../data/compat-grant": path.resolve(__dirname, "./packages/eslint/compat-grant"),
|
||||||
|
"../data/compat-headers": path.resolve(__dirname, "./packages/eslint/compat-headers"),
|
||||||
},
|
},
|
||||||
fallback: {
|
fallback: {
|
||||||
child_process: false,
|
child_process: false,
|
||||||
@ -175,6 +181,7 @@ export default defineConfig({
|
|||||||
minify: true,
|
minify: true,
|
||||||
chunks: ["sandbox"],
|
chunks: ["sandbox"],
|
||||||
}),
|
}),
|
||||||
|
new NodePolyfillPlugin(),
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
optimization: {
|
optimization: {
|
||||||
minimizer: [
|
minimizer: [
|
||||||
|
92
src/linter.worker.ts
Normal file
92
src/linter.worker.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
//@ts-ignore
|
||||||
|
import { Linter } from "eslint-linter-browserify";
|
||||||
|
import { userscriptsRules } from "../packages/eslint/linter-config";
|
||||||
|
|
||||||
|
// eslint语法检查,使用webworker
|
||||||
|
|
||||||
|
const linter = new Linter();
|
||||||
|
|
||||||
|
// 额外定义 userscripts 规则
|
||||||
|
linter.defineRules(userscriptsRules);
|
||||||
|
|
||||||
|
const rules = linter.getRules();
|
||||||
|
|
||||||
|
const severityMap = {
|
||||||
|
2: 8, // 2 for ESLint is error
|
||||||
|
1: 4, // 1 for ESLint is warning
|
||||||
|
};
|
||||||
|
|
||||||
|
function getTextBlock(text: string, startPosition: number, endPosition: number) {
|
||||||
|
if (startPosition > endPosition || startPosition < 0 || endPosition > text.length) {
|
||||||
|
throw new Error("Invalid positions provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
let startLineNumber = 1;
|
||||||
|
let startColumn = 1;
|
||||||
|
let endLineNumber = 1;
|
||||||
|
let endColumn = 1;
|
||||||
|
|
||||||
|
for (let i = 0, currentLine = 1, currentColumn = 1; i < text.length; i += 1) {
|
||||||
|
if (i === startPosition) {
|
||||||
|
startLineNumber = currentLine;
|
||||||
|
startColumn = currentColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i === endPosition) {
|
||||||
|
endLineNumber = currentLine;
|
||||||
|
endColumn = currentColumn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text[i] === "\n") {
|
||||||
|
currentLine += 1;
|
||||||
|
currentColumn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentColumn += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
startLineNumber,
|
||||||
|
startColumn,
|
||||||
|
endLineNumber,
|
||||||
|
endColumn,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addEventListener("message", (event) => {
|
||||||
|
const { code, id, config } = event.data;
|
||||||
|
const errs = linter.verify(code, config);
|
||||||
|
const markers = errs.map((err: any) => {
|
||||||
|
const rule = rules.get(err.ruleId);
|
||||||
|
let target = "";
|
||||||
|
if (rule) {
|
||||||
|
target = rule.meta.docs.url;
|
||||||
|
}
|
||||||
|
let fix: any;
|
||||||
|
if (err.fix) {
|
||||||
|
fix = {
|
||||||
|
range: getTextBlock(code, err.fix.range[0], err.fix.range[1]),
|
||||||
|
text: err.fix.text,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
code: {
|
||||||
|
value: err.ruleId || "",
|
||||||
|
target,
|
||||||
|
},
|
||||||
|
startLineNumber: err.line,
|
||||||
|
endLineNumber: err.endLine || err.line,
|
||||||
|
startColumn: err.column,
|
||||||
|
endColumn: err.endColumn || err.column,
|
||||||
|
message: err.message,
|
||||||
|
// 设置错误的等级,此处ESLint与monaco的存在差异,做一层映射
|
||||||
|
// @ts-ignore
|
||||||
|
severity: severityMap[err.severity],
|
||||||
|
source: "ESLint",
|
||||||
|
fix,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// 发回主进程
|
||||||
|
self.postMessage({ markers, id });
|
||||||
|
});
|
@ -3,6 +3,7 @@ import { LinterWorker } from "@App/pkg/utils/monaco-editor";
|
|||||||
import { useAppSelector } from "@App/pages/store/hooks";
|
import { useAppSelector } from "@App/pages/store/hooks";
|
||||||
import { editor, Range } from "monaco-editor";
|
import { editor, Range } from "monaco-editor";
|
||||||
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
||||||
|
import { globalCache, systemConfig } from "@App/pages/store/global";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -18,10 +19,26 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
|||||||
) => {
|
) => {
|
||||||
const settings = useAppSelector((state) => state.setting);
|
const settings = useAppSelector((state) => state.setting);
|
||||||
const [monacoEditor, setEditor] = useState<editor.IStandaloneCodeEditor>();
|
const [monacoEditor, setEditor] = useState<editor.IStandaloneCodeEditor>();
|
||||||
|
const [enableEslint, setEnableEslint] = useState(false);
|
||||||
|
const [eslintConfig, setEslintConfig] = useState("");
|
||||||
|
|
||||||
const div = useRef<HTMLDivElement>(null);
|
const div = useRef<HTMLDivElement>(null);
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
editor: monacoEditor,
|
editor: monacoEditor,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadConfigs = async () => {
|
||||||
|
const [eslintConfig, enableEslint] = await Promise.all([
|
||||||
|
systemConfig.getEslintConfig(),
|
||||||
|
systemConfig.getEnableEslint(),
|
||||||
|
]);
|
||||||
|
setEslintConfig(eslintConfig);
|
||||||
|
setEnableEslint(enableEslint);
|
||||||
|
};
|
||||||
|
loadConfigs();
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (diffCode === undefined || code === undefined || !div.current) {
|
if (diffCode === undefined || code === undefined || !div.current) {
|
||||||
return () => {};
|
return () => {};
|
||||||
@ -70,8 +87,7 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
|||||||
}, [div, code, diffCode, editable, id]);
|
}, [div, code, diffCode, editable, id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {};
|
if (!enableEslint) {
|
||||||
if (!settings.eslint.enable) {
|
|
||||||
return () => {};
|
return () => {};
|
||||||
}
|
}
|
||||||
if (!monacoEditor) {
|
if (!monacoEditor) {
|
||||||
@ -89,7 +105,7 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
|||||||
LinterWorker.sendLinterMessage({
|
LinterWorker.sendLinterMessage({
|
||||||
code: model.getValue(),
|
code: model.getValue(),
|
||||||
id,
|
id,
|
||||||
config: JSON.parse(settings.eslint.config),
|
config: JSON.parse(eslintConfig),
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
@ -183,7 +199,7 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Cache.getInstance().set("eslint-fix", fix);
|
globalCache.set("eslint-fix", fix);
|
||||||
|
|
||||||
// 在行号旁显示ESLint错误/警告图标
|
// 在行号旁显示ESLint错误/警告图标
|
||||||
const formatMarkers = message.markers.map(
|
const formatMarkers = message.markers.map(
|
||||||
@ -203,7 +219,7 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
|||||||
return () => {
|
return () => {
|
||||||
LinterWorker.hook.removeListener("message", handler);
|
LinterWorker.hook.removeListener("message", handler);
|
||||||
};
|
};
|
||||||
}, [id, monacoEditor, settings.eslint.config, settings.eslint.enable]);
|
}, [id, monacoEditor, enableEslint, eslintConfig]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -2,8 +2,9 @@ import { useEffect, useState } from "react";
|
|||||||
import { Button, Card, Checkbox, Input, Message, Select, Space } from "@arco-design/web-react";
|
import { Button, Card, Checkbox, Input, Message, Select, Space } from "@arco-design/web-react";
|
||||||
import Title from "@arco-design/web-react/es/Typography/title";
|
import Title from "@arco-design/web-react/es/Typography/title";
|
||||||
import { IconQuestionCircleFill } from "@arco-design/web-react/icon";
|
import { IconQuestionCircleFill } from "@arco-design/web-react/icon";
|
||||||
import { format } from "prettier";
|
import prettier from "prettier/standalone";
|
||||||
import babel from "prettier/parser-babel";
|
import * as babel from "prettier/parser-babel";
|
||||||
|
import prettierPluginEstree from "prettier/plugins/estree";
|
||||||
import GMApiSetting from "@App/pages/components/GMApiSetting";
|
import GMApiSetting from "@App/pages/components/GMApiSetting";
|
||||||
import i18n from "@App/locales/locales";
|
import i18n from "@App/locales/locales";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@ -270,9 +271,10 @@ function Setting() {
|
|||||||
setEslintConfig(v);
|
setEslintConfig(v);
|
||||||
}}
|
}}
|
||||||
onBlur={(v) => {
|
onBlur={(v) => {
|
||||||
format(eslintConfig, {
|
prettier
|
||||||
|
.format(eslintConfig, {
|
||||||
parser: "json",
|
parser: "json",
|
||||||
plugins: [babel],
|
plugins: [prettierPluginEstree, babel],
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
systemConfig.setEslintConfig(v.target.value);
|
systemConfig.setEslintConfig(v.target.value);
|
||||||
|
@ -5,3 +5,4 @@ import { MessageQueue } from "@Packages/message/message_queue";
|
|||||||
export const message = new ExtensionMessage();
|
export const message = new ExtensionMessage();
|
||||||
export const messageQueue = new MessageQueue();
|
export const messageQueue = new MessageQueue();
|
||||||
export const systemConfig = new SystemConfig(messageQueue);
|
export const systemConfig = new SystemConfig(messageQueue);
|
||||||
|
export const globalCache = new Map<string, any>();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Message } from "@arco-design/web-react";
|
import { Message } from "@arco-design/web-react";
|
||||||
import ChromeStorage from "./chrome_storage";
|
import ChromeStorage from "./chrome_storage";
|
||||||
import { defaultConfig } from "../../../eslint/linter-config";
|
import { defaultConfig } from "../../../packages/eslint/linter-config";
|
||||||
import { FileSystemType } from "@Packages/filesystem/factory";
|
import { FileSystemType } from "@Packages/filesystem/factory";
|
||||||
import { MessageQueue } from "@Packages/message/message_queue";
|
import { MessageQueue } from "@Packages/message/message_queue";
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import { globalCache } from "@App/pages/store/global";
|
||||||
import dts from "@App/template/scriptcat.d.tpl";
|
import dts from "@App/template/scriptcat.d.tpl";
|
||||||
|
import EventEmitter from "eventemitter3";
|
||||||
import { languages } from "monaco-editor";
|
import { languages } from "monaco-editor";
|
||||||
|
|
||||||
// 注册eslint
|
// 注册eslint
|
||||||
// const linterWorker = new Worker("/src/linter.worker.js");
|
const linterWorker = new Worker("/src/linter.worker.js");
|
||||||
|
|
||||||
export default function registerEditor() {
|
export default function registerEditor() {
|
||||||
window.MonacoEnvironment = {
|
window.MonacoEnvironment = {
|
||||||
@ -59,74 +61,74 @@ export default function registerEditor() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// // 处理quick fix
|
// 处理quick fix
|
||||||
// languages.registerCodeActionProvider("javascript", {
|
languages.registerCodeActionProvider("javascript", {
|
||||||
// provideCodeActions: (model /** ITextModel */, range /** Range */, context /** CodeActionContext */) => {
|
provideCodeActions: (model /** ITextModel */, range /** Range */, context /** CodeActionContext */) => {
|
||||||
// // const actions: languages.CodeAction[] = [];
|
const actions: languages.CodeAction[] = [];
|
||||||
// // const eslintFix = <Map<string, any>>Cache.getInstance().get("eslint-fix");
|
const eslintFix = <Map<string, any>>globalCache.get("eslint-fix");
|
||||||
// // for (let i = 0; i < context.markers.length; i += 1) {
|
for (let i = 0; i < context.markers.length; i += 1) {
|
||||||
// // // 判断有没有修复方案
|
// 判断有没有修复方案
|
||||||
// // const val = context.markers[i];
|
const val = context.markers[i];
|
||||||
// // const code = typeof val.code === "string" ? val.code : val.code!.value;
|
const code = typeof val.code === "string" ? val.code : val.code!.value;
|
||||||
// // const fix = eslintFix.get(
|
const fix = eslintFix.get(
|
||||||
// // `${code}|${val.startLineNumber}|${val.endLineNumber}|${val.startColumn}|${val.endColumn}`
|
`${code}|${val.startLineNumber}|${val.endLineNumber}|${val.startColumn}|${val.endColumn}`
|
||||||
// // );
|
);
|
||||||
// // if (fix) {
|
if (fix) {
|
||||||
// // const edit: languages.IWorkspaceTextEdit = {
|
const edit: languages.IWorkspaceTextEdit = {
|
||||||
// // resource: model.uri,
|
resource: model.uri,
|
||||||
// // textEdit: {
|
textEdit: {
|
||||||
// // range: fix.range,
|
range: fix.range,
|
||||||
// // text: fix.text,
|
text: fix.text,
|
||||||
// // },
|
},
|
||||||
// // versionId: undefined,
|
versionId: undefined,
|
||||||
// // };
|
};
|
||||||
// // actions.push(<languages.CodeAction>{
|
actions.push(<languages.CodeAction>{
|
||||||
// // title: `修复 ${code} 问题`,
|
title: `修复 ${code} 问题`,
|
||||||
// // diagnostics: [val],
|
diagnostics: [val],
|
||||||
// // kind: "quickfix",
|
kind: "quickfix",
|
||||||
// // edit: {
|
edit: {
|
||||||
// // edits: [edit],
|
edits: [edit],
|
||||||
// // },
|
},
|
||||||
// // isPreferred: true,
|
isPreferred: true,
|
||||||
// // });
|
});
|
||||||
// // }
|
}
|
||||||
// // }
|
}
|
||||||
|
|
||||||
// // const actions = context.markers.map((error) => {
|
// const actions = context.markers.map((error) => {
|
||||||
// // const edit: languages.IWorkspaceTextEdit = {
|
// const edit: languages.IWorkspaceTextEdit = {
|
||||||
// // resource: model.uri,
|
// resource: model.uri,
|
||||||
// // textEdit: {
|
// textEdit: {
|
||||||
// // range,
|
// range,
|
||||||
// // text: "console.log(1)",
|
// text: "console.log(1)",
|
||||||
// // },
|
|
||||||
// // versionId: undefined,
|
|
||||||
// // };
|
|
||||||
// // return <languages.CodeAction>{
|
|
||||||
// // title: ``,
|
|
||||||
// // diagnostics: [error],
|
|
||||||
// // kind: "quickfix",
|
|
||||||
// // edit: {
|
|
||||||
// // edits: [edit],
|
|
||||||
// // },
|
|
||||||
// // isPreferred: true,
|
|
||||||
// // };
|
|
||||||
// // });
|
|
||||||
// return {
|
|
||||||
// actions,
|
|
||||||
// dispose: () => {},
|
|
||||||
// };
|
|
||||||
// },
|
// },
|
||||||
|
// versionId: undefined,
|
||||||
|
// };
|
||||||
|
// return <languages.CodeAction>{
|
||||||
|
// title: ``,
|
||||||
|
// diagnostics: [error],
|
||||||
|
// kind: "quickfix",
|
||||||
|
// edit: {
|
||||||
|
// edits: [edit],
|
||||||
|
// },
|
||||||
|
// isPreferred: true,
|
||||||
|
// };
|
||||||
// });
|
// });
|
||||||
|
return {
|
||||||
|
actions,
|
||||||
|
dispose: () => {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// export class LinterWorker {
|
export class LinterWorker {
|
||||||
// static hook = new EventEmitter();
|
static hook = new EventEmitter();
|
||||||
|
|
||||||
// static sendLinterMessage(data: unknown) {
|
static sendLinterMessage(data: unknown) {
|
||||||
// linterWorker.postMessage(data);
|
linterWorker.postMessage(data);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// linterWorker.onmessage = (event) => {
|
linterWorker.onmessage = (event) => {
|
||||||
// LinterWorker.hook.emit("message", event.data);
|
LinterWorker.hook.emit("message", event.data);
|
||||||
// };
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user