-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Config: display user-friendly message when invalid generator is passed #771
Config: display user-friendly message when invalid generator is passed #771
Conversation
@jrfnl, while working on this PR, I noticed that, besides what I reported in #709, it is possible to trigger a different PHP fatal error if $ phpcs test.php --generator=Generator --standard=Generic
PHP Fatal error: Uncaught Error: Cannot instantiate abstract class PHP_CodeSniffer\Generators\Generator in src/Runner.php:98
Stack trace:
#0 bin/phpcs(14): PHP_CodeSniffer\Runner->runPHPCS()
#1 {main}
thrown in src/Runner.php on line 98 This happens because PHPCS tries to instantiate anything that it finds in the PHP_CodeSniffer/src/Runner.php Lines 97 to 98 in 3d14d00
The change suggested in this PR prevents this fatal error from happening, at least when using PHPCS in the command line. But I'm mentioning it anyway in case we want to do something else about it. |
Looking into the unrelated test that failed in the CI build. |
Eh.. the test failure is not unrelated... |
7141e6d
to
6bb661d
Compare
@jrfnl, I dropped the commit that changed |
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.
@rodrigoprimo Thanks for updating this. I have left some comments inline, mostly nitpicks/dotting of the i's and crossing the t's.
Other than that, this is looking good to go into the 3.12.0 release.
a6ddc1e
to
541e2ef
Compare
Thanks for your additional comments, @jrfnl. I pushed a new commit addressing all of them. Please take another look when you get a chance. |
This commit improves how `Config::processLongArgument()` handles the `--generator` parameter. Now it will show a user-friendly message if an invalid generator name is passed. Before, an invalid generator name caused a fatal error.
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
to a class constant in the future
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.
@rodrigoprimo Thank you for making those updates and for working on this. All looks good to me!
I'm going to rebase the PR before merging it as the last push feel in the time slot when Coveralls were having problems, so code coverage is not recorded (and I'd like to double-check it's okay).
I'll merge once the build has passed again.
502270e
to
b958235
Compare
#771) This commit improves how `Config::processLongArgument()` handles the `--generator` parameter. Now it will show a user-friendly message if an invalid generator name is passed. Before, an invalid generator name caused a fatal error. The commit also ensures that the value for the `generator` CLI parameter is handled case-insensitively.
Description
This PR improves how
Config::processLongArgument()
handles the--generator
parameter to display a user-friendly message if an invalid generator name is passed. Before, an invalid generator name caused a fatal error.I have checked, and it is not possible to add custom generators using third-party code (at least not without adding files to the PHPCS directory). This is because the
Runner
class only loads generators found in thesrc/Generator/
directory:PHP_CodeSniffer/src/Runner.php
Lines 97 to 98 in 3d14d00
So, it should be fine to limit the list of valid generators added in this PR to only the three generators provided by PHPCS.
Suggested changelog entry
Config: display a user-friendly message if an invalid generator name is passed in the command line
Related issues/external references
Fixes #709
Types of changes
PR checklist