Skip to content

Instantly share code, notes, and snippets.

@pedrouid
Last active August 11, 2022 14:31
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save pedrouid/71bb2d8b263731492dabfa302e7c6b67 to your computer and use it in GitHub Desktop.
Save pedrouid/71bb2d8b263731492dabfa302e7c6b67 to your computer and use it in GitHub Desktop.
Eslint + Prettier configuration for Typescript 3.7+ (2020)

Eslint + Prettier configuration for Typescript 3.7+ (2020)

  1. Install required dependencies
npm install --save-dev @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier

# OR

yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier
  1. Setup your .eslintrc config file
{
  "rules": {
    "@typescript-eslint/ban-ts-ignore": ["off"],
    "@typescript-eslint/camelcase": ["off"],
    "@typescript-eslint/explicit-function-return-type": ["off"],
    "@typescript-eslint/interface-name-prefix": ["off"],
    "@typescript-eslint/no-explicit-any": ["off"],
    "@typescript-eslint/no-unused-expressions": ["off"],
    "@typescript-eslint/no-var-requires": ["off"],
    "@typescript-eslint/no-use-before-define": ["off"],
    "comma-dangle": ["error", "always-multiline"],
    "no-async-promise-executor": ["off"],
    "no-empty-pattern": ["off"],
    "no-undef": ["error"],
    "no-var": ["error"],
    "object-curly-spacing": ["error", "always"],
    "quotes": ["error", "double", { "allowTemplateLiterals": true }],
    "semi": ["error", "always"],
    "spaced-comment": ["off"],
    "no-prototype-builtins": ["off"],
    "sort-keys": ["off"],
    "space-before-function-paren": ["off"],
    "indent": ["off"],
  },
  "env": {
    "browser": true,
    "es6": true
  },
  "extends": [
    "standard",
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": ["prettier", "@typescript-eslint"]
}
  1. Add the following lint script to package.json
{
"scripts": {
    "lint": "eslint -c './.eslintrc' --fix './src/**/*.ts'",
  },
}
  1. (optional) Setup .prettierc for prettier-vscode extension
{
  "tabWidth": 2,
  "useTabs": false,
  "trailingComma": "all",
  "printWidth": 100
}
@sostenesapollo
Copy link

sostenesapollo commented Nov 20, 2021

That worked, but it's not identing the code horizontally why ?

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