Adding code linting and autoformatting

We will continue to create our React and TypeScript project in this lesson by adding linting and autoformatting.

Adding linting #

We touched on linting with ESLint when we created a project using Create React App. We are going to use ESLint in this project as well. So, let’s install ESLint along with the plugins we are going to need as development dependencies:

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

Below is an explanation of the packages that we just installed:

  • eslint: This is the core ESLint library.
  • eslint-plugin-react: This contains some standard linting rules for React code.
  • eslint-plugin-react-hooks: This contains some linting rules for React hooks code.
  • @typescript-eslint/parser: This allows TypeScript code to be linted.
  • @typescript-eslint/eslint-plugin: This contains some standard linting rules for TypeScript code.

Can you remember what file we use to configure the linting rules?

Get hands-on with 1400+ tech skills courses.