Add new sniff for checking Control structure brackets are on a new line#1847
Add new sniff for checking Control structure brackets are on a new line#1847photodude wants to merge 42 commits intosquizlabs:masterfrom
Conversation
|
@gsherwood What Code standard should I use to format things here? I seem to have chosen the wrong one for the formatting. |
|
@photodude PHPCS has its own ruleset you can use: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist 😄 |
|
Thanks @jrfnl, hopefully I implemented the fixer right since I just ran it directly from the github files so I didn't have to mess with my PHPCS 2.9 install. |
|
@photodude Want me to have a look/review ? |
|
Do you mean to review the sniff? Yes, please. I think the code style is fixed, if I can get the one comment section to stop yelling at me that it wants more or less indenting, or things at the end. |
|
code style should be all in the green now |
|
@jrfnl @gsherwood This is now good to go for review consideration |
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/ControlStructures/ControlStructuresBracketsUnitTest.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/ControlStructures/ControlStructuresBracketsUnitTest.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/ControlStructures/ControlStructuresBracketsUnitTest.php
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,170 @@ | |||
| <?php | |||
There was a problem hiding this comment.
The test file doesn't have any examples of comments being placed between the closing parenthesis and the opening brace of the control structures, so it's not obvious how those would be fixed. A few examples of using // comment and the phpcs annotations like // phpcs:ignore -- for reasons would be good, just to make sure the sniff copes with them on other people's code.
There was a problem hiding this comment.
I'll see about adding those cases
|
Quick question, if (array_key_exists('nested_parenthesis', $tokens[$stackPtr])) {What is the correct solution for this? |
|
|
Thanks @gsherwood (and @jrfnl I saw your comment too for a moment) I believe the last items here are
|
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Sniffs/ControlStructures/ControlStructuresBracketsNewLineSniff.php
Outdated
Show resolved
Hide resolved
|
I've done another review of this but it's not ready to merge yet. It still needs those last two items completed (remove real code from tests + add tests for comment syntax) plus:
I've also put a few minor changes into a review for you. |
|
I've done another review of this and it's not ready to merge:
I'm going to remove this from the 3.5.0 release and there looks to be too much more to do here to get it ready. |
|
@photodude any way that this will be finished? If you need some assistance let me know |
|
@pimjansen I would love to get this finished. Assistance would be greatly appreciated and would greatly speed along the process. (I, unfortunately, have reduced availability to work on side projects like this at the moment)
|
|
What is the easiest way to help here since this is open for way too long. What is still open and the fastest way to continue on this branch? |
@pimjansen If you can work on any of the open items in the to do checklist that would help complete this sniff. |
|
@pimjansen I don't think I'm going to get back to working on this, as I'm now working in a different field. If you would like to take over and finish this PR all the necessary information on what needs to be completed is here. |
- Sniff Error Case Changes in error sentences - Sniff errors don't end with full stops, remove periods - Replace `PHP_CodeSniffer_Tokens` with `Tokens` Co-Authored-By: photodude <photodude@users.noreply.github.com>
Leave test code as code structure but not "real" code. The intent is to only test the structure.
We don't want "real" code in the test just code structure as we are only testing code structure
…ketsNewLineUnitTest.inc
…esBracketsNewLineUnitTest.inc.fixed
…ketsNewLineUnitTest.php
return an empty array as getWarningList() must return an array
First round of correcting the line numbers for the Error list
Round 2 of correcting the line numbers for the Error list Expected errors should now be correct... LINE 225 is reporting expected 1 error but found 0 errors. but there is an indent error as the line should be indented more to match the control structure. Seems like line 225 is thinking it belongs to the closure function and not the control structure.
I believe this sniff's scope is restricted to checking the first bracket for new line and associated alignment.
…tsNewLineSniff.php
…NewLineUnitTest.inc.fixed
…cketsNewLineUnitTest.php
The unit test files are indented using tabs, replace tabs with spaces unless the tab is testing something (add comments to specify if the tabs are testing something specific)
e1849ea to
e11b5d7
Compare
Examples of comments being placed between the closing parenthesis () and the opening brace {} of the control structures using // comment
Add examples using phpcs annotations to make sure the sniff copes with them on other people's code.
This reverts commit a94ff2f.
Add examples using phpcs annotations to make sure the sniff copes with them on other people's code.
|
Closing as Joomla4 is moving to PSR12. There is work to make this PR happen and I'm currently not working in PHP and don't know when I would be able to work on this again. |
Add new sniff for checking Control structure brackets are on a new line
Add new test for the new sniff checking Control structure brackets are on a new line