React.Js. Adding Eslint With Prettier + Husky (Git Hook)

React.Js. Adding Eslint With Prettier + Husky (Git Hook)

How to add Eslint with Prettier to the Typescript React.JS project and run lint on each git commit or git push? we used create-react-app script, we will get eslint libraries automatically, so we don’t need to add them to our package.json file explicitly.

How to add Eslint with Prettier to the Typescript React.JS project and run lint on each git commit or git push?

I will be using React.js project that was started from scratch, using create-react-app with typescript

npx create-react-app my-app --template typescript

## or
yarn create react-app my-app --template typescript

I have deleted CSS files, logo.svg, and cleaned up App.tsx file. I all other ways — I will be using a standard clean typescript React.js project.

Image for post

Projects comparison. To the left — old version, to the right — new version.

Adding Eslint and Prettier to our project

Because we used create-react-app script, we will get eslint libraries automatically, so we don’t need to add them to our package.json file explicitly.

/node-modules folder:

Image for post

node-modules library with eslint packages


Image for post

If you are using custom react build, here are **package.json** dependencies:

"devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.7.0",
    "@typescript-eslint/parser": "^3.7.0",
    "eslint": "^6.6.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-react": "^7.20.3",
    "eslint-plugin-react-hooks": "^4.0.8",
    "typescript": "^3.9.7"
},

hooks husky eslint prettier react

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

What are hooks in React JS? - INFO AT ONE

In this article, you will learn what are hooks in React JS? and when to use react hooks? Also, we will see the react hooks example.

Validating React Forms With React-Hook-Form

In this article we will learn how to Validating React Forms With React-Hook-Form . Validating inputs is very often required. For example, when you want to make sure two passwords inputs are the same, an email input should in fact be an email or that the input is not too long

Hooks, Hooks, Hooks!

Hooks are functions, provided by React (and completely opt-in, not required), that allows you to “hook into” React features from functional components. So you can continue to use functional components, which are inherently simpler and less bloated, and access state.

The Ugly Side of React Hooks

In this post, I will share my own point of view about React Hooks, and as the title of this post implies, I am not a big fan.