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: Improve information available about installed standards #2600

Closed
jrfnl opened this issue Sep 4, 2019 · 8 comments
Closed

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Sep 4, 2019

(I seem to remember seeing a discussion about something like this before, but can't find it anymore, so hoping I'm not opening a duplicate issue)

At this moment, there is the --version option to show the version of PHPCS itself, the -i option to show which (external) standards are installed and the --config-show option which provides information on the configuration used.

# phpcs --version
PHP_CodeSniffer version 3.5.0 (stable) by Squiz (http://www.squiz.net)

# phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, PHPCompatibility, Debug, PHPCSDev, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra, WPThemeReview, Joomla and Symfony

# phpcs --config-show
Using config file: /path/to/PHP_CodeSniffer/CodeSniffer.conf                                                                                     
                                                                                                                                                            
installed_paths: /path/to/PHPCompatibility,/path/to/PHPCSDevTools,/path/to/WordPress,/path/to/WPThemeReview,/path/to/Joomla-coding-standards,/path/to/Symfony-coding-standard
report_width:    90                                                                                                                                         

I believe it would be helpful if there was a command-line option available which would combine some of this information.

For this to work as I envision, external standards would need to be allowed to pass their version number on to PHPCS through the XML ruleset.

Something along the lines of:

<ruleset
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="PHPCSDev"
    namespace="PHPCSStandards\PHPCSDev"
    version="1.0.0"
    xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
    ...
</ruleset>

This would require a change to the phpcs.xsd file along the lines of adding the below to the <xs:element name="ruleset"> block:

            <xs:attribute name="version" type="xs:string"></xs:attribute>

Secondly, either one of the above mentioned command-line options would need to be adjusted or a new one should be introduced, let's call it --list-standards for now.

I imagine the output could then look something like this:

# phpcs --list-standards
PHP_CodeSniffer version 3.5.0 (stable) by Squiz (http://www.squiz.net)

Standards        | Version   | Installed path
---------------------------------------------------------------
MySource         | 3.5.0     | N/A (build-in)
PEAR             | 3.5.0     | N/A (build-in)
PSR1             | 3.5.0     | N/A (build-in)
PSR2             | 3.5.0     | N/A (build-in)
PSR12            | 3.5.0     | N/A (build-in)
Squiz            | 3.5.0     | N/A (build-in)
Zend             | 3.5.0     | N/A (build-in)
Debug            | 1.0.0     | /path/to/PHPCSDevTools
Joomla           | 2.0.0-rc3 | /path/to/Joomla-coding-standards
PHPCompatibility | 9.3.0     | /path/to/PHPCompatibility
PHPCSDev         | 1.0.0     | /path/to/PHPCSDevTools
Symfony          | 3.9.0     | /path/to/Symfony-coding-standard
WordPress        | 2.1.1     | /path/to/WordPress
WordPress-Core   | 2.1.1     | /path/to/WordPress
WordPress-Docs   | 2.1.1     | /path/to/WordPress
WordPress-Extra  | 2.1.1     | /path/to/WordPress
WPThemeReview    | 0.2.0     | /path/to/WPThemeReview

For standards which do not (yet) supply the version number via the ruleset.xml file, it could be tried to retrieve the version number via a composer --show in case of a Composer based install.

For non-Composer based installs, the version could either be left empty of be listed as Unknown.

Also take note of the ordering of the list: build-in standards first and then external standards in alphabetic order using natsort.

Opinions ?

@glensc
Copy link
Contributor

glensc commented Sep 4, 2019

@jrfnl thanks for opening the RFE!

I think versioning is important for support cases like, what version of the standard X are you running?

@gsherwood
Copy link
Member

Sounds like a good change. I'd probably just change the -i option instead of introducing another one.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 4, 2019

I'd probably just change the -i option instead of introducing another one.

I'm not familiar enough with external tooling which integrates PHPCS, but I was a bit wary that could possibly break any of those integrations.

@gsherwood
Copy link
Member

I was a bit wary that could possibly break any of those integrations

I'd probably do this in a major release, but I wouldn't add a second command line argument to do that same thing.

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 12, 2019

Just thinking - it may be a nice idea to also display the <description> for each ruleset (if available) in a table like above.

@glensc
Copy link
Contributor

glensc commented May 8, 2020

I'm currently just extracting the version from composer lock of the package:

composer show --format=json phpcompatibility/php-compatibility > vendor/package.json
php -r 'echo json_decode(file_get_contents($argv[1]),1)["versions"][0];' vendor/package.json > vendor/VERSION

@jrfnl
Copy link
Contributor Author

jrfnl commented May 14, 2020

@gsherwood Could this feature request be earmarked for PHPCS 4.x ?

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#17

@jrfnl jrfnl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
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

3 participants