node js pre-commit hook bypass
- Install the
husky
package as a development dependency:
bash
npm install husky --save-dev
- Open the
package.json
file and add the following configuration to enable pre-commit hooks:
json
"husky": {
"hooks": {
"pre-commit": "npm test"
}
}
- Install
lint-staged
as a development dependency:
bash
npm install lint-staged --save-dev
- Update the
package.json
file to configurelint-staged
:
json
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
]
}
Create an
.eslintrc.js
file for ESLint configuration.Update your existing ESLint rules or add new rules as needed.
Example .eslintrc.js
:
javascript
module.exports = {
"extends": "eslint:recommended",
"rules": {
// Your ESLint rules here
}
};
- Run the following command to add a pre-commit hook for linting:
bash
npx mrm lint-staged
- Add a test script to your
package.json
file if not already present:
json
"scripts": {
"test": "your-test-command"
}
- Commit your changes to the repository.
Now, the pre-commit hook is configured to run ESLint on staged files before each commit. If ESLint detects any issues, the commit will be prevented until the issues are resolved.