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

Have a way to output deprecations warnings when running PHPCS #2061

Open
wata727 opened this issue Jun 14, 2018 · 7 comments
Open

Have a way to output deprecations warnings when running PHPCS #2061

wata727 opened this issue Jun 14, 2018 · 7 comments

Comments

@wata727
Copy link

wata727 commented Jun 14, 2018

Hi team,

I'm trying Squiz.WhiteSpace.LanguageConstructSpacing Sniff with phpcs v3.3.0. This Sniff is deprecated according to CHANGELOG.
However, I cannot get deprecation warnings even if use this deprecated Sniff. I'd like to know in advance whether the current configuration will be impacted.

The following is the example:

<?php

print"Hello";
<?xml version="1.0"?>
<ruleset name="Custom Standard" namespace="MyProject\CS\Standard">
  <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing">
  </rule>
</ruleset>
$ phpcs --standard=ruleset.xml test.php 

FILE: /tmp/test.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------
 3 | ERROR | [x] Language constructs must be followed by a single space; expected "print "Hello"" but found "print"Hello""
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------

Time: 16ms; Memory: 4Mb

Are there any good ideas?
Thanks for this great project.

@gsherwood
Copy link
Member

PHPCS doesn't inject deprecation warnings into the error reports as that would cause build failures.

The changelog tells you what to do with this sniff, which is to change the code you are using in your ruleset.xml file. The sniff will continue to work correctly until version 4, so you've got plenty of time.

Once you change the code, your ruleset will only work with PHPCS 3.3.0+, so it's up to you to decide when you want to change it based on who is using your ruleset and what PHPCS version they are running.

@wata727
Copy link
Author

wata727 commented Jun 14, 2018

Thanks for your quick response!

I would like to update the version of PHPCS naturally without confirming the changelog. For example, deprecation warnings are very useful when using PHPCS that updated automatically.

Is it possible to display warning messages without failing the build?

$ phpcs --standard=ruleset.xml test.php 
WARNING: Squiz.WhiteSpace.LanguageConstructSpacing Sniff is deprecated and will be removed in 4.0. Please use `Generic.WhiteSpace.LanguageConstructSpacing` instead.

FILE: /tmp/test.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------
 3 | ERROR | [x] Language constructs must be followed by a single space; expected "print "Hello"" but found "print"Hello""
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------

Time: 16ms; Memory: 4Mb

@gsherwood
Copy link
Member

Is it possible to display warning messages without failing the build?

I could certainly do that, but I couldn't guarantee that it wouldn't fail builds or generate loads of emails to admins via cron. It's basically a BC break and would need to wait for version 4 anyway.

I'll turn this into a feature request for that and put it in the 4.0 backlog. I'm not sure I'll build it, but someone else might pick it up if not.

@gsherwood gsherwood changed the title [Question] How do I catch deprecation warnings? Have a way to output deprecations warnings when running PHPCS Jun 14, 2018
@wata727
Copy link
Author

wata727 commented Jun 30, 2018

Hi @gsherwood,

I'm working on this like the following:
wata727@9b2aac5

After implementation is complete, can I open a pull request?

@gsherwood
Copy link
Member

I'm working on this like the following:

I'm not sure if that's the best way of achieving deprecation warnings. I think different types of warnings would need to be considered, and possibly processed in different ways.

Maybe sniffs should be able to add a deprecation warning if they detect a run is using them, or is using a specific setting. Or maybe a report class wants to add a deprecation warning for a setting it is using (or for using it at all). Or maybe the ruleset should actually hard-code all the checks for everything. I'm not really sure - I haven't had any time to think deeply about it.

@gsherwood
Copy link
Member

Actually, the ruleset can't have the job of checking deprecations now that I think about it some more. If it did, sniff developers would never be able to deprecate their sniffs or custom reports.

@wata727
Copy link
Author

wata727 commented Jul 5, 2018

Thanks for your advice. I will consider another way.

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