Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Husky for auto formatting on pre commit #856

Closed
wants to merge 3 commits into from

Conversation

MuntazirHaider
Copy link
Contributor

Description

I setup husky in following steps

  1. Install Husky and Lint-Staged by running this command --> npm install husky lint-staged --save-dev
  2. Create a lint-staged.config.js file inproject's root directory.
  3. Modify package.json file by adding script and add a husky configuration to define the pre-commit hook.

Related Issue

Fixes #854

Motivation and Context

There have been multiple issues while reviewing due to issues with conflicting formats.
Adding Husky to your project to enforce code formatting and linting before commits is a great way to maintain code quality.

How Has This Been Tested?

Before committing, Husky and Lint-Staged will automatically run the specified scripts on the staged files. If there are formatting or linting issues, the commit will be blocked until you fix them. It does not affect any other areas of the code.

Screenshots or GIF (In case of UI changes):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

```
npm install husky lint-staged --save-dev
```
2. create lint-staged.config.js file in root directory and add following code
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes here. Since you've pushed lint-staged.config.js file with your pr, it should be available in the root directory after merging your pr right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should write husky post installation setup. I will keep in mind thank you. 😊

@Sarfraz-droid
Copy link
Collaborator

@MuntazirHaider You can define a postinstall to setup husky.. Follow, https://typicode.github.io/husky/getting-started.html

@MuntazirHaider
Copy link
Contributor Author

this issue is assigned to @Sarfraz-droid so I should modify this or should I wait.

@Sarfraz-droid
Copy link
Collaborator

@MuntazirHaider you can work on it, since you have initialized the setup. We will merge the changes if the setup is successful

@MuntazirHaider
Copy link
Contributor Author

Can you please tell me how can I check my changes is working perfectly or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup Husky for auto formatting on pre commit
3 participants