From 8dafafa74985d5948bcb874142eb1424736fee73 Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Thu, 20 Nov 2025 21:22:44 -0500 Subject: [PATCH] ci: mandatory eslint rules for build This commit adds verification for statically identifiable definite errors. Sometimes global variables used will be falsely reported as undefined variables in which case the new file `mandatory.eslint.config.js` should be updated to include these definitions in the narrowest scope possible that has these definitions --- eslint/mandatory.eslint.config.js | 86 +++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 eslint/mandatory.eslint.config.js diff --git a/eslint/mandatory.eslint.config.js b/eslint/mandatory.eslint.config.js new file mode 100644 index 00000000..e3036508 --- /dev/null +++ b/eslint/mandatory.eslint.config.js @@ -0,0 +1,86 @@ +import tseslintPlugin from '@typescript-eslint/eslint-plugin'; +import { defineConfig } from 'eslint/config'; +import globals from 'globals'; + +const backendLanguageOptions = { + globals: { + // Current, intentionally supported globals + extension: 'readonly', + config: 'readonly', + global_config: 'readonly', + + // Older not entirely ideal globals + use: 'readonly', // <-- older import mechanism + def: 'readonly', // <-- older import mechanism + kv: 'readonly', // <-- should be passed/imported + ll: 'readonly', // <-- questionable + + // Language/environment globals + ...globals.node, + }, +}; + +export default defineConfig([ + { + ignores: [ + 'src/backend/src/modules/apps/AppInformationService.js', // TEMPORARY - SHOULD BE FIXED! + 'src/backend/src/services/worker/WorkerService.js', // TEMPORARY - SHOULD BE FIXED! + 'src/backend/src/public/**/*', // We may be able to delete this! I don't think it's used + + // These files run in the worker environment, so these rules don't apply + 'src/backend/src/services/worker/dist/**/*.{js,cjs,mjs}', + 'src/backend/src/services/worker/src/**/*.{js,cjs,mjs}', + 'src/backend/src/services/worker/template/puter-portable.js', + ], + }, + { + plugins: { + '@typescript-eslint': tseslintPlugin, + }, + }, + { + files: [ + 'src/backend/**/*.{js,mjc,cjs}', + 'extensions/**/*.{js,mjc,cjs}', + 'src/backend-core-0/**/*.{js,mjc,cjs}', + ], + ignores: [ + 'src/backend/src/services/database/sqlite_setup/**/*.js', + ], + rules: { + 'no-undef': 'error', + }, + languageOptions: { + ...backendLanguageOptions, + }, + }, + { + files: [ + 'src/backend/src/services/database/sqlite_setup/**/*.js', + ], + rules: { + 'no-undef': 'error', + }, + languageOptions: { + globals: { + read: 'readonly', + write: 'readonly', + log: 'readonly', + ...globals.node, + }, + }, + }, + { + files: [ + 'src/backend/**/*.{ts}', + 'extensions/**/*.{ts}', + 'src/backend-core-0/**/*.{ts}', + ], + rules: { + 'no-undef': 'error', + }, + languageOptions: { + ...backendLanguageOptions, + }, + }, +]); diff --git a/package.json b/package.json index c80a3839..d559ca78 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "start": "node ./tools/run-selfhosted.js", "prestart": "npm run build:ts", "dev": "npm run build:ts && DEVCONSOLE=1 node ./tools/run-selfhosted.js", - "build": "npm run build:ts; cd src/gui; node ./build.js", + "build": "npx eslint --quiet -c eslint/mandatory.eslint.config.js src/backend/src extensions && npm run build:ts && cd src/gui && node ./build.js", "check-translations": "node tools/check-translations.js", "prepare": "husky", "build:ts": "tsc",