← back to Dw Photo Capture
eslint.config.mjs
64 lines
// Flat ESLint config — DEV-ONLY static analysis for the photo-capture tool.
// Goal: catch correctness bugs (undefined vars like the getLS crash, typos,
// unreachable code) as ERRORS, while keeping pure-style nits as warnings so
// the signal isn't drowned in noise. Nothing here ships or is required at runtime.
import js from "@eslint/js";
import globals from "globals";
import html from "eslint-plugin-html";
// Rules we hold as hard errors — the bug classes that actually break the app.
const correctness = {
"no-undef": "error", // <- this is the rule that catches `getLS`
"no-unreachable": "error",
"no-dupe-keys": "error",
"no-dupe-args": "error",
"no-func-assign": "error",
"no-cond-assign": ["error", "always"],
"no-constant-condition": ["error", { checkLoops: false }],
"use-isnan": "error",
"valid-typeof": "error",
};
// Style / hygiene — surfaced but non-blocking.
// caughtErrors:"none" silences idiomatic throwaway `catch (e) {}` bindings so the
// only no-unused-vars hits left are GENUINE dead variables (real refactor targets).
const hygiene = {
"no-unused-vars": ["warn", { args: "none", caughtErrors: "none", varsIgnorePattern: "^_" }],
"no-empty": ["warn", { allowEmptyCatch: true }],
};
export default [
js.configs.recommended,
// Server-side: Node CommonJS.
{
files: ["server.js", "**/*.cjs", "test-*.js"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "commonjs",
globals: { ...globals.node },
},
rules: { ...correctness, ...hygiene },
},
// selfcheck-ui.cjs is a Node script, but the strings it passes to Playwright's
// page.$eval() execute in the BROWSER — so it legitimately references browser
// globals (getComputedStyle, document, …). Give it both worlds.
{
files: ["selfcheck-ui.cjs"],
languageOptions: { globals: { ...globals.node, ...globals.browser } },
},
// Front-end: the <script> block extracted from index.html, browser globals.
{
files: ["public/**/*.html"],
plugins: { html },
languageOptions: {
ecmaVersion: 2022,
sourceType: "script",
globals: { ...globals.browser },
},
rules: { ...correctness, ...hygiene },
},
];