-
-
Notifications
You must be signed in to change notification settings - Fork 518
[Update] Docs for array declaration spacing sniff #2593
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
base: develop
Are you sure you want to change the base?
Changes from all commits
ac45798
f676769
16949aa
6bd80ec
c2b316c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,75 @@ | ||||||
<?xml version="1.0"?> | ||||||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||||||
title="Array Declaration Spacing" | ||||||
> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
When an array uses keys, each key/value pair must start on a new line. | ||||||
]]> | ||||||
</standard> | ||||||
<code_comparison> | ||||||
<code title="Valid: There is only one key/value pair per line."> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<![CDATA[ | ||||||
$args = array( | ||||||
<em>'post_id' => 22</em>, | ||||||
<em>'category' => 1</em>, | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
<code title="Invalid: More than one key/value pair per line."> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<![CDATA[ | ||||||
$args = array( | ||||||
<em>'post_id' => 22, 'category' => 1</em>, | ||||||
); | ||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing that I missed in my original review is that in order for this example to trigger the |
||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
Each item in a multi-line array must be on a new line. | ||||||
]]> | ||||||
</standard> | ||||||
<code_comparison> | ||||||
<code title="Valid: Only one array item per line."> | ||||||
<![CDATA[ | ||||||
$args = array( | ||||||
<em>'post_id'</em>, | ||||||
<em>'comment_count'</em>, | ||||||
<em>'post_type'</em>, | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
<code title="Invalid: More than one item per line in a multi-line array."> | ||||||
<![CDATA[ | ||||||
$args = array( | ||||||
<em>'post_id', 'comment_count', 'post_type'</em>, | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
Associative arrays with multiple key-value pairs must also follow this rule. | ||||||
]]> | ||||||
</standard> | ||||||
<code_comparison> | ||||||
<code title="Valid: Each key-value pair on its own line."> | ||||||
<![CDATA[ | ||||||
$settings = array( | ||||||
<em>'width' => 300</em>, | ||||||
<em>'height' => 200</em>, | ||||||
<em>'color' => 'blue'</em>, | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
<code title="Invalid: Multiple key-value pairs on the same line in a multi-line array."> | ||||||
<![CDATA[ | ||||||
$settings = array( | ||||||
<em>'width' => 300, 'height' => 200</em>, | ||||||
<em>'color' => 'blue'</em>, | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
Comment on lines
+51
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry if my comment in the original PR was not clear, but in https://github.com/WordPress/WordPress-Coding-Standards/pull/2489/files#r1775277204, I was not suggesting to add a new |
||||||
</documentation> |
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.
There is something else that I missed in my original review. Using the default configuration of the sniff, which is what we want to document the XML file, the error
ArrayItemNoNewLine
is only triggered for multi-item single-line arrays, so it might be worth including this information in the description and in the code comparison titles.