I've upgraded to the latest version of yarn and now I'm setting up Husky in my project.
Here is the content from .huskyrc.json
:
{
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run test:noWatch"
}
}
Now, let's take a look at lintstagedrc.json
{
"src/**/*.{js,ts,jsx,tsx}": ["yarn lint"],
"*.json": ["prettier --write"]
}
Lastly, we have the contents of package.json
{
...
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest --watchAll",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.json --max-warnings 0",
"lint:fix": "eslint . --ext .ts,.tsx,.js,.jsx,.json --fix",
"prettier-format": "prettier --config .prettierrc '**/*.{json,js,jsx,ts,tsx,css,scss,md}' --write"
},
...
{
An error occurred:
npm ERR! missing script: pre-commit
To address this, I added the following script to package.json
:
"pre-commit": "yarn prettier-format && yarn lint",
After implementing this change, the pre-commit script now executes these two commands. But what about the configurations in all the other files mentioned?
I came across an article on here, but it didn't mention anything about the pre-commit script.