Configuring Visual Studio Code to lint TypeScript code

CRA has already installed ESLint and configured it for us. 

Note that ESLint doesn't appear in our package.json file. Instead, it is part of the CRA package. This can be confirmed by opening the package.json file in node_modules eact-scripts.

We need to tell Visual Studio Code to lint TypeScript code. Let's carry out the following steps to do this:

  1. First, let's reopen Visual Studio Code in the frontend folder. This is required for an extension that we are going to install in a later step.
  2. Create a new folder called .vscode.
  3. Create a new file in the .vscode folder called settings.jsonThis file is the Visual Studio Code settings file for this project.
  4. Let's add the following content into the settings.json file:
{
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
]
}

These settings tell Visual Studio Code to validate TypeScript code, as well as JavaScript code, with ESLint.

    1. Now, we can go to the Extensions area in Visual Studio Code (Ctrl + Shift + X) and type eslint into the search box in the top-left corner. The extension we are looking for is called ESLint and is published by Dirk Baeumer:

    1. Click on the Install button to install the extension.

    Now, Visual Studio Code will be using ESLint to validate our code.

    ..................Content has been hidden....................

    You can't read the all page of ebook, please click here login for view all page.
    Reset
    18.191.168.83