Skip to content

Commit b1d2f55

Browse files
Merge pull request #44 from VincentLanglet/commentRule
✨ Relax comment rule
2 parents cb12ef4 + bc0f015 commit b1d2f55

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,8 @@ public function process(File $phpcsFile, $stackPtr)
4343
}
4444
}
4545

46-
$name = $phpcsFile->getDeclarationName($stackPtr);
47-
$isTestFunction = strpos($name, 'test') === 0;
48-
$isAllowedFunction = in_array($name, ['setUp', 'tearDown']);
49-
$commentRequired = !$isTestFunction && !$isAllowedFunction;
50-
51-
if (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
52-
&& T_COMMENT !== $tokens[$commentEnd]['code']
53-
) {
54-
$hasComment = false;
55-
$phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'no');
56-
57-
if ($commentRequired) {
58-
$phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
59-
60-
return;
61-
}
62-
} else {
63-
$hasComment = true;
64-
$phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'yes');
65-
}
46+
$hasComment = T_DOC_COMMENT_CLOSE_TAG === $tokens[$commentEnd]['code']
47+
|| T_COMMENT === $tokens[$commentEnd]['code'];
6648

6749
if ($hasComment) {
6850
if (T_COMMENT === $tokens[$commentEnd]['code']) {

SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ function testToIgnore2()
9494
{
9595
$test = 42;
9696
}
97+
98+
function toIgnore1()
99+
{
100+
$test = 42;
101+
}
102+
function toIgnore2()
103+
{
104+
$test = 42;
105+
}

SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,13 @@ function testToIgnore2()
9797
{
9898
$test = 42;
9999
}
100+
101+
function toIgnore1()
102+
{
103+
$test = 42;
104+
}
105+
106+
function toIgnore2()
107+
{
108+
$test = 42;
109+
}

SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ class FunctionCommentUnitTest extends AbstractSniffUnitTest
2222
public function getErrorList()
2323
{
2424
return array(
25-
5 => 1,
26-
10 => 2,
27-
43 => 1,
28-
48 => 2,
29-
76 => 2,
30-
83 => 1,
31-
93 => 1,
25+
5 => 1,
26+
10 => 2,
27+
43 => 1,
28+
48 => 2,
29+
76 => 2,
30+
83 => 1,
31+
93 => 1,
32+
102 => 1,
3233
);
3334
}
3435

0 commit comments

Comments
 (0)