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

Feature suggestion: --validate to check ruleset against XSD #14

Open
jrfnl opened this issue Nov 8, 2023 · 0 comments
Open

Feature suggestion: --validate to check ruleset against XSD #14

jrfnl opened this issue Nov 8, 2023 · 0 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Nov 8, 2023

Repost from squizlabs/PHP_CodeSniffer#2188:

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.

  • When called like phpcs --validate=filename.xml it would validate that specific file.
  • When called like phpcs --validate=*/Standards/*/ruleset.xml it would validate all files which match the pattern.
  • When called without a value, like 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.
  • When called in combination with other command line options, like for a normal run, it would validate the ruleset(s) and then continue to the normal PHPCS run, providing the ruleset(s) are valid.

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:

Related to and could partially replace #2187.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant