This commit is contained in:
Ludy 2025-11-15 01:49:35 +08:00 committed by GitHub
commit 09374cdff5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 1239 additions and 570 deletions

View File

@ -3,31 +3,133 @@
import eslint from '@eslint/js'; import eslint from '@eslint/js';
import globals from 'globals'; import globals from 'globals';
import { defineConfig } from 'eslint/config'; import { defineConfig } from 'eslint/config';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import reactPlugin from 'eslint-plugin-react';
import tseslint from 'typescript-eslint'; import tseslint from 'typescript-eslint';
import { fileURLToPath } from 'node:url';
import importPlugin from 'eslint-plugin-import'; import importPlugin from 'eslint-plugin-import';
const srcGlobs = [ const ignorePatterns = [
'src/**/*.{js,mjs,jsx,ts,tsx}', "__tests/**",
"dist/**",
"./dist/**",
"dist/**/*",
"./dist/**/*",
"**/dist/**",
"**/dist/**/*",
"build/**",
"./build/**",
"build/**/*",
"./build/**/*",
"**/build/**",
"**/build/**/*",
"node_modules/**",
"./node_modules/**",
"node_modules/**/*",
"./node_modules/**/*",
"**/node_modules/**",
"**/node_modules/**/*",
"public/**",
"./public/**",
"public/**/*",
"./public/**/*",
"**/public/**",
"**/public/**/*",
"src-tauri/**",
"./src-tauri/**",
"src-tauri/**/*",
"./src-tauri/**/*",
"**/src-tauri/**",
"**/src-tauri/**/*"
]; ];
const jsGlobs = ['{src,frontend/src}/**/*.{js,jsx}'];
const srcGlobs = ['{src,frontend/src}/**/*.{ts,tsx}'];
const nodeGlobs = [ const nodeGlobs = [
'scripts/**/*.{js,ts,mjs}', 'scripts/**/*.{js,ts,mjs}',
'*.config.{js,ts,mjs}', 'vite.config.ts',
'vitest.config.ts',
'vitest.minimal.config.ts',
'playwright.config.ts',
'tailwind.config.js',
'postcss.config.js',
'eslint.config.mjs',
]; ];
const __dirname = fileURLToPath(new URL('./', import.meta.url));
export default defineConfig( export default defineConfig(
{ ignores: ignorePatterns },
// Shared settings for all files
{
ignores: ignorePatterns,
rules: {
semi: "error",
"prefer-const": "error",
},
},
// Core rules for all source files
eslint.configs.recommended,
// Specific rules for different types of files
{ {
// Everything that contains 3rd party code that we don't want to lint // Everything that contains 3rd party code that we don't want to lint
ignores: [ ignores: [
'dist', ...ignorePatterns,
'node_modules', ...jsGlobs,
'public', ...nodeGlobs
'src-tauri',
], ],
files: srcGlobs,
extends: [
reactPlugin.configs.flat.recommended,
reactPlugin.configs.flat['jsx-runtime'],
...tseslint.configs.recommendedTypeChecked,
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: {
allowDefaultProject: [
'src/components/tooltips/usePageSelectionTips.tsx',
'src/reportWebVitals.js',
'src/setupTests.js'
],
defaultProject: './tsconfig.json'
},
tsconfigRootDir: __dirname,
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
react: reactPlugin,
'react-hooks': reactHooksPlugin,
},
settings: {
react: {
version: 'detect',
},
}, },
eslint.configs.recommended,
tseslint.configs.recommended,
{
rules: { rules: {
// Enabled rules
'react-hooks/exhaustive-deps': 'error',
'react-hooks/rules-of-hooks': 'error',
'react/display-name': 'error',
'react/no-children-prop': 'error',
'react/prop-types': 'error',
'react/no-unescaped-entities': 'error',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/class-literal-property-style': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'no-restricted-imports': [ 'no-restricted-imports': [
'error', 'error',
{ {
@ -44,38 +146,106 @@ export default defineConfig(
allowInterfaces: 'with-single-extends', allowInterfaces: 'with-single-extends',
}, },
], ],
'@typescript-eslint/no-explicit-any': 'off', // Temporarily disabled until codebase conformant "@typescript-eslint/no-explicit-any": "error",
'@typescript-eslint/no-require-imports': 'off', // Temporarily disabled until codebase conformant "@typescript-eslint/no-require-imports": "error",
'@typescript-eslint/no-unused-vars': [ "@typescript-eslint/no-unused-vars": [
'error', "error",
{ {
'args': 'all', // All function args must be used (or explicitly ignored) args: 'all', // All function args must be used (or explicitly ignored)
'argsIgnorePattern': '^_', // Allow unused variables beginning with an underscore argsIgnorePattern: '^_', // Allow unused variables beginning with an underscore
'caughtErrors': 'all', // Caught errors must be used (or explicitly ignored) caughtErrors: 'all', // Caught errors must be used (or explicitly ignored)
'caughtErrorsIgnorePattern': '^_', // Allow unused variables beginning with an underscore caughtErrorsIgnorePattern: '^_', // Allow unused variables beginning with an underscore
'destructuredArrayIgnorePattern': '^_', // Allow unused variables beginning with an underscore destructuredArrayIgnorePattern: '^_', // Allow unused variables beginning with an underscore
'varsIgnorePattern': '^_', // Allow unused variables beginning with an underscore varsIgnorePattern: '^_', // Allow unused variables beginning with an underscore
'ignoreRestSiblings': true, // Allow unused variables when removing attributes from objects (otherwise this requires explicit renaming like `({ x: _x, ...y }) => y`, which is clunky) ignoreRestSiblings: true, // Allow unused variables when removing attributes from objects (otherwise this requires explicit renaming like `({ x: _x, ...y }) => y`, which is clunky)
}, },
], ],
"no-redeclare": "error",
// Disabled rules (too restrictive or not useful for this codebase)
'react/react-in-jsx-scope': 'off', // Not needed with React 17+
"no-unused-vars": "off", // Use the TypeScript version instead
"no-undef": "off", // Use the TypeScript version instead
'@typescript-eslint/no-empty-function': 'off', // Ignore empty functions (they're often useful)
'@typescript-eslint/prefer-nullish-coalescing': 'off', // Ignore preference of ?? over || (both have their uses)
'@typescript-eslint/unbound-method': 'off', // Ignore unbound methods (they're often useful)
'@typescript-eslint/restrict-template-expressions': 'off', // Ignore restrictions on template expressions (they're often useful)
'@typescript-eslint/dot-notation': 'off', // Ignore dot notation (it's often more readable to use bracket notation)
'@typescript-eslint/non-nullable-type-assertion-style': 'off', // Ignore preference of using !. over other methods (both have their uses)
'@typescript-eslint/consistent-generic-constructors': 'off', // Ignore preference of using new Array<T>() over Array<T> (both have their uses)
'@typescript-eslint/no-redundant-type-constituents': 'off', // Ignore redundant type constituents (they're often useful for clarity)
'@typescript-eslint/array-type': 'off', // see: https://github.com/Stirling-Tools/Stirling-PDF/pull/4521#issuecomment-3346477814
// Should be checked
"@typescript-eslint/no-inferrable-types": "error",
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/only-throw-error': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/prefer-promise-reject-errors': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-misused-promises': 'error',
}, },
}, },
// Config for browser scripts
{
files: srcGlobs,
languageOptions: {
globals: {
...globals.browser,
}
}
},
// Config for node scripts
{ {
ignores: [
...ignorePatterns,
...jsGlobs
],
files: nodeGlobs, files: nodeGlobs,
extends: [
tseslint.configs.disableTypeChecked
],
languageOptions: { languageOptions: {
globals: { globals: {
...globals.node, ...globals.node,
} },
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
sourceType: 'module',
},
},
{
files: jsGlobs,
ignores: [
...nodeGlobs,
...ignorePatterns
],
extends: [
reactPlugin.configs.flat.recommended,
eslint.configs.recommended,
],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
tsconfigRootDir: __dirname,
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
react: reactPlugin,
'react-hooks': reactHooksPlugin,
},
settings: { react: { version: 'detect' } },
rules: {
'no-unused-vars': 'error',
'no-console': 'error',
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
} }
}, },
// Config for import plugin // Config for import plugin

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,6 @@
"@embedpdf/plugin-viewport": "^1.4.1", "@embedpdf/plugin-viewport": "^1.4.1",
"@embedpdf/plugin-zoom": "^1.4.1", "@embedpdf/plugin-zoom": "^1.4.1",
"@emotion/react": "^11.14.0", "@emotion/react": "^11.14.0",
"@tauri-apps/api": "^2.5.0",
"@tauri-apps/plugin-fs": "^2.4.0",
"@emotion/styled": "^11.14.1", "@emotion/styled": "^11.14.1",
"@iconify/react": "^6.0.2", "@iconify/react": "^6.0.2",
"@mantine/core": "^8.3.1", "@mantine/core": "^8.3.1",
@ -39,9 +37,11 @@
"@reactour/tour": "^3.8.0", "@reactour/tour": "^3.8.0",
"@tailwindcss/postcss": "^4.1.13", "@tailwindcss/postcss": "^4.1.13",
"@tanstack/react-virtual": "^3.13.12", "@tanstack/react-virtual": "^3.13.12",
"@tauri-apps/api": "^2.5.0",
"@tauri-apps/plugin-fs": "^2.4.0",
"autoprefixer": "^10.4.21", "autoprefixer": "^10.4.21",
"axios": "^1.12.2", "axios": "^1.12.2",
"globals": "^16.4.0", "globals": "^16.5.0",
"i18next": "^25.5.2", "i18next": "^25.5.2",
"i18next-browser-languagedetector": "^8.2.0", "i18next-browser-languagedetector": "^8.2.0",
"i18next-http-backend": "^3.0.2", "i18next-http-backend": "^3.0.2",
@ -110,15 +110,16 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@tauri-apps/cli": "^2.5.0", "@eslint/js": "^9.39.1",
"@eslint/js": "^9.36.0",
"@iconify-json/material-symbols": "^1.2.37", "@iconify-json/material-symbols": "^1.2.37",
"@iconify/utils": "^3.0.2", "@iconify/utils": "^3.0.2",
"@playwright/test": "^1.55.0", "@playwright/test": "^1.55.0",
"@tauri-apps/cli": "^2.5.0",
"@testing-library/dom": "^10.4.1", "@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.8.0", "@testing-library/jest-dom": "^6.8.0",
"@testing-library/react": "^16.3.0", "@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1", "@testing-library/user-event": "^14.6.1",
"@tsconfig/vite-react": "^7.0.1",
"@types/gapi": "^0.0.47", "@types/gapi": "^0.0.47",
"@types/gapi.client.drive-v3": "^0.0.5", "@types/gapi.client.drive-v3": "^0.0.5",
"@types/google.accounts": "^0.0.18", "@types/google.accounts": "^0.0.18",
@ -126,14 +127,17 @@
"@types/node": "^24.5.2", "@types/node": "^24.5.2",
"@types/react": "^19.1.13", "@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9", "@types/react-dom": "^19.1.9",
"@typescript-eslint/eslint-plugin": "^8.44.1", "@typescript-eslint/eslint-plugin": "^8.46.3",
"@typescript-eslint/parser": "^8.44.1", "@typescript-eslint/parser": "^8.46.3",
"@vitejs/plugin-react-swc": "^4.1.0", "@vitejs/plugin-react-swc": "^4.1.0",
"@vitest/coverage-v8": "^3.2.4", "@vitest/coverage-v8": "^3.2.4",
"eslint": "^9.36.0", "eslint": "^9.39.1",
"eslint-import-resolver-typescript": "^4.4.4", "eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0", "eslint-plugin-import": "^2.32.0",
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"globals": "^16.5.0",
"jsdom": "^27.0.0", "jsdom": "^27.0.0",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"madge": "^8.0.0", "madge": "^8.0.0",
@ -142,8 +146,8 @@
"postcss-preset-mantine": "^1.18.0", "postcss-preset-mantine": "^1.18.0",
"postcss-simple-vars": "^7.0.1", "postcss-simple-vars": "^7.0.1",
"puppeteer": "^24.25.0", "puppeteer": "^24.25.0",
"typescript": "^5.9.2", "typescript": "^5.9.3",
"typescript-eslint": "^8.44.1", "typescript-eslint": "^8.46.2",
"vite": "^7.1.7", "vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4", "vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.2.4" "vitest": "^3.2.4"

