{
  "env": {
    "browser": true,
    "es2021": true,
    "node": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "rules": {
    // ===================================
    // inst_026: Client-Side Code Quality
    // ===================================

    // No console.log in production code (console.error allowed)
    "no-console": ["error", {
      "allow": ["error", "warn"]
    }],

    // Consistent code style
    "quotes": ["error", "single", {
      "avoidEscape": true,
      "allowTemplateLiterals": true
    }],
    "semi": ["error", "always"],
    "indent": ["error", 2, {
      "SwitchCase": 1
    }],
    "comma-dangle": ["error", "never"],

    // No unused variables (prevents dead code)
    "no-unused-vars": ["error", {
      "argsIgnorePattern": "^_",
      "varsIgnorePattern": "^_"
    }],

    // Require let/const instead of var
    "no-var": "error",
    "prefer-const": "error",

    // Arrow functions consistency
    "arrow-spacing": ["error", {
      "before": true,
      "after": true
    }],
    "arrow-parens": ["error", "as-needed"],

    // Best practices
    "eqeqeq": ["error", "always"],
    "no-eval": "error",
    "no-implied-eval": "error",
    "no-with": "error",
    "no-new-func": "error",

    // Security (XSS prevention)
    "no-script-url": "error",
    "no-alert": "warn",

    // Code quality
    "no-debugger": "error",
    "no-empty": "error",
    "no-extra-semi": "error",
    "no-unreachable": "error",
    "no-dupe-keys": "error",

    // Spacing and formatting
    "space-before-function-paren": ["error", {
      "anonymous": "never",
      "named": "never",
      "asyncArrow": "always"
    }],
    "keyword-spacing": ["error", {
      "before": true,
      "after": true
    }],
    "space-infix-ops": "error",
    "comma-spacing": ["error", {
      "before": false,
      "after": true
    }],
    "brace-style": ["error", "1tbs", {
      "allowSingleLine": true
    }],

    // Modern JavaScript
    "prefer-arrow-callback": "warn",
    "prefer-template": "warn",
    "object-shorthand": ["warn", "always"],

    // Disable rules that conflict with Prettier (if used later)
    "max-len": ["warn", {
      "code": 120,
      "ignoreUrls": true,
      "ignoreStrings": true,
      "ignoreTemplateLiterals": true
    }]
  },

  "overrides": [
    {
      // Frontend JavaScript (public/js/**)
      "files": ["public/js/**/*.js"],
      "env": {
        "browser": true,
        "node": false
      },
      "globals": {
        "fetch": "readonly",
        "Headers": "readonly",
        "Request": "readonly",
        "Response": "readonly",
        "URL": "readonly",
        "URLSearchParams": "readonly"
      },
      "rules": {
        // Stricter rules for client-side code
        "no-console": ["error", {
          "allow": ["error"]
        }]
      }
    },
    {
      // Backend JavaScript (src/**)
      "files": ["src/**/*.js"],
      "env": {
        "browser": false,
        "node": true
      },
      "rules": {
        // Allow console in backend code
        "no-console": "off"
      }
    },
    {
      // Test files
      "files": ["tests/**/*.js", "**/*.test.js", "**/*.spec.js"],
      "env": {
        "jest": true,
        "node": true
      },
      "rules": {
        // Relax rules for tests
        "no-console": "off",
        "no-unused-expressions": "off"
      }
    }
  ],

  "ignorePatterns": [
    "node_modules/",
    "dist/",
    "build/",
    "coverage/",
    ".claude/",
    "*.min.js"
  ]
}
