mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 23:20:46 +00:00
Replaces all direct usage of browser globals and infrastructure service imports in UI components with dedicated application/state backend hooks. Introduces lint rules to prevent direct access to backend bridges and localStorage from components, promoting a cleaner separation of concerns and improved maintainability. Moves user preferences (e.g., port forwarding form mode) to persistent state hooks, updates port forwarding and SFTP logic to rely on backend hooks, and centralizes logging through a logger utility. Cleans up debug code and removes obsolete scripts from HTML. Improves testability, prepares for alternative backend implementations, and enforces architectural boundaries.
172 lines
4.8 KiB
JavaScript
172 lines
4.8 KiB
JavaScript
import js from "@eslint/js";
|
|
import tsParser from "@typescript-eslint/parser";
|
|
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
|
import unusedImports from "eslint-plugin-unused-imports";
|
|
import reactHooks from "eslint-plugin-react-hooks";
|
|
|
|
export default [
|
|
js.configs.recommended,
|
|
{
|
|
ignores: ["node_modules/**", "dist/**", "electron/**", "scripts/**"],
|
|
},
|
|
{
|
|
files: ["**/*.{ts,tsx}"],
|
|
languageOptions: {
|
|
parser: tsParser,
|
|
parserOptions: {
|
|
ecmaVersion: "latest",
|
|
sourceType: "module",
|
|
ecmaFeatures: {
|
|
jsx: true,
|
|
},
|
|
},
|
|
globals: {
|
|
// Browser globals
|
|
window: "readonly",
|
|
document: "readonly",
|
|
navigator: "readonly",
|
|
console: "readonly",
|
|
setTimeout: "readonly",
|
|
clearTimeout: "readonly",
|
|
setInterval: "readonly",
|
|
clearInterval: "readonly",
|
|
requestAnimationFrame: "readonly",
|
|
cancelAnimationFrame: "readonly",
|
|
fetch: "readonly",
|
|
URL: "readonly",
|
|
URLSearchParams: "readonly",
|
|
FormData: "readonly",
|
|
Blob: "readonly",
|
|
File: "readonly",
|
|
FileReader: "readonly",
|
|
AbortController: "readonly",
|
|
AbortSignal: "readonly",
|
|
Event: "readonly",
|
|
EventTarget: "readonly",
|
|
CustomEvent: "readonly",
|
|
MouseEvent: "readonly",
|
|
KeyboardEvent: "readonly",
|
|
DragEvent: "readonly",
|
|
ClipboardEvent: "readonly",
|
|
HTMLElement: "readonly",
|
|
HTMLInputElement: "readonly",
|
|
HTMLTextAreaElement: "readonly",
|
|
HTMLButtonElement: "readonly",
|
|
HTMLDivElement: "readonly",
|
|
HTMLFormElement: "readonly",
|
|
Element: "readonly",
|
|
Node: "readonly",
|
|
NodeList: "readonly",
|
|
MutationObserver: "readonly",
|
|
ResizeObserver: "readonly",
|
|
IntersectionObserver: "readonly",
|
|
localStorage: "readonly",
|
|
sessionStorage: "readonly",
|
|
crypto: "readonly",
|
|
performance: "readonly",
|
|
confirm: "readonly",
|
|
alert: "readonly",
|
|
prompt: "readonly",
|
|
getComputedStyle: "readonly",
|
|
atob: "readonly",
|
|
btoa: "readonly",
|
|
// Node.js globals (for Electron)
|
|
process: "readonly",
|
|
global: "readonly",
|
|
Buffer: "readonly",
|
|
__dirname: "readonly",
|
|
__filename: "readonly",
|
|
module: "readonly",
|
|
require: "readonly",
|
|
exports: "readonly",
|
|
},
|
|
},
|
|
plugins: {
|
|
"@typescript-eslint": tsPlugin,
|
|
"unused-imports": unusedImports,
|
|
"react-hooks": reactHooks,
|
|
},
|
|
rules: {
|
|
// Disable base rules that conflict with TypeScript
|
|
"no-unused-vars": "off",
|
|
"no-undef": "off", // TypeScript handles this
|
|
|
|
// TypeScript unused vars (disabled in favor of unused-imports)
|
|
"@typescript-eslint/no-unused-vars": "off",
|
|
|
|
// Disallow any type
|
|
"@typescript-eslint/no-explicit-any": "error",
|
|
|
|
// Unused imports plugin - this is the main feature you want
|
|
"unused-imports/no-unused-imports": "warn",
|
|
"unused-imports/no-unused-vars": [
|
|
"warn",
|
|
{
|
|
vars: "all",
|
|
varsIgnorePattern: "^_",
|
|
args: "after-used",
|
|
argsIgnorePattern: "^_",
|
|
},
|
|
],
|
|
|
|
// React Hooks rules
|
|
"react-hooks/rules-of-hooks": "error",
|
|
"react-hooks/exhaustive-deps": "warn",
|
|
|
|
// Downgrade some rules to warnings (less critical)
|
|
"no-empty": "warn",
|
|
"no-useless-escape": "warn",
|
|
"no-case-declarations": "warn",
|
|
},
|
|
},
|
|
{
|
|
files: ["**/*.{ts,tsx}"],
|
|
rules: {
|
|
"no-restricted-properties": [
|
|
"error",
|
|
{
|
|
object: "window",
|
|
property: "netcatty",
|
|
message:
|
|
"Do not access window.netcatty directly; use netcattyBridge or an application/state backend hook.",
|
|
},
|
|
],
|
|
"no-restricted-globals": ["error", "localStorage", "sessionStorage"],
|
|
},
|
|
},
|
|
{
|
|
files: ["infrastructure/services/netcattyBridge.ts"],
|
|
rules: {
|
|
"no-restricted-properties": "off",
|
|
},
|
|
},
|
|
{
|
|
files: ["infrastructure/persistence/localStorageAdapter.ts"],
|
|
rules: {
|
|
"no-restricted-globals": "off",
|
|
},
|
|
},
|
|
{
|
|
files: ["components/**/*.{ts,tsx}"],
|
|
rules: {
|
|
"no-restricted-imports": [
|
|
"error",
|
|
{
|
|
patterns: [
|
|
{
|
|
group: [
|
|
"../infrastructure/persistence/*",
|
|
"../infrastructure/services/*",
|
|
"../../infrastructure/persistence/*",
|
|
"../../infrastructure/services/*",
|
|
],
|
|
message:
|
|
"Components should not import infrastructure persistence/services; use application/state hooks instead.",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
];
|