skip to Main Content

I have added ESLint to my TypeScript project by installing:

npm install eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev

and adding this script:

"lint": "eslint src/**/*.ts"

and this config file .eslintrc.json:


{
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
      "project": "./tsconfig.json"
    },
    "plugins": ["@typescript-eslint"],
    "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
    "rules": {
      // Add your custom rules here
    }
  }

In VS Code, if I install the ESLint extension. Will it also use that same config file or do I have to redefine this config in VS Code?

2

Answers


  1. VS Code will use this file, if it can find it (best is to place it in the project root). You can then go to the OUTPUT tab for ESlint, to see that it started normally. Should be something like:

    [Info  - 10:02:54] ESLint server is starting.
    [Info  - 10:02:54] ESLint server running in node v18.18.2
    [Info  - 10:02:54] ESLint server is running.
    [Info  - 10:02:55] ESLint library loaded from: /*path*/node_modules/eslint/lib/api.js
    

    if the config file was found and is correct. To check that introduce a syntax error in the config file (e.g. remove a needed comma) which will then print an error in that OUTPUT channel like:

    Error - 11:58:17] Calculating config file for file:///*path*/src/myfile.ts) failed.
    SyntaxError: Cannot read config file: /*path*/.eslintrc.json
    Error: Expected ',' or '}' after property value in JSON at position 115 (line 8 column 5)
        at JSON.parse (<anonymous>)
        ...
    
    Login or Signup to reply.
  2. Yes it supports. Same file is used for the extension and project. If doesn’t try creating config file from a different format

    ESLint

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search