Postponed on #3221049: Let ShortNotCapital allow starting with some characters that do not have case See #72
Part of meta-issue #2571965: [meta] Fix PHP coding standards in core
Step 1: Preparation
Open the file core/phpcs.xml.dist
and add a line for the sniff of this ticket. The sniff name is in the issue title. Make sure your patch will include the addition of this line.
Step 2: Install & configure PHPCS
Install PHP CodeSniffer and the ruleset from the Coder module:
$ composer install
$ ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
Once you have installed the phpcs package, you can list all the sniffs available to you like this:
$ ./vendor/bin/phpcs --standard=Drupal -e
This will give you a big list of sniffs, and the Drupal-based ones should be present.
Step 3: Prepare the phpcs.xml file
To speed up the testing you should make a copy of the file phpcs.xml.dist
(in the core/
folder) and save it as phpcs.xml
. This is the configuration file for PHP CodeSniffer.
We only want this phpcs.xml file to specify the sniff we're interested in. So we need to remove all the rule items, and add only our own sniff's rule. Rule items look like this:
<rule ref="Drupal.Classes.UnusedUseStatement"/>
Remove all of them, and add only the sniff from this issue title. This will make sure that our tests run quickly, and are not going to contain any output from unrelated sniffs.
Step 4: Run the test
Now you are ready to run the test! From within the core/
folder, run the following command to launch the test:
$ cd core/
$ ../vendor/bin/phpcs -p
This takes a couple of minutes. The -p
flag shows the progress, so you have a bunch of nice dots to look at while it is running.
Step 5: Fix the failures
When the test is complete it will present you a list of all the files that contain violations of your sniff, and the line numbers where the violations occur. You could fix all of these manually, but thankfully phpcbf
can fix many of them. You can call phpcbf like this:
$ ../vendor/bin/phpcbf
This will fix the errors in place. You can then make a diff of the changes using git. You can also re-run the test with phpcs and determine if that fixed all of them.
Comment | File | Size | Author |
---|
Issue fork drupal-2903027
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mfernea CreditAttribution: mfernea at AmeXio commentedComment #3
mfernea CreditAttribution: mfernea at AmeXio commentedPartial work.
Comment #4
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedgoing to reroll it
Comment #5
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedre-rolled
Comment #6
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #8
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedAdded some part of work an additional
@Jo, it may be useful don't put it to status "Needs review" until work done?
Comment #9
jofitz CreditAttribution: jofitz at ComputerMinds commentedI set the status to "Needs review" to run the testbot on the patch you had re-rolled. Why did you not want it run? Similarly, why have you not set the status to "Needs review for your latest patch in #8?
Comment #10
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedI set the status to "Needs work" because the task isn`t finished (I did it similarly to the comment #3)
Anyway, I`m willing to get all the remarks/advises about work process. I`m new in contribution ) Thanks
Comment #11
andypostIt makes sense to run tests anyway - to get stats about how many inconsistencies left
Comment #13
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedComment #14
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled.
@Saviktor Are you working against the latest version of the 8.5.x branch? That might explain why your patch failed to apply.
Comment #16
jofitz CreditAttribution: jofitz at ComputerMinds commentedPatch in #14 no longer applies. Re-rolled.
Comment #18
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled #14.
Comment #19
mfernea CreditAttribution: mfernea at AmeXio commentedThe patch contains a lot of modifications which are out of scope. Please remove them. At 17 I also pointed out another type of issue.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Let's try to not add new issues.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Out of scope.
Comment #20
jofitz CreditAttribution: jofitz at ComputerMinds commentedThanks for the review @mfernea.
Removed the out of scope changes and corrected a few more comments that didn't start with capital letters.
Most (if not all) of the remaining 'errors' are comments starting "(optional) ..." which I would argue should be allowed.
Any thoughts?
Comment #21
mfernea CreditAttribution: mfernea at AmeXio commentedLooks better!
Can we put this on one line?
I would just remove (optional) as it's not part of Coding standards and is not used consistently even in the classes where it is present.
Comment #22
jofitz CreditAttribution: jofitz at ComputerMinds commentedRemoved all instances of (optional) at the beginning of comments and fixed the other coding standards error that had been introduced by the patch.
I could not think of a shorter comment that could remain on 1 line. I'm open to suggestions.
Comment #23
borisson_Do we need to fix this ; in this issue as well? It should be a period instead of the semicolon.
This removes the
*
, making it invalid.Same here.
More of those.
Verifies that ::renderRoot() is not called in another ::renderRoot() call.
Does that make sense?
Comment #24
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedI've made the above mention changes in a new patch.
Comment #25
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedComment #26
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedComment #27
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commenteduploading correct interdiff.
Comment #28
mfernea CreditAttribution: mfernea at AmeXio commented@borisson_'s #5 note from his last comment still needs to be addressed.
Other than that all issues mentioned by @borisson_ are solved and there aren't any new. Looks good to me!
Comment #29
jofitz CreditAttribution: jofitz at ComputerMinds commentedAddressed @borisson_'s point 5 from #23.
Comment #30
mfernea CreditAttribution: mfernea at AmeXio commentedWe should add ShortNotCapital in the comment from above that statement. Please make sure it's in alpha order. Sorry for not pointing this earlier.
Other than that the patch looks fine and includes the other mentioned changes. Still applies cleanly and no cs issues.
Comment #31
jofitz CreditAttribution: jofitz at ComputerMinds commented@mfernea But the comment above (I assume you mean lines 32-34) is not currently in alphabetical order.
Comment #32
mfernea CreditAttribution: mfernea at AmeXio commentedIndeed! Just add it there then. :)
Comment #33
jofitz CreditAttribution: jofitz at ComputerMinds commentedAdded ShortNotCapital to the list of errors to sniff for.
Comment #34
mfernea CreditAttribution: mfernea at AmeXio commentedGreat! RTBC then!
Comment #36
mfernea CreditAttribution: mfernea at AmeXio commentedThe failing test doesn't relate to modifications in this patch.
I guess it's related to this #2924201: Resolve random failure in LayoutBuilderTest so that it can be added to HEAD. Back to RTBC!
Comment #37
xjmThis docblock is already invalid; either
{@inheritdoc}
should be the only thing in the docblock, or it needs to override the whole thing. We could spin this off into a separate issue.So, this issue is doing the opposite of #2909370: Fix 'Drupal.Commenting.VariableComment.IncorrectVarType' coding standard.
Looking at all the changes in this patch, many of which are to work around what is probably valid documentation, I'm thinking we need to fix this rule to be less strict, instead of fixing it. At least this particular pattern of a parenthetical before a sentence that starts with a capital and ends with a period should be allowed. So let's file an issue to tweak the rule, and postpone this issue on that.
Thanks!
Comment #38
xjmIt looks like we have a standard for the callbacks here that also doesn't match how we're fixing it in the patch: https://www.drupal.org/node/1354#callback-def
Comment #39
neclimdulFriendly post #2902381: Revert phpcs.xml.dist changes from "Ensure that we're using the right ruleset for coding standards checking" reroll. No feedback addressed. No credit needed.
Comment #40
mfernea CreditAttribution: mfernea at AmeXio commentedRegarding "(optional)" I added #2925237: ShortNotCapital triggered by non-letters.
Regarding "{@inheritdoc}" we already have #2904801: @inheritdoc without { } is treated as a tag and gives missleading message. The problem is widespread.
Comment #48
SpokjeJust ran a test-run locally with this sniff, a lot seems to have changed for the better.
Unpostponing.
Comment #49
SpokjeMoving in to MR-land.
Comment #51
SpokjeComment #52
longwaveI am not 100% convinced this sniff adds anything useful, it doesn't help readability for me. It will also slow down patch authoring if test runs start to fail just because of this sniff, when they wouldn't otherwise.
Comment #53
SpokjeNot sure about this one either, for me it also doesn't add much, however readability is about the same for me before and after this sniff.
One could argue that the "real bad" non-capitalized comments were fixed in other sniffs, and that they might sneak in again in new code without this sniff.
One could argue that the sniff should not check for comments starting with numbers or "non-letters" (uses Get-Out-Of-Jail-Free-Card-Because-I-Am-A-Non-Native-Speaker card there) like
!@#$%^&*()
.Personally I would just turn this sniff on to prevent future "nasty" comments.
Although true, I think this can be said about any sniff, so I'm not sure if it's a valid argument
Comment #54
quietone CreditAttribution: quietone as a volunteer commentedI disagree with #51 so went ahead and reviewed the changes, no worries if they are not used. Personally, I do like the comment starting with 'The' and not '#'. And since this sniff picked up only 60 files, it is very unlikely to be disruptive. That is people are already writing new summary lines which will pass this sniff.
Comment #55
SpokjeThus spoke the mighy @quietone in #54
That alone is (at least for me) a good reason to think it's not disruptive.
If it makes more readable code is up for debate, but is, of course, a matter of personal taste.
@quietone likes it, @longwave doesn't.
Personally I say: Turn this sniff on, since it's basically non-disruptive. It will only catch the (small amount of) people that incidentally write something that's not cAPITALIZED correctly.
For that reason I addressed all the issues found by @quietone and put this on NR again.
Comment #56
quietone CreditAttribution: quietone as a volunteer commentedI read through the changes and it all looks good. For me, this is RTBC. Let's wait for longwave to chime in again.
Comment #57
longwaveSome of the changes here have swayed me to think that this is a good idea. Added a few comments/notes as I went along.
Comment #58
Spokje2 unresolved threats remaining
Comment #59
longwaveAdded suggestions for the two outstanding.
Comment #60
SpokjeThanks @longwave for the suggestions.
Changes made, all threads resolved -> NR
Comment #61
longwaveGreat, it's time to see what core committers think.
Comment #62
SpokjeRandom test fail on last run, triggered new test run.
Comment #63
longwaveAnother instance of #3208791: [random test failure] Random fail in LayoutBuilderDisableInteractionsTest
Comment #64
catchQuestion/comment from me in the MR..
Comment #65
SpokjeAn attempt to comment on the question/comment/suggestion/whatever from @catch in the MR, in the...
....
Wait for it....
.
..
...
MR :)
Comment #67
SpokjeRebased MR against
9.3.x
.Comment #68
paulocsI did a review and the patch fixes all doc comments that start with upper case character.
I'll move it RTBC and see if @catch will point any thing about #64.
I'm not attaching pictures from my local test because Drupal Automated Test would get it, but I ran
../vendor/bin/phpcs --extensions=php -p ./
and no error is displayed.Comment #69
paulocsComment #70
SpokjeThanks @paulocs for the Review.
I gave up on keeping MRs mergeable for non-RTBC issues, because somehow GitLab is notoriously bad at rebasing/merging with HEAD on Drupal (not noticed this on other projects), but since you made it an
RTBC
, here's a merge with HEAD from9.3.x
to get theMerge request !540
showing up in Green again.Comment #71
SpokjeRandom test-failure #3214565: [random test failure] Random fail in BuildTestTest::testPortMany
Comment #72
catchI think we should patch coder to be more permissive - coder should follow core coding standards rather than the other way around.
Comment #73
Spokje@catch: Although I agree with what you're saying I also see a lot of effort put in this issue now slowly being eroded by new code and code changes.
Oh well, let's wait until coder gets patched.
Comment #74
quietone CreditAttribution: quietone as a volunteer commentedThis is disappointing. This sniff is implementing what is in the coding standards. Does this mean the coding standards page is wrong and needs to be edited?
Comment #75
quietone CreditAttribution: quietone as a volunteer commentedAdded to the IS that this is postponed on #3221049: Let ShortNotCapital allow starting with some characters that do not have case