Skip to content

Commit 0ff6ddd

Browse files
committed
✨ 支持自定义eslint
1 parent cf571c8 commit 0ff6ddd

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.11.0-beta",
3+
"version": "0.11.0-beta.1",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

src/linter.worker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const config = {
1313
parserOptions: {
1414
ecmaVersion: "latest",
1515
sourceType: "script",
16-
ecmaFeatures: { globalReturn: true },
16+
ecmaFeatures: {
17+
globalReturn: true,
18+
},
1719
},
1820
rules: {
1921
"constructor-super": ["error"],

src/pages/components/CodeEditor/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import IoC from "@App/app/ioc";
2+
import { SystemConfig } from "@App/pkg/config/config";
13
import { LinterWorker } from "@App/pkg/utils/monaco-editor";
24
import { editor } from "monaco-editor";
35
import React, { useEffect, useImperativeHandle, useState } from "react";
@@ -78,6 +80,10 @@ const CodeEditor: React.ForwardRefRenderFunction<
7880
}, [code, diffCode]);
7981

8082
useEffect(() => {
83+
const config = IoC.instance(SystemConfig) as SystemConfig;
84+
if (!config.enableEslint) {
85+
return () => {};
86+
}
8187
if (!monacoEditor) {
8288
return () => {};
8389
}

src/pages/options/routes/Setting.tsx

+48
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Button,
44
Card,
55
Checkbox,
6+
Input,
67
Message,
78
Select,
89
Space,
@@ -11,6 +12,8 @@ import FileSystemParams from "@App/pages/components/FileSystemParams";
1112
import { SystemConfig } from "@App/pkg/config/config";
1213
import IoC from "@App/app/ioc";
1314
import FileSystemFactory, { FileSystemType } from "@Pkg/filesystem/factory";
15+
import Title from "@arco-design/web-react/es/Typography/title";
16+
import { IconQuestionCircleFill } from "@arco-design/web-react/icon";
1417

1518
function Setting() {
1619
const systemConfig = IoC.instance(SystemConfig) as SystemConfig;
@@ -32,6 +35,9 @@ function Setting() {
3235
direction="vertical"
3336
style={{
3437
width: "100%",
38+
height: "100%",
39+
overflow: "auto",
40+
position: "relative",
3541
}}
3642
>
3743
<Card title="脚本同步" bordered={false}>
@@ -137,6 +143,48 @@ function Setting() {
137143
</Checkbox>
138144
</Space>
139145
</Card>
146+
<Card title="ESLint" bordered={false}>
147+
<Space direction="vertical" className="w-full">
148+
<Checkbox
149+
onChange={(checked) => {
150+
systemConfig.enableEslint = checked;
151+
}}
152+
defaultChecked={systemConfig.enableEslint}
153+
>
154+
开启ESLint
155+
</Checkbox>
156+
<Title heading={5}>
157+
ESLint规则{" "}
158+
<Button
159+
type="text"
160+
style={{
161+
height: 24,
162+
}}
163+
icon={
164+
<IconQuestionCircleFill
165+
style={{
166+
margin: 0,
167+
}}
168+
/>
169+
}
170+
href="https://eslint.org/play/"
171+
target="_blank"
172+
iconOnly
173+
/>
174+
</Title>
175+
<Input.TextArea
176+
placeholder="请输入eslint规则,可以从https://eslint.org/play/下载配置"
177+
autoSize={{
178+
minRows: 4,
179+
maxRows: 8,
180+
}}
181+
defaultValue={systemConfig.eslintConfig}
182+
onBlur={(v) => {
183+
systemConfig.eslintConfig = v.target.value;
184+
}}
185+
/>
186+
</Space>
187+
</Card>
140188
</Space>
141189
);
142190
}

src/pkg/config/config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,20 @@ export class SystemConfig {
178178
set scriptCatFlag(val: string) {
179179
this.set("script_cat_flag", val);
180180
}
181+
182+
get enableEslint() {
183+
return <boolean>this.cache.get("enable_eslint");
184+
}
185+
186+
set enableEslint(val: boolean) {
187+
this.set("enable_eslint", val);
188+
}
189+
190+
get eslintConfig() {
191+
return <string>this.cache.get("eslint_config") || "";
192+
}
193+
194+
set eslintConfig(v: string) {
195+
this.set("eslint_config", v);
196+
}
181197
}

webpack/webpack.dev.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CompressionPlugin from "compression-webpack-plugin";
44
import common from "../webpack.config";
55

66
const src = `${__dirname}/../src`;
7+
const dist = `${__dirname}/../dist`;
78

89
common.entry = {
910
// @ts-ignore
@@ -14,14 +15,16 @@ common.entry = {
1415
"ts.worker": "monaco-editor/esm/vs/language/typescript/ts.worker.js",
1516
};
1617

18+
common.output = {
19+
path: `${dist}/ext/src`,
20+
filename: "[name].js",
21+
clean: false,
22+
};
23+
1724
// 取消splitChunks
1825
common.optimization = {};
1926

20-
common.optimization = {};
2127
export default merge(common, {
22-
output: {
23-
clean: false,
24-
},
2528
watch: true,
2629
devtool: "inline-source-map",
2730
plugins: [

0 commit comments

Comments
 (0)