优化:使用 eslint 处理

This commit is contained in:
Hmjz100
2026-04-19 03:30:52 +08:00
parent 65749feb0b
commit 6155ad4209
4 changed files with 1037 additions and 943 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
package-lock.json

45
eslint.config.mjs Normal file
View File

@@ -0,0 +1,45 @@
import js from "@eslint/js";
export default [
js.configs.recommended,
{
files: ["**/*.user.js"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "script", // 适配油猴脚本的非模块化特性
globals: {
// 基础环境
window: "readonly", document: "readonly", console: "readonly",
location: "readonly", navigator: "readonly", history: "readonly",
localStorage: "readonly", sessionStorage: "readonly",
setTimeout: "readonly", setInterval: "readonly",
clearTimeout: "readonly", clearInterval: "readonly",
fetch: "readonly", URL: "readonly", URLSearchParams: "readonly",
Blob: "readonly", File: "readonly", FormData: "readonly",
alert: "readonly", confirm: "readonly", prompt: "readonly",
requestAnimationFrame: "readonly", cancelAnimationFrame: "readonly",
MutationObserver: "readonly", HTMLElement: "readonly",
btoa: "readonly", atob: "readonly", structuredClone: "readonly",
// GM 环境
GM: "readonly", GM_info: "readonly", GM_getValue: "readonly", GM_setValue: "readonly",
GM_deleteValue: "readonly", GM_listValues: "readonly", GM_addStyle: "readonly",
GM_xmlhttpRequest: "readonly", GM_registerMenuCommand: "readonly",
GM_openInTab: "readonly", GM_setClipboard: "readonly",
GM_getResourceText: "readonly", unsafeWindow: "readonly",
// 第三方库
$: "readonly", jQuery: "readonly", Swal: "readonly", md5: "readonly"
}
},
rules: {
"prefer-const": ["error", { "destructuring": "all" }],
"no-unused-vars": "warn",
"no-empty": "off",
"no-useless-escape": "off",
"no-prototype-builtins": "off",
"no-control-regex": "off",
"no-irregular-whitespace": "off"
}
}
];

34
package.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "linkswift",
"version": "1.1.3.1",
"description": "一个基于 JavaScript 的网盘文件下载地址获取工具",
"main": "eslint.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"check": "npx eslint . --fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hmjz100/LinkSwift.git"
},
"keywords": [
"linkswift",
"link",
"swift",
"download",
"file",
"address",
"get"
],
"author": "hmjz100",
"license": "AGPL-3.0",
"type": "commonjs",
"bugs": {
"url": "https://github.com/hmjz100/LinkSwift/issues"
},
"homepage": "https://github.com/hmjz100/LinkSwift#readme",
"devDependencies": {
"@eslint/js": "^10.0.1",
"eslint": "^10.2.1"
}
}

File diff suppressed because it is too large Load Diff