-
Notifications
You must be signed in to change notification settings - Fork 16
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
Update BoilerplateCommentSniff and add fixes. #158
Conversation
262c1b8
to
cd34717
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #158 +/- ##
============================================
+ Coverage 98.03% 98.08% +0.05%
- Complexity 901 932 +31
============================================
Files 40 40
Lines 2697 2769 +72
============================================
+ Hits 2644 2716 +72
Misses 53 53 ☔ View full report in Codecov by Sentry. |
cd34717
to
a260665
Compare
Hi, just sharing... also note that, regarding Edited: Note that it's only allowed in the php opening tag when the script has mixes of php and html sections, something that is not normally used by Moodle nowadays. Ciao :-) |
Thanks for the feedback @andrewnicols and @stronk7! I see declare strict types in line with the PHP opening tag an awful lot, so I'd assumed it was standard practice, but if it's not allowed by the standard that's good. I've excised all the code relating to declares and it's simplified the patch a lot. I've also added a unit test for the new error condition I added (CommentEndedTooSoon). I'd like to add tests for the fixes but I'm at a bit of a loss as to how to do that, as I can't find any examples anywhere - I've looked in quite a few standards. |
Also I have a couple of questions that could help me to improve the patch if I knew the answers.
(I was also wondering whether the http: URLs could be changed to https: ?) Do you know the answers to these? |
957a75e
to
ebd9b05
Compare
I've got a version of this that I'm happy with now, I hope you might consider it. Apologies for the confusion around the declare statements - I was mistaken about that and I've removed all traces of it. Hopefully it's clear enough from the code but the logic of the checks is now:
(The last one is a new rule, but it seems reasonable to me and helps with the fixes. I'll remove it if it's not acceptable.) The way the checks are done simplifies the corresponding fixes:
As well as the unit tests I ran the fixes against Moodle core and can't see any issues: moodle/moodle@main...micaherne:moodle:boilerplate-sniff-test (apart from where there are some existing very non-standard copyright notices that couldn't be detected!) |
Thanks for all the effort put on this, @micaherne. I'm going to take a look to it now, sorry for the delay! Will come with some comments or suggestions if I find something. Ciao :-) |
FYI, I've taken the liberty of rebasing your commit on top of "main", to have it updated. |
0ce282e
to
a9a549a
Compare
a9a549a
to
159cb2c
Compare
And another small edition, simply changing a few var names, no change in logic, so far. |
And, now, I've added (in a new commit, to see the changes easier) a good number of "fixture.php.fixed" files to ensure that the fixer is doing its job with all them. Also, have added one new test (trailing_whitespace_missing) to complete the coverage. And updated the changelog file. |
2280873
to
ba88826
Compare
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.
Ok, I think this can be considered ready, with tests passing and all the previous discussions already resolved, hence, accepting.
@stronk7 thanks for fixing this up and getting it into production! |
ty! |
For the records, #168 has been created, regression of this, about we needing, surely, to allow "extra lines" in the boilerplate to exist, and only apply the |
There are a few troublesome things I find about BoilerplateCommentSniff:
declare(strict_types=1)
in the standard place - on the same line as the opening PHP tag. You have to put it directly after the Moodle comment, which is obviously valid but it's non-standard and harder to spot.(I appreciate that the second point probably doesn't affect core development so much because all core files have the boilerplate, but it just swamps the output with noise if you have a plugin that doesn't yet have the boilerplate in any of the files.)
Could I propose this patch to improve things a bit? It:
declare()
calls on the same line as the opening PHP tag