Skip to content

feat: add ignore_single_line_comments option to phpdoc_type_annotations_only rule#428

Draft
MrPunyapal wants to merge 3 commits intolaravel:mainfrom
MrPunyapal:feat/make-single-line-comment-optional
Draft

feat: add ignore_single_line_comments option to phpdoc_type_annotations_only rule#428
MrPunyapal wants to merge 3 commits intolaravel:mainfrom
MrPunyapal:feat/make-single-line-comment-optional

Conversation

@MrPunyapal
Copy link
Contributor

This PR adds a configurable ignore_single_line_comments option to the Pint/phpdoc_type_annotations_only fixer.

When enabled, single-line comments (// and #) are preserved instead of being removed, while block comments (/* */) and docblocks without annotations are still processed as before.

This is useful for teams that want to keep inline documentation and section dividers in their code but still strip prose from docblocks.

Usage

{
    "rules": {
        "Pint/phpdoc_type_annotations_only": {
            "ignore_single_line_comments": true
        }
    }
}

Before (with ignore_single_line_comments: true)

// Authentication routes
Route::post('/login', [AuthController::class, 'login']);

/**
 * Display a listing of users.
 *
 * @return \Illuminate\Http\JsonResponse
 */
public function index() {}

After

// Authentication routes
Route::post('/login', [AuthController::class, 'login']);

/**
 * @return \Illuminate\Http\JsonResponse
 */
public function index() {}

Single-line comments stay, docblock prose is still stripped.

Changes

  • app/Fixers/TypeAnnotationsOnlyFixer.php — Implements ConfigurableFixerInterface with ConfigurableFixerTrait, adds ignore_single_line_comments boolean option (default: false)
  • tests/Feature/Fixers/PhpdocTypeAnnotationsOnlyFixerTest.php — Adds 12 new test cases covering the option in both true and false modes

Notes

  • Default behavior is unchangedignore_single_line_comments defaults to false
  • Body placeholder comments (// inside empty {}) are still handled correctly regardless of the setting
  • Comments containing @ annotations are always preserved regardless of the setting

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant