express icon indicating copy to clipboard operation
express copied to clipboard

add ESLint pre-commit hook to enforce code quality

Open kgarg1 opened this issue 8 months ago • 3 comments

Summary

This pull request introduces a pre-commit hook that uses Husky to automatically run ESLint on staged files before each commit. The goal is to enforce consistent code quality and catch potential issues early in the development process.

Changes

Added a pre-commit hook using Husky in the .husky/ directory. Updated package.json to include the necessary scripts for running ESLint. Fixed existing ESLint issues to ensure compliance with the project’s style guide.

Motivation

By integrating this pre-commit hook, we aim to: Enforce consistent code quality by automatically linting code before every commit. Reduce the risk of committing code that doesn't adhere to the coding standards. Ensure uniform code formatting across the team by catching issues before they are committed.

How to Test

Make a code change in any JavaScript file. Stage the changes using git add . Commit the changes using git commit. The pre-commit hook will automatically run ESLint on the staged files. If any linting issues are found, the commit will fail, and you’ll need to fix the issues before proceeding.

Additional Information

The pre-commit hook only checks the staged files and runs ESLint on them. If no issues are found, the commit will proceed normally.

kgarg1 avatar Apr 23 '25 06:04 kgarg1

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedhusky@​9.1.71001005982100

View full report

socket-security[bot] avatar Apr 23 '25 06:04 socket-security[bot]

Unfortunately we need to migrate a lot of code before we can do this. Also there is an o going conversation on how we want to fix the linking going forward. I won't close this, but also it might sit for a while.

wesleytodd avatar Apr 23 '25 14:04 wesleytodd

@wesleytodd I implement a fix https://github.com/expressjs/express/pull/6644 which also solve the same problem using single script npm run lint:fix

shivarm avatar Aug 13 '25 13:08 shivarm