Skip to content

Instantly share code, notes, and snippets.

@cybersiddhu
Last active October 5, 2022 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybersiddhu/44268281bfb1c90581fad9a1a79906db to your computer and use it in GitHub Desktop.
Save cybersiddhu/44268281bfb1c90581fad9a1a79906db to your computer and use it in GitHub Desktop.

Packages

yarn add -D eslint eslint-config-airbnb eslint-config-prettier eslint-config-react-app \
        eslint-plugin-compat eslint-plugin-github eslint-plugin-import eslint-plugin-jest \
	eslint-plugin-jest-dom eslint-plugin-jsx-a11y eslint-plugin-prettier \
	eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-sonarjs \
	eslint-plugin-unicorn eslint-import-resolver-typescript @typescript-eslint/eslint-plugin

Configuration

{
  "extends": [
    "react-app",
    "plugin:jest/recommended",
    "plugin:jest-dom/recommended",
    "airbnb",
    "airbnb/hooks",
    "plugin:github/recommended",
    "plugin:sonarjs/recommended",
    "plugin:unicorn/recommended",
    "plugin:compat/recommended",
    "prettier",
  ],
  "env": {
    "browser": true
  },
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"]
    }
  ],
  "ignorePatterns": ["src/generated/**","public/mockServiceWorker.js"],
  "settings": {
      "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "typescript": {
        "alwaysTryTypes": true
      }
    }
  },
  "rules": {
    "import/no-unresolved": "error",
    "quotes": ["off", "single"],
    "semi": ["error", "never"],
    "react/jsx-filename-extension": [
      "warn",
      {
        "extensions": [".tsx", ".ts"]
      }
    ],
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ],
    "react/react-in-jsx-scope": "off",
    "react/function-component-definition": [
      "warn",
      {
        "namedComponents": "arrow-function"
      }
    ],
    "filenames/match-regex": "off",
    "unicorn/filename-case": [
      "error",
      {
        "cases": {
          "camelCase": true,
          "pascalCase": true,
          "snakeCase": true
        }
      }
    ],
    "eslint-comments/no-use": [
      "error",
      { "allow": ["eslint-disable", "eslint-disable-next-line"] }
    ],
    "no-unused-vars": "off"
  }
}

For vitejs

Install packages

yarn add -D vite-tsconfig-paths @tsconfig/recommended

tsconfig.json

{
  "extends": "@tsconfig/vite-react/tsconfig.json",
  "compilerOptions": {
        "baseUrl": "./src"
    },
  "include": ["src"]
}

vite.config.js

import react from "@vitejs/plugin-react"
import tsconfigPaths from "vite-tsconfig-paths"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [tsconfigPaths(), react()],
  server: {
    port: 3000,
  },
})
@cybersiddhu
Copy link
Author

cybersiddhu commented Sep 27, 2022

@benbradley747

eslint configuration is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment