cakephp / cakephp/cakephp-codesniffer

CakePHP.WhiteSpace.FunctionSpacing should recognize comments

Open
#409 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
232
Forks
85
PR merge metrics
No merged PRs in 30d

Description

1 public function foo(): void {
2  //blah
3 }
4
5 // here's a comment
6 public function bar(): void {
7  //blah
8 }

The above produces an error:
6 | ERROR | [x] Every function/method needs a newline before (CakePHP.WhiteSpace.FunctionSpacing.Concrete)

Line 4 is a newline, which, IMO, satisfies the sniff requirement. The sniff is not paying attention to the fact that just above is a comment, and above that comment is a new line.

Changing line 5 to this /** here's a comment */ passes the sniff. Why does one comment style pass and the other does not? Both are perfectly valid php comments.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CakePHP.WhiteSpace.FunctionSpacing sniff and reproduce the reported PHP example containing line comments and doc comments. Trace why the blank line before the function is treated differently, then add coverage showing both valid comment styles satisfy the spacing requirement.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.