Skip to content
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

Generic/ArrayIndent: add XML documentation #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/Standards/Generic/Docs/Arrays/ArrayIndentStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<documentation title="Array Indent">
<standard>
<![CDATA[
The opening square bracket/parenthesis of a multi-line array must be indented at least to the same level of the start of the statement.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to use opening square bracket/parenthesis here and in a few other places as the sniff supports both array syntaxes. That is not super correct as in the old syntax, the opening token of an array is not just a parenthesis, but actually array(.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the phrase "open brace" (and "close brace" for the end, of course) ? Would that work ? What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this <standard> block, I'm specifically mentioning multi-line arrays. It is the only error that could apply to a single-line array, but single-line arrays are not handled by this sniff. The example that I have in mind is:

    $a = 
[1, 2];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested, that snippet would not trigger the sniff anyway, so we can forget about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a possible alternative (to get away from the kind of braces):

Suggested change
The opening square bracket/parenthesis of a multi-line array must be indented at least to the same level of the start of the statement.
The start of a multi-line array must be indented at least to the same level as the start of the statement.

]]>
</standard>
<code_comparison>
<code title="Valid: Opening square bracket/parenthesis token of a multi-line array indented at least to the same level of the start of the statement.">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<code title="Valid: Opening square bracket/parenthesis token of a multi-line array indented at least to the same level of the start of the statement.">
<code title="Valid: Opening square bracket/parenthesis token of a multi-line array indented at least to the same level as the start of the statement.">

(aside from having a think about the braces phrasing)

<![CDATA[
if ($condition) {
$a =
<em> [</em>
1,
2,
];
Comment on lines +11 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a second code sample here showing that having the opening brace on the same line as the assignment is also perfectly valid under this rule ?

}
]]>
</code>
<code title="Invalid: Opening square bracket/parenthesis of a multi-line array not indented at least to the same level of the start of the statement.">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<code title="Invalid: Opening square bracket/parenthesis of a multi-line array not indented at least to the same level of the start of the statement.">
<code title="Invalid: Opening square bracket/parenthesis of a multi-line array not indented at least to the same level as the start of the statement.">

(aside from having a think about the braces phrasing)

<![CDATA[
if ($condition) {
jrfnl marked this conversation as resolved.
Show resolved Hide resolved
$a =
<em>[</em>
1,
2,
];
}
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
The elements of an array must be indented four spaces beyond the indentation level of the opening square bracket/parenthesis.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, not sure how to rephrase this, but there are some things here which don't ring true/could be confusing:

  • The indentation is only checked for the first line of each element (subsequent lines are not checked for indentation).
  • "Four spaces beyond"- not sure how much margin that give to interpret this as "at least four spaces", while the rule is "exactly four spaces".
  • "the indentation level of the opening square bracket/parenthesis" - it's not about the indentation/position of the brackets, but about the start of statement which includes the array opener.

Let's rethink the phrasing of this rule.

Note: this also means the Valid/Invalid phrasing may need updating.

]]>
</standard>
<code_comparison>
<code title="Valid: Elements of an array indented four spaces beyond the indentation level of the opening square bracket/parenthesis.">
<![CDATA[
$a = array(
<em> 1</em>,
<em> 2</em>,
<em> 3</em>,
);
]]>
</code>
<code title="Invalid: Elements of an array not indented four spaces beyond the indentation level of the opening square bracket/parenthesis.">
<![CDATA[
$a = array(
<em> 1</em>,
2,
<em> 3</em>,
);
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
There must be a newline before the array closing square bracket/parenthesis.
]]>
</standard>
<code_comparison>
<code title="Valid: Newline before the array closing square bracket/parenthesis.">
<![CDATA[
$a = [
1,
2,<em>
]</em>;
]]>
</code>
<code title="Invalid: No newline before the array closing square bracket/parenthesis.">
<![CDATA[
$a = [
1,
2,<em>]</em>;
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
The closing square bracket/parenthesis must be indented four spaces less than the array elements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be clearer if the indentation was phrased to be related to "same level of indentation as the start of the statement containing the array opener" (or something along those lines) ?

]]>
</standard>
<code_comparison>
<code title="Valid: Closing square bracket/parenthesis indented four spaces less than the array elements.">
<![CDATA[
$a = array(
1,
2,
<em>)</em>;
]]>
</code>
<code title="Invalid: Closing square bracket/parenthesis not indented four spaces less than the array elements.">
<![CDATA[
$a = array(
1,
2,
<em> )</em>;
]]>
</code>
</code_comparison>
</documentation>