Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Created June 23, 2020 04:46
Show Gist options
  • Save rajatk16/9ba201f6b7de46487f0dd72cc929fb0d to your computer and use it in GitHub Desktop.
Save rajatk16/9ba201f6b7de46487f0dd72cc929fb0d to your computer and use it in GitHub Desktop.
Setup a TypeScript project with ESLint and Prettier

Project Setup

Setup ESLint to work with TypeScript

  1. Install the Dev Dependencies
yarn add eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin -D
  1. Create .eslintrc file and write the following in it:
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "extends": [
    "plugin:@typescript-eslint/recommended"
  ],
  "rules": {
    
  }
}

Adding Prettier

  1. Install Dev Dependencies
yarn add prettier eslint-config-prettier eslint-config-prettier -D
  1. Create .prettierrc fule and right a few rules like this:
{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 100,
  "tabWidth": 2,
  "bracketSpacing": true
}
  1. Update .eslintrc file
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "extends": [
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment