Skip to content

Commit 26c0368

Browse files
committed
Issue #22: Enforce type hint inline comment syntax
1 parent 9256901 commit 26c0368

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Backdrop/Sniffs/Commenting/InlineCommentSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ public function process(File $phpcsFile, $stackPtr)
179179
}
180180
}
181181

182+
if ($tokens[$stackPtr]['type'] === 'T_COMMENT' && strpos($tokens[$stackPtr]['content'], '@var') !== FALSE) {
183+
// Enforce inline type hints to the syntax most widely supported by IDEs and tools.
184+
if (strpos($tokens[$stackPtr]['content'], '/**') !== 0) {
185+
$error = 'Inline type hint comments must be in the form "/** @var ... */".';
186+
$phpcsFile->addError($error, $stackPtr, 'InvalidTypeHint');
187+
}
188+
}
189+
182190
// Only want inline comments.
183191
if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
184192
return;

0 commit comments

Comments
 (0)