-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature suggestion: --validate
to check ruleset against XSD
#2188
Comments
I like everything about this. |
jrfnl
added a commit
to jrfnl/PHP_CodeSniffer
that referenced
this issue
Dec 23, 2018
While the `libxml` error messages are far from perfect, they at least give some clue as to where to look for the error in a ruleset file. This PR changes two things: 1. Previously, a PHP warning would also be thrown for a ruleset of a standard which is not used in the current run. This warning is now silenced. 2. However, for the standards and rulesets actually _used_ by the current run, any potential warnings are made more readable and will now also mention the file in which they were encountered. Previously the output would be along the lines of: ``` Warning: simplexml_load_string(): Entity: line 82: parser error : Opening and ending tag mismatch: rule line 80 and rue in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 Warning: simplexml_load_string(): </rue> in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 Warning: simplexml_load_string(): ^ in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 ``` Now, it will look like: ``` ERROR: Ruleset /path/to/ruleset.xml is not valid - On line 82, column 10: Opening and ending tag mismatch: rule line 80 and rue ``` Loosely related to squizlabs#2188
jrfnl
added a commit
to jrfnl/PHP_CodeSniffer
that referenced
this issue
Dec 23, 2018
While the `libxml` error messages are far from perfect, they at least give some clue as to where to look for the error in a ruleset file. This PR changes two things: 1. Previously, a PHP warning would also be thrown for a ruleset of a standard which is not used in the current run. This warning is now silenced. 2. However, for the standards and rulesets actually _used_ by the current run, any potential warnings are made more readable and will now also mention the file in which they were encountered. Previously the output would be along the lines of: ``` Warning: simplexml_load_string(): Entity: line 82: parser error : Opening and ending tag mismatch: rule line 80 and rue in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 Warning: simplexml_load_string(): </rue> in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 Warning: simplexml_load_string(): ^ in /path/to/PHP_CodeSniffer/src/Util/Standards.php on line 119 ``` Now, it will look like: ``` ERROR: Ruleset /path/to/ruleset.xml is not valid - On line 82, column 10: Opening and ending tag mismatch: rule line 80 and rue ``` Loosely related to squizlabs#2188
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PR #1433 added an XML schema file to the repo and while people can use it with external tools to validate their custom rulesets/external standards, I think it could be a nice feature to offer ruleset validation against the XSD file from within PHPCS itself.
I'm thinking a
--validate
command line option.phpcs --validate=filename.xml
it would validate that specific file.phpcs --validate=*/Standards/*/ruleset.xml
it would validate all files which match the pattern.phpcs --validate
, it would look for an[.]phpcs.xml[.dist]
file in the same way PHPCS does for a normal run and validate such a file if found.Validation could be done using the XMLReader PHP extension which is shipped with PHP by default and enabled by default since PHP 5.1.2.
There are caveats regarding whether
libxml
is compiled with PHP with schema support, but in case it's not, I suppose an error message could be thrown saying so.While the initial implementation I'm proposing would be a command-line option, I imagine that ruleset validation could possibly become a standard part of the ruleset processing as of PHPCS 4.0.
Opinions ?
Inspired by:
phpunit.xml
file before each run since PHPUnit 7.2 - see Implements #3048 - XML configuration is validated against the schema sebastianbergmann/phpunit#3066.Related to and could partially replace #2187.
The text was updated successfully, but these errors were encountered: