Commit 4a7e3e8
committed
fix: wrongly adding
When a function doesn't have a docblock that is found to need a `@return`, and the function or class property above it does have a docblock, the `@return` is added to that docblock. Ergo: the wrong docblock.
The problem was that the code was finding the previous docblock in the file and treating it as if it belonged to the current function, even when there were other elements (like properties or other functions) between the docblock and the function being processed.
To fix, we validate whether the found docblock actually belongs to the function we were looking for. This is done by looking for significant tokens between the found docblock and the function. If the tokens contain anything other than function modifiers like `public`, `protected`, `abstract`, etc. then we ignore the docblock entirely and just stop processing the issue.
- Added logic in the `FunctionCommentSniff` class to check if the docblock belongs to the function and skip if it doesn't.
- Added new test functions in the test file.@return to the wrong docblock.1 parent 457137c commit 4a7e3e8
File tree
3 files changed
+41
-0
lines changed- test_utils
- yCodeTech/Sniffs/Commenting
3 files changed
+41
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
78 | 91 | | |
79 | 92 | | |
80 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
78 | 91 | | |
79 | 92 | | |
80 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
68 | 83 | | |
69 | 84 | | |
70 | 85 | | |
| |||
0 commit comments