Skip to content
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

Merged
merged 5 commits into from
Dec 15, 2021
Merged

linters #9

merged 5 commits into from
Dec 15, 2021

Conversation

alvinjohnsonso
Copy link
Owner

  • 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'
Copy link
Owner Author

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;"
Copy link
Owner Author

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.

@alvinjohnsonso alvinjohnsonso merged commit 4a76a07 into fix/coding-standards Dec 15, 2021
@alvinjohnsonso alvinjohnsonso deleted the linters branch January 7, 2022 05:58
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant