drupal-project
drupal-project copied to clipboard
Add Husky pre-commit configuration, #318.
How to test:
- Get this branch
git clone [email protected]:wunderio/drupal-project.gitcd drupal-projectgit checkout feature/husky - Start Lando
lando start(orlando rebuildif you've working on existing Lando project) - Create example js file
echo 'var foo="bar"' > web/modules/custom/phpunit_example/example.js - Add the file to GIT
git add web/modules/custom/phpunit_example/example.js - Try to commit
git commit
It seems this overwrites Code Quality hooks so rest of the scanners don't execute anymore (phpcs, psalm etc).
Also this scans all the files, Code Quality scans only the committed files.
Also this scans all the files, Code Quality scans only the committed files.
Added lint-staged setup to overcome this. However, since we're using lando npm run pre-commit within Husky, it also requires git config --global user.email "[email protected]" & git config --global user.name "Your Name" inside the node container ;)
➜ dp git:(feature/husky) ✗ git commit
> [email protected] pre-commit
> lint-staged
[STARTED] Preparing lint-staged...
[FAILED]
[FAILED] *** Please tell me who you are.
[FAILED]
[FAILED] Run
[FAILED]
[FAILED] git config --global user.email "[email protected]"
[FAILED] git config --global user.name "Your Name"
[FAILED]
[FAILED] to set your account's default identity.
[FAILED] Omit --global to set the identity only in this repository.
[FAILED]
[FAILED] fatal: unable to auto-detect email address (got 'node@588bb4551201.(none)')
[FAILED] Cannot save the current index state
[STARTED] Running tasks for staged files...
[SKIPPED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[SKIPPED]
[SKIPPED] ✖ lint-staged failed due to a git error.
[STARTED] Cleaning up temporary files...
[SKIPPED]
[SKIPPED] ✖ lint-staged failed due to a git error.
✖ lint-staged failed due to a git error.
Any lost modifications can be restored from a git stash:
> git stash list
stash@{0}: automatic lint-staged backup
> git stash apply --index stash@{0}
husky - pre-commit hook exited with code 1 (error)
Test was running successfully only on staged file after I've defined git config flags noted above:
➜ dp git:(feature/husky) ✗ git commit
> [email protected] pre-commit
> lint-staged
[STARTED] Preparing lint-staged...
[SUCCESS] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 1 file
[STARTED] web/**/*.{js,jsx,ts,tsx,json,css,scss,md} — 1 file
[STARTED] npx eslint --config=web/core/.eslintrc.passing.json
[FAILED] npx eslint --config=web/core/.eslintrc.passing.json [FAILED]
[FAILED] npx eslint --config=web/core/.eslintrc.passing.json [FAILED]
[FAILED] npx eslint --config=web/core/.eslintrc.passing.json [FAILED]
[STARTED] Applying modifications from tasks...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up temporary files...
[SUCCESS] Cleaning up temporary files...
✖ npx eslint --config=web/core/.eslintrc.passing.json:
/app/web/modules/custom/phpunit_example/example.js
1:1 error Unexpected var, use let or const instead no-var
1:5 warning 'foo' is assigned a value but never used no-unused-vars
1:8 error Replace `="bar"` with `·=·'bar';` prettier/prettier
✖ 3 problems (2 errors, 1 warning)
2 errors and 0 warnings potentially fixable with the `--fix` option.
husky - pre-commit hook exited with code 1 (error)