Skip to content

Commit 821b348

Browse files
committed
Allow names marking unused variable ($_, $__ etc.)
1 parent 38b50a9 commit 821b348

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Cdn77/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class ValidVariableNameSniff extends AbstractVariableSniff
2828
{
29-
public string $pattern = '\b[a-zA-Z][a-zA-Z0-9]*?([A-Z][a-zA-Z0-9]*?)*?\b';
29+
public string $pattern = '\b(([a-zA-Z][a-zA-Z0-9]*?([A-Z][a-zA-Z0-9]*?)*?)|_+)\b';
3030

3131
/**
3232
* Processes this test, when one of its tokens is encountered.

tests/Sniffs/NamingConventions/ValidVariableNameSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function testErrors(): void
6161
141 => self::CODE_NOT_CAMEL_CAPS,
6262
146 => self::CODE_MEMBER_NOT_CAMEL_CAPS,
6363
150 => [self::CODE_NOT_CAMEL_CAPS, self::CODE_NOT_CAMEL_CAPS],
64+
152 => self::CODE_NOT_CAMEL_CAPS,
6465
];
6566
$possibleLines = array_keys($errorTypesPerLine);
6667

@@ -78,6 +79,6 @@ public function testErrors(): void
7879
}
7980
}
8081

81-
self::assertSame(37, $file->getErrorCount());
82+
self::assertSame(38, $file->getErrorCount());
8283
}
8384
}

tests/Sniffs/NamingConventions/data/ValidVariableNameSniffTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,5 @@ echo $obj?->varname;
148148
echo $obj?->_varName;
149149

150150
$var_name . $var_name;
151+
152+
fn($_, $__, $_x) => true;

0 commit comments

Comments
 (0)