Problem/Motivation
After #1876018: Displaced space in core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php has been committed I stumble upon lots of "disabled spaces". Both ways are possible but I think that we have to agree on a standard for that.
$ grep -irn " =&" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme | wc -l
50
$ grep -irn " = &" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme | wc -l
328
The results include some regex expressions but you can see that the = & way is more present than the other way. After the code freeze we can start with writing patches for that. Note that this part is missing in the coding standards, so we also have to update them.
Benefits
If we adopted this change, the Drupal Project would benefit by ...
Three supporters required
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
Proposed changes
Provide all proposed changes to the Drupal Coding standards. Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:
1. Operators
Current text
All binary operators (operators that come between two values), such as
+,-,=,!=,==,>, etc. should have a space before and after the operator, for readability. For example, an assignment should be formatted as$foo = $bar;rather than$foo=$bar;. Unary operators (operators that operate on only one value), such as++, should not have a space between the operator and the variable or number they are operating on.
Proposed text
All binary operators (operators that come between two values), such as
+,-,=,!=,==,>, etc. should have a space before and after the operator, for readability. For example, an assignment should be formatted as$foo = $bar;and an assignment by reference as$foo = &$bar.
Unary operators (operators that operate on only one value), such as++, should not have a space between the operator and the variable or number they are operating on.
2. Repeat the above for each page or sub-page that needs to be changed.
Remaining tasks
Create this issue in the Coding Standards queue, using the defined template- Add supporters
- Create a Change Record
- Review by the Coding Standards Committee
- Coding Standards Committee takes action as required
- Discussed by the Core Committer Committee, if it impacts Drupal Core
- Final review by Coding Standards Committee
- Documentation updates
- Edit all pages
- Publish change record
- Remove 'Needs documentation edits' tag
- If applicable, create follow-up issues for PHPCS rules/sniffs changes
For a full explanation of these steps see the Coding Standards project page
Comments
Comment #0.0
yannickooTypo
Comment #1
jhodgdonTagging and standardizing issue title for a standards issue.
Comment #1.0
jhodgdonSplitted
block.Comment #2
jhodgdonCoding standards decisions are now supposed to be made by the TWG
Comment #3
tizzo commentedMoving this issue to the Coding Standards queue per the new workflow defined in #2428153: Create and document a process for updating coding standards.
Comment #4
avpadernoIn a directory containing Drupal 11 files,
grep -irn "=&" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme| wc -lreturned 93, whilegrep -irn "=&" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme| wc -lreturned 328.Truly, the first command also count lines like the following ones.
Probably, the following commands give a more precise result.
grep -irn " =&" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme | wc -l(50)grep -irn " = &" ./ --include=*.module --include=*.php --include=*.inc --include=*.install --include=*.theme | wc -l(328)Comment #5
avpaderno(I apologize: I added a sentence to the issue summary instead of putting it on my comment.)
Comment #6
quietone commentedThis was discussed at coding standards meetings, #3456119: Coding Standards Meeting Tuesday 2024-06-18 2100 UTC.
The existing text does cover this case but there was a question if the text should make clear that 'operator' does not mean any combination of operators.
And a sniff will be needed to ensure the agreed format is enforced.
Comment #7
quietone commentedComment #8
catchYeah I think it's implicit in the existing coding standard but we should make it explicit.
Comment #9
quietone commentedJust for info:
and
I updated the issue summary with a proposed text. It add an example, removes the two related 'instead of' examples and moved the 'unary to a separate paragraph. I removed the 'instead of' because I find pointing out what not to do isn't helpful.
Comment #10
avpadernoIn the following sentence, I would use a different operator as example.
$var = 1++;contains a syntax error, likeecho 1++, "\n";.I am not sure how to make that sentence better, considering that even
newis a unary operator, for which there must be a space between the operator and its operand. (their operand can replace the variable or number they are operating on, but that role is not valid for all the unary operators.)