Skip to content

Instantly share code, notes, and snippets.

@freddie-freeloader
Created July 1, 2024 10:43
Show Gist options
  • Save freddie-freeloader/58edf68f250dde54c968da4aad5e4046 to your computer and use it in GitHub Desktop.
Save freddie-freeloader/58edf68f250dde54c968da4aad5e4046 to your computer and use it in GitHub Desktop.
/**
* This is a ESLint config for a Remix project.
*/
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
env: {
browser: true,
commonjs: true,
es6: true,
},
ignorePatterns: ["!**/.server", "!**/.client"],
// Base config
extends: ["eslint:recommended"],
overrides: [
// React
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: ["react", "jsx-a11y"],
extends: [
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
],
settings: {
react: {
version: "detect",
},
formComponents: ["Form"],
linkComponents: [
{ name: "Link", linkAttribute: "to" },
{ name: "NavLink", linkAttribute: "to" },
],
"import/resolver": {
typescript: {
"project": "./tsconfig.json",
},
},
},
},
// Typescript
{
files: ["**/*.{ts,tsx}"],
plugins: ["@typescript-eslint", "import"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
// FIXME: __dirname not defined
tsconfigRootDir: __dirname,
},
settings: {
"import/internal-regex": "^~/",
"import/resolver": {
node: {
extensions: [".ts", ".tsx"],
},
typescript: {
alwaysTryTypes: true,
},
},
},
extends: [
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/recommended",
"plugin:import/typescript",
],
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-inferrable-types": "off",
"prefer-const": "warn",
"prefer-promise-reject-errors": "off",
"@typescript-eslint/prefer-promise-reject-errors": "warn",
"@typescript-eslint/no-redundant-type-constituents": "warn",
"no-throw-literal": "off",
// We have to wait for https://github.com/typescript-eslint/typescript-eslint/issues/6226
// Then we could specify to only allow Error (this works already) & Response on server (this does not work yet, but recommended by Remix)
"@typescript-eslint/only-throw-error": [
"off",
{ allowThrowingAny: false, allowThrowingUnknown: false },
],
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-base-to-string": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
],
"@typescript-eslint/restrict-template-expressions": "warn",
"dot-notation": "off",
"@typescript-eslint/dot-notation": "warn",
"@typescript-eslint/no-confusing-void-expression": "warn",
}
},
// Node
{
files: [".eslintrc.js"],
env: {
node: true,
},
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment