Skip to content

Commit f49e20f

Browse files
committed
🎨 修复eslint问题
1 parent b08187a commit f49e20f

File tree

95 files changed

+430
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+430
-395
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ jobs:
2323
node-version: 22
2424
cache: 'pnpm'
2525

26+
- name: Install dependencies
27+
run: pnpm i --frozen-lockfile
28+
29+
- name: Lint
30+
run: pnpm run lint
31+
2632
- name: Unit Test
2733
run: |
28-
pnpm i --frozen-lockfile
2934
pnpm test
3035
pnpm run coverage
3136

eslint.config.mjs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import reactHooks from "eslint-plugin-react-hooks";
44
import reactJsx from "eslint-plugin-react/configs/jsx-runtime.js";
55
import react from "eslint-plugin-react/configs/recommended.js";
66
import ts from "typescript-eslint";
7+
import globals from "globals";
78

89
export default [
910
{
10-
env: {
11-
browser: true,
12-
es2020: true,
13-
webextensions: true,
11+
languageOptions: {
12+
ecmaVersion: 2020,
13+
sourceType: "module",
14+
globals: {
15+
...globals.browser,
16+
...globals.webextensions,
17+
},
1418
},
1519
},
1620
js.configs.recommended,
@@ -32,8 +36,17 @@ export default [
3236
"@typescript-eslint/no-explicit-any": "off",
3337
"@typescript-eslint/ban-ts-comment": "off",
3438
"@typescript-eslint/no-unused-expressions": "off",
39+
"@typescript-eslint/consistent-type-imports": "error",
40+
"@typescript-eslint/no-unused-vars": [
41+
"error",
42+
{
43+
"argsIgnorePattern": "^_",
44+
"varsIgnorePattern": "^_",
45+
"caughtErrorsIgnorePattern": "^_"
46+
}
47+
],
3548
...reactHooks.configs.recommended.rules,
3649
},
3750
},
38-
{ ignores: ["dist/"] },
51+
{ ignores: ["dist/", "example/"] },
3952
];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default class Downloads {
2-
download(_: any, callback: Function) {
2+
download(_: any, callback: () => void) {
33
callback && callback();
44
}
55
}

packages/chrome-extension-mock/web_reqeuest.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
export default class WebRequest {
2-
sendHeader?: (
3-
details: chrome.webRequest.WebRequestHeadersDetails
4-
) => chrome.webRequest.BlockingResponse | void;
2+
sendHeader?: (details: chrome.webRequest.OnSendHeadersDetails) => chrome.webRequest.BlockingResponse | void;
53

64
mockXhr(xhr: any): any {
7-
// eslint-disable-next-line no-underscore-dangle
8-
const _this = this;
9-
// eslint-disable-next-line func-names
10-
return function () {
11-
// eslint-disable-next-line new-cap
5+
return () => {
126
const ret = new xhr();
137
const header: chrome.webRequest.HttpHeader[] = [];
148
ret.setRequestHeader = (k: string, v: string) => {
@@ -23,14 +17,13 @@ export default class WebRequest {
2317
name: "cookie",
2418
value: "website=example.com",
2519
});
26-
const resp = _this.sendHeader?.({
20+
const resp = this.sendHeader?.({
2721
method: ret.method,
2822
url: ret.url,
2923
requestHeaders: header,
3024
initiator: chrome.runtime.getURL(""),
31-
} as chrome.webRequest.WebRequestHeadersDetails) as chrome.webRequest.BlockingResponse;
25+
} as chrome.webRequest.OnSendHeadersDetails) as chrome.webRequest.BlockingResponse;
3226
resp.requestHeaders?.forEach((h) => {
33-
// eslint-disable-next-line no-underscore-dangle
3427
ret._authorRequestHeaders!.addHeader(h.name, h.value);
3528
});
3629
oldSend(data);

packages/cloudscript/cloudscript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Script } from "@App/app/repo/scripts";
2-
import { Value } from "@App/app/repo/value";
1+
import type { Script } from "@App/app/repo/scripts";
2+
import type { Value } from "@App/app/repo/value";
33
import { valueClient } from "@App/pages/store/features/script";
44

55
export type ExportCookies = {

packages/cloudscript/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ExportTarget } from "@App/app/repo/export";
2-
import { ExportParams } from "./cloudscript";
1+
import type { ExportTarget } from "@App/app/repo/export";
2+
import type { ExportParams } from "./cloudscript";
33
import LocalCloudScript from "./local";
44

55
export interface CloudScriptParams {

packages/cloudscript/local.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ExtVersion } from "@App/app/const";
2-
import { Script } from "@App/app/repo/scripts";
3-
import { Value } from "@App/app/repo/value";
4-
import JSZip from "jszip";
2+
import type { Script } from "@App/app/repo/scripts";
3+
import type { Value } from "@App/app/repo/value";
4+
import type JSZip from "jszip";
55
import packageTpl from "@App/template/cloudcat-package/package.tpl";
66
import utilsTpl from "@App/template/cloudcat-package/utils.tpl";
77
import indexTpl from "@App/template/cloudcat-package/index.tpl";
8-
import CloudScript, { ExportCookies, ExportParams } from "./cloudscript";
8+
import type { ExportCookies, ExportParams } from "./cloudscript";
9+
import type CloudScript from "./cloudscript";
910

1011
// 导出到本地,一个可执行到npm包
1112
export default class LocalCloudScript implements CloudScript {

packages/eslint/compat-grant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/* eslint-disable no-undef */
13
const compat_grant = require("eslint-plugin-userscripts/dist/data/compat-grant.js");
24
const compatMap = {
35
CAT_userConfig: [{ type: "scriptcat", versionConstraint: ">=0.11.0-beta" }],

packages/eslint/compat-headers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/* eslint-disable no-undef */
13
const compat_headers = require("eslint-plugin-userscripts/dist/data/compat-headers.js");
24

35
const compatMap = {

packages/eslint/linter-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { configs, rules } = require("eslint-plugin-userscripts");
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
const { configs } = require("eslint-plugin-userscripts");
23

34
// 默认规则
45
const config = {

0 commit comments

Comments
 (0)