Skip to content

Commit 330241b

Browse files
Merge pull request #107 from tcet-opensource/40-create_a_eslint_hook_for_precommit
created a setup file to setup hook
2 parents a204ac9 + e231ace commit 330241b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

hooks/pre-commit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
4+
do
5+
git show ":$file" | npm run eslint --stdin --stdin-filename "$file"
6+
if [ $? -ne 0 ]; then
7+
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
8+
exit 1
9+
fi
10+
done

setup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
fs.copyFile(path.join("hooks", "pre-commit"), path.join(".git", "hooks", "pre-commit"), (err) => {
5+
if (err) throw err;
6+
console.log("Hook setup completed");
7+
});

0 commit comments

Comments
 (0)