-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
linters #9
linters #9
Conversation
alvinjohnsonso
commented
Dec 13, 2021
- Added linters
- CSS - stylelint
- JS - eslint
- PHP - phpcs
- Added pre-commit hook for linting
- Resolved issues reported by the linters
'*.css': 'stylelint --cache --fix', | ||
'*.php': [ | ||
'composer run lint:fix', | ||
'composer run lint' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case anyone asks, the commands that were use in these scripts came from only one package which is PHPCS
.
Basically, the command composer run lint
uses phpcs
which is the linter and composer run lint:fix
uses phpcbf
which is the fixer that was included in the PHPCS package.
"scripts": { | ||
"post-install-cmd": "phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs,vendor/phpcompatibility/php-compatibility", | ||
"lint": "phpcs -p -s -v --runtime-set ignore_warnings_on_exit true tawkto", | ||
"lint:fix": "phpcbf -p -s -v tawkto; err=$?; if [ $err -eq 1 ]; then exit 0; else exit $err; fi;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a custom handler for exit code for the command phpcbf
because, according to this comment in one of the issues reported to PHPCS, here are the current exit codes for phpcbf
:
- Exit code 0 is used to indicate that no errors were found
- Exit code 1 is used to indicate that errors were found but can be fixed
- Exit code 2 is used to indicate that errors were found and some can be fixed
So I made a handler for exit code 1 to have an exit code of 0 just so lint-staged
won't fail.