The Comments Density Analyzer is a tool to help you monitor and manage comments in your codebase.
- Control TODOs and FIXMEs in CI/CD: Ensure these comments are not proliferating unchecked in your codebase.
- Spot Problematic Comments: Identify regular comments explaining "shitty code" or remnants of commented-out code.
- Enforce Documentation Standards: Require docblocks for classes and methods to maintain clear, consistent documentation.
All of this is made possible with a powerful plugin system (see the documentation for examples).
- Multiple Comment Types: Detect and analyze regular comments, docblocks, TODOs, FIXMEs, and license headers.
- Plugin Support: Extend functionality by creating custom plugins via a simple interface.
- Detailed Reporting: Quickly identify areas of your code that need attention.
- Thresholds and Exit Codes: Set thresholds for comment types and return an exit code when they are exceeded.
- Configurable Reports: Output results to the console or as an HTML report.
- Baseline Support: Filter out known technical debt using a baseline file and focus on new issues.
Install Comments Density Analyzer as a development dependency via Composer:
composer require --dev savinmikhail/comments-density
Analyze the comments in your PHP files:
php vendor/bin/comments_density analyze
Generate a baseline to ignore existing technical debt:
php vendor/bin/comments_density baseline
During installation, the tool can generate a default configuration file. Customize your analysis by editing the comments_density.php
file:
<?php
declare(strict_types=1);
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\FixMeComment;
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\RegularComment;
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\TodoComment;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\Config;
return new Config(
directories: [
'src',
],
thresholds: [
RegularComment::NAME => 0,
TodoComment::NAME => 0,
FixMeComment::NAME => 0,
],
);
This project was inspired by Yegor Bugayenko. See Open Source Ideas.
Contributions are always welcome! Feel free to submit a pull request with improvements or new features.
This library is licensed under the MIT License.