Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for an invalid sniff code #344

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fredden
Copy link
Member

@fredden fredden commented Feb 16, 2024

Description

This is an implementation of the suggestions made by @gsherwood in squizlabs/PHP_CodeSniffer#2646 (comment)
I have intentionally not looked at the code changes initially suggested in squizlabs/PHP_CodeSniffer#2646 (to avoid any copyright woes).

Suggested changelog entry

Improved error message when invalid sniff codes are supplied to --sniffs or --exclude command line arguments.

Related issues/external references

Replaces / closes squizlabs/PHP_CodeSniffer#2646
Related to #319

Types of changes

  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @fredden.

Unfortunately, there are no pre-existing tests covering the changes, so new tests will need to be written to cover this change - as the line you removed from the "PR checklist" pointed out... (that checklist item is there for a reason... I've added it back now)

Some observations when I look at the behaviour around this error message:

  • If multiple erroneous names are passed via the --sniffs option, only the first error is displayed, so the user fixes that one, runs PHPCS again and will then be confronted with the next error.
    I believe this should be made more user friendly.
  • If the list of sniffs contains a stray comma, like --sniffs=A.B.C,,D.E.F, this will be reported as "The specified sniff code "" is invalid".
    I believe we can filter out/ignore empty sniff codes altogether without bothering the end-user with this.

As this PR introduces a dedicated method to validate the sniff codes (👍🏻), I think we should take this opportunity to make the fix comprehensive.

Other than that, I find the messaging a bit "wordy", so I wonder whether it can be made more succinct.

@fredden
Copy link
Member Author

fredden commented Mar 4, 2024

I have discussed this with @jrfnl. I intend to add tests to cover the existing behaviour in a separate pull request. I'll mark this as a draft until that change is complete. I'll come back to this when that change is done and make any necessary changes here at that time.

@fredden fredden force-pushed the feature/improve-sniff-code-error-message branch from 5fa0d0e to 1665e40 Compare May 14, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants