Lint only staged files in precommit hook
npm install git-precommitExecute commands on files that are part of the current commit. This project is an alternative
to the usual bash scripts, which obviously won't work on windows machines.
There is also a much shorter version for bash in
case your developers don't use windows.
``bash`run this in your pre-commit hook
./git-precommit path/to/my/config.js
For example: If you are using husky, you need to add this in your package.json:
`json`
{
"scripts": {
"precommit": "git-precommit precommit.config.js"
}
}
And don't forget the config file itself:
`js`
module.exports = {
tasks: [{
// files will be appended to this command
// e.g.: eslint [file1] [file2]...
command: "eslint",
extensions: ["js", "jsx"],
message: "Linting scripts"
}, {
command: "stylelint",
extensions: /\.s?css/g, // Regex works as well
message: "Linting stylesheets"
}],
};
MIT, see License.md`