View File

@ -1,4 +1,5 @@
{ {
"extends": "@tsconfig/vite-react/tsconfig.json",
"compilerOptions": { "compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */ /* Visit https://aka.ms/tsconfig to read more about this file */
@ -11,7 +12,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */ /* Language and Environment */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"jsx": "react-jsx", /* Specify what JSX code is generated. */ "jsx": "react-jsx", /* Specify what JSX code is generated. */
// "libReplacement": true, /* Enable lib replacement. */ // "libReplacement": true, /* Enable lib replacement. */
@ -42,7 +43,7 @@
}, },
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */ "types": ["vite/client", "vitest/globals"], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
@ -66,7 +67,7 @@
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "noEmit": true, /* Disable emitting files from a compilation. */ "noEmit": true, /* Disable emitting files from a compilation. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */ // "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */ // "removeComments": true, /* Disable emitting comments. */
@ -85,9 +86,9 @@
/* Interop Constraints */ /* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ "verbatimModuleSyntax": false, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ "erasableSyntaxOnly": false, /* Do not allow runtime constructs that are not part of ECMAScript. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
@ -104,8 +105,8 @@
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ "noUnusedLocals": false, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ "noUnusedParameters": false, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
@ -121,6 +122,17 @@
}, },
"include": [ "include": [
"src", "src",
"src/global.d.ts" "src/global.d.ts",
, "vite.config.ts" ] "vite.config.ts",
"vitest.config.ts",
"vitest.minimal.config.ts",
"playwright.config.ts",
"tailwind.config.js",
"postcss.config.js"
],
"exclude": [
"dist",
"node_modules",
"public"
]
} }