Skip to content

Add a pre-commit ESLint hook #9052

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

Closed
wants to merge 2 commits into from

Conversation

Neon-White
Copy link
Contributor

Describe the Problem

Currently, there's no automated way to ensure code quality through ESLint checks before commits. This can lead to inconsistent code style and potential issues being committed to the repository.

Explain the Changes

  1. Added a pre-commit hook in .githooks/pre-commit that runs ESLint on staged JavaScript/TypeScript files
  2. Added a preinstall script in package.json that automatically configures git to use the hooks from .githooks directory
  3. The hook will:
    • Check only staged JavaScript/TypeScript files (.js, .jsx, .ts, .tsx)
    • Run ESLint on these files
    • Block the commit if any ESLint errors are found
    • Show the specific ESLint errors that need to be fixed

Testing Instructions:

Fresh repo clone:

  1. Clone the repository
  2. Run npm install - this will automatically set up the git hooks.
  3. Make a change to any JavaScript/TypeScript file that violates ESLint rules (e.g., add an unused variable)
  4. Try to commit the change - the commit should be blocked with ESLint error messages
  5. Fix the ESLint errors and try to commit again - the commit should succeed

Existing repo clone:

  1. cd into the repo directory
  2. Run git config core.hooksPath .githooks
  3. Follow step 4 onwards above

@Neon-White Neon-White requested a review from romayalon June 4, 2025 07:54
@nimrod-becker
Copy link
Contributor

LGTM
Might be a good idea to also add something similar in the operator?

@Neon-White Neon-White closed this by deleting the head repository Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants