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

Ruleset/basic validation: improve error messages #2327

Merged
merged 1 commit into from
Jan 14, 2019

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented 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/installed 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 #2188

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
@gsherwood gsherwood merged commit 4b3611d into squizlabs:master Jan 14, 2019
@gsherwood
Copy link
Member

I never got any of those XML errors - only the PHPCS exception. I must have a different config.

But these changes are really good because now I get errors, and they are nicely formatted. Thanks.

@gsherwood gsherwood added this to the 3.4.1 milestone Jan 14, 2019
@gsherwood gsherwood added this to Backlog in PHPCS v3 Development via automation Jan 14, 2019
gsherwood added a commit that referenced this pull request Jan 14, 2019
@gsherwood gsherwood moved this from Backlog to Ready for Release in PHPCS v3 Development Jan 14, 2019
@jrfnl jrfnl deleted the feature/human-readable-xml-errors branch January 14, 2019 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants