Skip to content

Commit 2b33a70

Browse files
committed
💚 修复lint问题
1 parent eb4d1ab commit 2b33a70

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"test": "jest --coverage",
99
"lint": "eslint --ext .js,.ts,.tsx src/",
10+
"lint-fix": "eslint --ext .js,.ts,.tsx src/ --fix",
1011
"dev": "concurrently \"webpack --mode development --config ./webpack/webpack.dev.ts\" \"webpack --mode development --config ./webpack/webpack.inject.dev.ts\"",
1112
"build": "webpack --mode production --config ./webpack/webpack.prod.ts && concurrently \"npm run build:linter\" \"npm run build:inject && npm run build:no-split\"",
1213
"build:linter": "webpack --mode production --config ./webpack/webpack.linter.ts",
@@ -107,4 +108,4 @@
107108
"webpack-cli": "^5.1.4",
108109
"webpack-merge": "^5.9.0"
109110
}
110-
}
111+
}

src/pkg/utils/script.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
SCRIPT_TYPE_BACKGROUND,
99
SCRIPT_TYPE_CRONTAB,
1010
SCRIPT_TYPE_NORMAL,
11-
ScriptDAO
11+
ScriptDAO,
12+
type UserConfig,
1213
} from "@App/app/repo/scripts";
1314
import {
1415
Subscribe,
@@ -94,7 +95,6 @@ export async function fetchScriptInfo(
9495
isUpdate: boolean,
9596
uuid: string
9697
): Promise<ScriptInfo> {
97-
9898
const body = await fetchScriptBody(url);
9999
const ok = parseMetadata(body);
100100
if (!ok) {
@@ -165,7 +165,7 @@ export async function prepareScriptByCode(
165165
}
166166
const newUUID = uuid || uuidv4();
167167
const config: UserConfig | undefined = parseUserConfig(code);
168-
let script: Script = {
168+
const script: Script = {
169169
id: 0,
170170
uuid: newUUID,
171171
name: metadata.name[0],
@@ -196,24 +196,32 @@ export async function prepareScriptByCode(
196196
}
197197
if (old) {
198198
if (
199-
(old.type === SCRIPT_TYPE_NORMAL &&
200-
script.type !== SCRIPT_TYPE_NORMAL) ||
201-
(script.type === SCRIPT_TYPE_NORMAL &&
202-
old.type !== SCRIPT_TYPE_NORMAL)
199+
(old.type === SCRIPT_TYPE_NORMAL && script.type !== SCRIPT_TYPE_NORMAL) ||
200+
(script.type === SCRIPT_TYPE_NORMAL && old.type !== SCRIPT_TYPE_NORMAL)
203201
) {
204202
throw new Error("脚本类型不匹配,普通脚本与后台脚本不能互相转变");
205203
}
206-
const { id, uuid, createtime, lastruntime, error, sort, selfMetadata, subscribeUrl, status } = old;
204+
const {
205+
id,
206+
uuid: oldUUID,
207+
createtime,
208+
lastruntime,
209+
error,
210+
sort,
211+
selfMetadata,
212+
subscribeUrl,
213+
status,
214+
} = old;
207215
Object.assign(script, {
208216
id,
209-
uuid,
217+
oldUUID,
210218
createtime,
211219
lastruntime,
212220
error,
213221
sort,
214222
selfMetadata: selfMetadata || {},
215223
subscribeUrl,
216-
status
224+
status,
217225
});
218226
} else {
219227
// 前台脚本默认开启
@@ -223,7 +231,6 @@ export async function prepareScriptByCode(
223231
script.checktime = Date.now();
224232
}
225233
return { script, oldScript: old };
226-
227234
}
228235

229236
// 通过代码解析出脚本信息 (Subscribe)
@@ -246,7 +253,7 @@ export async function prepareSubscribeByCode(
246253
code,
247254
author: (metadata.author && metadata.author[0]) || "",
248255
scripts: {},
249-
metadata: metadata,
256+
metadata,
250257
status: SUBSCRIBE_STATUS_ENABLE,
251258
createtime: Date.now(),
252259
updatetime: Date.now(),

src/pkg/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export async function getCurrentTab() {
166166
// `tab` will either be a `tabs.Tab` instance or `undefined`.
167167
const [tab] = await new Promise<chrome.tabs.Tab[]>((resolve, reject) => {
168168
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (results) => {
169-
const lastError = chrome.runtime.lastError;
169+
const {lastError} = chrome.runtime;
170170
if (lastError) {
171171
reject(new Error(lastError.message));
172172
return;
@@ -205,7 +205,7 @@ export async function openInCurrentTab(url: string) {
205205
delete createProperties.windowId;
206206
try {
207207
await chrome.tabs.create(createProperties);
208-
return;
208+
209209
} catch {
210210
// do nothing
211211
}

0 commit comments

Comments
 (0)