nix/eslint.config.mjs
2024-10-25 16:57:29 +02:00

153 lines
4.3 KiB
JavaScript

import jseslint from "@eslint/js";
import eslintPluginImportX from "eslint-plugin-import-x";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import eslintPluginReact from "eslint-plugin-react";
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
import eslintPluginReactRefresh from "eslint-plugin-react-refresh";
import eslintPluginFormatjs from "eslint-plugin-formatjs";
import tseslint from "typescript-eslint";
// This config is provided through nix environment.
// Config is meant to be injected through devshell env variable and "cp" command in .envrc to copy it in the proper path
// Install dependencies: npm i -D @eslint/js@9 eslint-plugin-import-x@4 eslint-plugin-prettier@5 eslint-plugin-react@7 eslint-plugin-react-hooks@5 eslint-plugin-react-refresh@0.4 eslint-plugin-formatjs@5 typescript-eslint@8
export default tseslint.config(
{
ignores: [
"build/",
"dist/",
"tsconfig.json",
"tsconfig.*.json",
"eslint.config.mjs",
],
},
jseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginImportX.flatConfigs.recommended,
eslintPluginImportX.flatConfigs.typescript,
eslintPluginReact.configs.flat.recommended,
eslintPluginPrettierRecommended,
{
languageOptions: {
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: "./tsconfig.json",
},
},
settings: {
react: {
version: "detect",
},
"import-x/resolver": {
typescript: true,
node: true,
},
},
plugins: {
"react-hooks": eslintPluginReactHooks,
"react-refresh": eslintPluginReactRefresh,
formatjs: eslintPluginFormatjs,
},
rules: {
curly: ["error"],
"no-console": ["warn"],
"no-constant-condition": [
"error",
{
checkLoops: "allExceptWhileTrue",
},
],
// Typescript
// Some non typescript rules must be disabled as they can report incorrect errors
"default-param-last": "off",
"@typescript-eslint/default-param-last": "error",
"dot-notation": "off",
"@typescript-eslint/dot-notation": [
"error",
{
allowKeywords: true,
},
],
"@typescript-eslint/naming-convention": [
"error",
{
selector: ["function", "import"],
format: ["camelCase", "PascalCase"],
},
{
selector: ["variable"],
format: ["camelCase", "PascalCase", "UPPER_CASE"],
},
{
selector: ["enum", "typeLike"],
format: ["PascalCase"],
},
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
args: "after-used",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_$",
},
],
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
},
},
],
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"no-loop-func": "off",
"@typescript-eslint/no-loop-func": "error",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"no-return-await": "off",
"@typescript-eslint/return-await": "error",
"@typescript-eslint/prefer-promise-reject-errors": ["off"],
// Import
"import-x/no-extraneous-dependencies": [
"error",
{
devDependencies: true,
},
],
// Some issues with react import, no time to debug
"import-x/default": ["off"],
"prettier/prettier": "warn",
// React
"react-hooks/exhaustive-deps": "error",
"react-refresh/only-export-components": "warn",
"react/jsx-no-duplicate-props": [
"error",
{
ignoreCase: false,
},
],
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
// FormaJS/INTL
"formatjs/enforce-default-message": "error",
"formatjs/enforce-id": [
"error",
{
idInterpolationPattern: "[sha1:contenthash:base64:6]",
},
],
"formatjs/no-id": "off",
},
}
);