-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Rewrite PSR12.Files.DeclareStatement
sniff
#578
base: master
Are you sure you want to change the base?
Rewrite PSR12.Files.DeclareStatement
sniff
#578
Conversation
@fredden I thought we'd discussed before that I was already working on a rewrite of this one ? [Edit: we did, also see #335, which you referenced yourself above] As things are, I don't know where to even start reviewing this PR as other than "there are fixer conflicts", it is completely unclear what you are trying fix.... |
13 => 2, | ||
14 => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same things are being detected here. The difference is that we are highlighting the problem token, not the correct token. This is a consistency benefit from using the new private method on the sniff.
22 => 1, | ||
13 => 2, | ||
14 => 1, | ||
16 => 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we are now reporting fewer problems. We used to report that the opening bracket should be the last thing on the line, and that the closing bracket needs to be on a line by itself. Now we're only reporting about the closing bracket. This is an implementation detail. If there were some PHP statements (or a comment) between the {
and }
, then both would be reported again.
18 => 1, | ||
19 => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two changes here: one is the same as lines 13 & 14, and the other is the same as line 16 above.
16 => 2, | ||
18 => 1, | ||
19 => 1, | ||
21 => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as lines 13 & 14 above.
24 => 1, | ||
26 => 3, | ||
26 => 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as line 16 above.
28 => 3, | ||
34 => 2, | ||
38 => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an error that the previous version of this sniff didn't detect.
@@ -0,0 +1,6 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of src/Standards/Generic/Tests/PHP/RequireStrictTypesUnitTest.5.inc
to ensure that the sniff does not act on line 6.
@fredden I appreciate the comments, they help a little, but they still do not explain enough as they are vague and non-specific. I know exactly what the problems are with this sniff (and there are plenty) and I have no clue which of those problems this PR is supposed to address. To give an example of the "non-specific":
Which error codes have changed ? This needs to be detailed in the changelog as end-users may need to update their ruleset. As for me, my questions regarding this statement are: Why were they changed/Why couldn't the change be avoided ? This is just one example of the non-specific. As things are, to review this, I will basically have to go through the complete dev journey you've gone through to figure out what you found, what the problem was, how it should be fixed and then to review if the fix made is correct. |
fd24097
to
71144b5
Compare
@jrfnl let's discuss this on our next call (tomorrow). I started the work before I remembered that you said you wanted to do this. I have added a table of differences between the old & new sniffs to the pull request description. You mentioned problems that you are aware of and that you would need to rewrite the sniff again anyway, but I don't see those details documented here on GitHub. Perhaps I'm not looking in the right places / using the search effectively enough. I've updated the code to include more test cases (the vast majority of which the previous sniff fails). I would like to get some XML documentation added too. |
@fredden Let's.
That is helpful, but underlines the opinion that this PR should have been split into multiple commits or even better, multiple PRs as a number of these changes are highly disputable (like the checks for spacing for the PHP close tag as those will very quickly conflict with a sniff which is dedicated to PHP close tags).
Correct, I didn't open an issue for this as there is so much and I intended to just fix it. I did mention the rewrite though whenever the sniff was brought up. To give you some idea of the more pertinent problems:
Making the PR even larger is not going to help at this time.
As noted in the docs issue (#148), that one is on hold until after the sniff rewrite. |
This comment was marked as outdated.
This comment was marked as outdated.
66ddbf4
to
8f89123
Compare
Description
While investigating a fixer conflict within the PSR12 standard (see #152), I noticed that the
PSR12.Files.DeclareStatement
sniff was doing the wrong thing for this test file:src/Standards/Generic/Tests/PHP/RequireStrictTypesUnitTest.5.inc
. Specifically, it was processing tokens well beyond the end of thedeclare()
statement and conflicting with thePSR12.Operators.OperatorSpacing
sniff for code after thedeclare()
statement. While attempting to fix this particular issue, I decided that a complete rewrite would be easier than trying to squeeze a patch in for the specific conflict.I have copied this test file so that we do not get any regressions in this sniff.
Suggested changelog entry
Complete rewrite of
PSR12.Files.DeclareStatement
. Error codes have been preserved where feasible.Related issues/external references
PSR12.Files.DeclareStatement
- bow out when parse error detected #335Types of changes
PR checklist
Table of differences between sniffs