Files
czchan/eslint.config.mts
sneedmaster bbe75c008c eslint
2026-04-20 13:33:22 +02:00

115 lines
2.7 KiB
TypeScript

import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import tseslint from "typescript-eslint";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const tsRules = {
// Shit nophono cares fan about
"no-empty": "off",
"@typescript-eslint/no-explicit-any": "off",
// No unused vars (except _*)
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
// Correctness
eqeqeq: "error",
"no-var": "error",
"prefer-const": "warn",
"no-constant-condition": "warn",
"no-unreachable": "error",
"no-implicit-coercion": ["error", { boolean: false }],
"no-duplicate-imports": "error",
"no-self-compare": "error",
"no-sparse-arrays": "error",
"no-unsafe-optional-chaining": "error",
"func-style": ["error", "expression", { allowArrowFunctions: true }],
// TypeScript safety
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/consistent-type-imports": "error",
// Style consistency
"dot-notation": "error",
"prefer-template": "warn",
"object-shorthand": "warn",
// async
"require-await": "off",
"@typescript-eslint/require-await": "warn",
"no-return-await": "off",
"@typescript-eslint/return-await": ["error", "in-try-catch"],
// Logging
"no-console": "off",
"no-debugger": "warn",
};
export default [
{
ignores: ["dist/**", "public/js/**"],
},
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["src/**/*.ts", "src/**/*.tsx", "scripts/**/*.ts"],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
},
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.node,
},
},
rules: tsRules,
},
{
files: ["web/ts/**/*.ts"],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: "./web/tsconfig.json",
tsconfigRootDir: __dirname,
},
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
},
},
rules: tsRules,
},
prettier,
// Re-enable rules that prettier disables but we actually want
{
rules: {
curly: ["error", "all"],
},
},
];