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

Make MissingDoclock code more specific (Fixes #154) #156

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt

## [Unreleased]
### Added
- The existing `moodle.PHPUnit.TestCaseCovers` sniff now detects multiple uses of the `@coversDefaultClass` annotation. Only one is allowed by class.
- The existing `moodle.PHPUnit.TestCaseCovers` sniff now detects multiple uses of the `@coversDefaultClass` annotation. Only one is allowed by class.

### Changed
- Made codes for `moodle.Commenting.MissingDocblock` more specific to the scenario (Fixes #154).

## [v3.4.7] - 2024-05-31
### Added
Expand Down
10 changes: 5 additions & 5 deletions moodle/Sniffs/Commenting/MissingDocblockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function processScopes(File $phpcsFile, int $stackPtr): void {

if ($fileblock === null) {
$objectName = TokenUtil::getObjectName($phpcsFile, $stackPtr);
$phpcsFile->addError('Missing docblock for file %s', $stackPtr, 'Missing', [$objectName]);
$phpcsFile->addError('Missing docblock for file %s', $stackPtr, 'File', [$objectName]);
}
}

Expand All @@ -110,7 +110,7 @@ protected function processScopes(File $phpcsFile, int $stackPtr): void {
$objectName = TokenUtil::getObjectName($phpcsFile, $typePtr);
$objectType = TokenUtil::getObjectType($phpcsFile, $typePtr);

$phpcsFile->addError('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, ucfirst($objectType), [$objectType, $objectName]);
}

if ($artifactCount === 1) {
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function processFunctions(File $phpcsFile, int $stackPtr): void {
);
}
} else {
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, ucfirst($objectType), [$objectType, $objectName]);
}
}
}
Expand Down Expand Up @@ -255,14 +255,14 @@ protected function processConstants(File $phpcsFile, int $stackPtr): void {
$phpcsFile->addError(
'Missing docblock for constant %s::%s',
$typePtr,
'Missing',
'Constant',
[$containerName, $objectName]
);
} else {
$phpcsFile->addError(
'Missing docblock for constant %s',
$typePtr,
'Missing',
'Constant',
[$objectName]
);
}
Expand Down
22 changes: 21 additions & 1 deletion moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testMissingDocblockSniff(

public static function docblockCorrectnessProvider(): array {
$cases = [
'Multiple artifacts in a file' => [
'Multiple artifacts in a file, check messages' => [
'fixture' => 'multiple_artifacts',
'fixtureFilename' => null,
'errors' => [
Expand All @@ -72,6 +72,26 @@ public static function docblockCorrectnessProvider(): array {
'warnings' => [
],
],
'Multiple artifacts in a file, check codes' => [
'fixture' => 'multiple_artifacts',
'fixtureFilename' => null,
'errors' => [
1 => 'moodle.Commenting.MissingDocblock.File',
34 => 'moodle.Commenting.MissingDocblock.Function',
38 => 'moodle.Commenting.MissingDocblock.Class',
95 => 'moodle.Commenting.MissingDocblock.Interface',
118 => 'moodle.Commenting.MissingDocblock.Trait',
151 => 'moodle.Commenting.MissingDocblock.Function',
159 => 'moodle.Commenting.MissingDocblock.Function',
166 => 'moodle.Commenting.MissingDocblock.Function',
170 => 'moodle.Commenting.MissingDocblock.Class',
171 => 'moodle.Commenting.MissingDocblock.Function',
175 => 'moodle.Commenting.MissingDocblock.Class',
176 => 'moodle.Commenting.MissingDocblock.Function',
],
'warnings' => [
],
],
'File level tag, no class' => [
'fixture' => 'class_without_docblock',
'fixtureFilename' => null,
Expand Down