lint (1403B)
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 # Ensure Node.js v24 is available 5 script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 "$script_dir/node" --version >/dev/null 7 8 project_dir="$(pwd)" 9 config_file="$project_dir/eslint.config.temp.mjs" 10 11 # Ensure we have a package.json (it is already gitignored) 12 if [ ! -f package.json ]; then 13 npm init -y >/dev/null 2>&1 14 fi 15 16 # Lightweight local install of eslint + TypeScript support 17 # (node_modules and package.json are gitignored) 18 npm install --no-save --save-dev eslint @eslint/js typescript-eslint >/dev/null 2>&1 19 20 # Generate temporary config at the project root (gitignored) 21 cat > "$config_file" << 'CFG' 22 import js from "@eslint/js"; 23 import tseslint from "typescript-eslint"; 24 25 export default tseslint.config( 26 js.configs.recommended, 27 ...tseslint.configs.recommended, 28 { 29 files: ["**/*.ts", "**/*.tsx"], 30 rules: { 31 "@typescript-eslint/no-explicit-any": "warn", 32 "@typescript-eslint/no-unused-vars": [ 33 "warn", 34 { argsIgnorePattern: "^_", varsIgnorePattern: "^_" } 35 ], 36 "no-undef": "off", 37 }, 38 }, 39 { 40 ignores: ["node_modules/**", "dist/**", ".git/**"], 41 } 42 ); 43 CFG 44 45 # Run eslint using the generated config (capture exit code for cleanup) 46 set +e 47 npx eslint \ 48 --config "$config_file" \ 49 --fix \ 50 . 51 eslint_exit=$? 52 set -e 53 54 # Always remove the temporary config file 55 rm -f "$config_file" 56 57 exit $eslint_exit