Skip to content

Commit 35fd3b6

Browse files
committed
CommaAfterArrayItem: add metrics for comma after last item
Add metrics to make it easier for people to decide whether or not to en/disable this rule. The generated metrics will look like this and can be called up using `--report=info`: ``` PHP CODE SNIFFER INFORMATION REPORT ---------------------------------------------------------------------- Multi-line array - comma after last item: no => 2,064 ( 95.82%) yes => 90 ( 4.18%) ------------------------- total => 2,154 (100.00%) Single line array - comma after last item: 0 [804/804, 100%] ```
1 parent eea3371 commit 35fd3b6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public function process_token( $stackPtr ) {
103103
*/
104104
if ( true === $single_line && $item_index === $array_item_count ) {
105105

106+
$this->phpcsFile->recordMetric(
107+
$stackPtr,
108+
'Single line array - comma after last item',
109+
( true === $is_comma ? 'yes' : 'no' )
110+
);
111+
106112
if ( true === $is_comma ) {
107113
$fix = $this->phpcsFile->addFixableError(
108114
'Comma not allowed after last value in single-line array declaration',
@@ -153,6 +159,14 @@ public function process_token( $stackPtr ) {
153159
}
154160
}
155161

162+
if ( false === $single_line && $item_index === $array_item_count ) {
163+
$this->phpcsFile->recordMetric(
164+
$stackPtr,
165+
'Multi-line array - comma after last item',
166+
( true === $is_comma ? 'yes' : 'no' )
167+
);
168+
}
169+
156170
if ( false === $is_comma ) {
157171
// Can't check spacing around the comma if there is no comma.
158172
continue;

0 commit comments

Comments
 (0)