5

I am trying to add eslint to my typescript create-react-app application. I am using Visual Studio Code.

I did :

  1. Download Eslint package in visual code
  2. Download Eslint package
  3. I installed 3 eslint plugin
    "eslint:recommended", 
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended"
  1. Create an .eslintrc file that look like this in the app's root folder
{
  "plugins": [
    "react"
  ],
  "extends": [
    "eslint:recommended", 
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended"
  ],
  "parserOptions": {
    "ecmaVersion": 7,
    "sourceType": "module",
    "ecmaFeatures": {
        "jsx": true
    }
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "settings": {
    "import/resolver": {
      "node": {},
      "babel-module": {
        "root": ["./src"]
      }
    }
  }
}
  1. Started eslint and restart vs code

Now, I try to do some linting problem like trailing spaces or not pascalCase, but I never get warned by Eslint, I only see typescript errors, but never some linting issues like.

Is there some additional configuration to do to make it work on my workspace ?

3
  • Download the eslint vscode plugin from the vscode marketplace. The plugin integrates eslint into your gui and enables warnings and also auto fix. Without the eslint vscode plugin you will have to run the eslint command on the command line. Also, the plugin shows you any additional errors in the lower right corner of the editor in case there is something wrong with your eslintrc config.
    – Andre
    Commented Nov 12, 2019 at 2:02
  • @Andre sorry, that is what I ment in the 1), but i written only package.
    – Crocsx
    Commented Nov 12, 2019 at 2:11
  • What else is to mention that create-react-app already uses .eslintrc in the background. There is some more to it. See this guide for example: dev.to/benweiser/… (first on google search)
    – Andre
    Commented Nov 12, 2019 at 2:26

1 Answer 1

4

Had a similar issue. Turned out I didn't specify any rules, so technically Eslint was working, but no rules were set up. As a starter, try to extend Airbnb rules:

"extends": [
    "eslint:recommended", 
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended",
    "airbnb"
  ],

You should also specify a TypeScript parser for your files:

module.exports = {
  parser: '@typescript-eslint/parser',
  ...
}

Don't forget to install the above: npm i --save-dev @typescript-eslint/parser

And finally check if you have Eslint Extension set-up for your editor!

Not the answer you're looking for? Browse other questions tagged or ask your own question.