'Is it possible to add ESLint directly to Git?

I want ESLint to check my files before committing them to git. I found husky and lint-staged to do this but in this way every programmer has to have husky and lint-staged in their machine.

What if ESLint is directly injected into git so that all the commits are checked with ESLint, without every programmer having to install husky and lint-staged?



Solution 1:[1]

You cannot force people to run those programs on their machine or integrate them directly into Git. People use all sorts of tools to interact with Git, some of which don't run hooks or external program at all (e.g., those using libgit2). Anyone using regular Git can simply add --no-verify to git commit to bypass the hooks, as outlined in the Git FAQ.

If you need to implement an effective control that makes sure that people's code meets some standard, you should use a CI system (e.g., GitHub Actions) and check that the code passes before merging it into the desired branch.

In addition, it's not even useful to install pre-commit hooks by default, as the FAQ mentions, because this means that advanced users who use lots of squash or fixup commits can end up frustrated by the fact that those commits are incorrectly flagged by the linter.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bk2204