Php-cs-fixer: phpstorm comments code with // at the beginning of line

Created on 18 Feb 2015  路  15Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

when commenting code phpstorm comments code with // at the beginning of the line and when phpcs runs it corrects only the first line apparently. We either don't do it at all or we correct more than one line.

<?php

class Example
{
     public function getGoalChoices(CaseId $caseId)
     {
-//        'query_builder' => function (GoalRepository $repository) use ($options) {
+        //        'query_builder' => function (GoalRepository $repository) use ($options) {
 //        return $repository->createQueryBuilder('g')
}
kinquestion

Most helpful comment

when commenting code phpstorm comments code with // at the beginning of the line

OT, just a little note: You can change this in settings (Editor / Code Style / PHP / Other / Line comment at first column).

All 15 comments

@GrahamCampbell does your upcoming fixer also fixes this?

@cordoval No. My fixers only deal with the contents of T_DOC_COMMENT, not the other comments.

This doesn't look like a bug imo though. This is the indentation fixer saying you must correctly indent your function bodies.

See no reason why not to indent whole multiline comment.
Could you send a patch?

you are asking @GrahamCampbell right? :older_man:

If you are tell me that, then can you elaborate at least where can I start trying my patch?

Could you send a patch?

@cordoval I assume @keradus wants you to send a fix since you're affected by this bug.

To be honest - I would be happy if any one of you could. Just can't handle all of them myself.

First should be decision about solution - to ignore comment or indent whole comment body.
Then - find a fixer which has that bug.
Next one is add a testcase to prove that bug in SomeFixerTest class.
And finally fix is it SomeFixer ;)

there should be a cookbook with approaches to solve issues like this. Thank you @GrahamCampbell @keradus I will try but no promises i am pretty busy but trying to get back to the FOSS arena again.

We have one for creating a new fixer.
Please, based on new experience you gain could you propose it? For a regular contributor it is obvious and he won't mention everything what is needed.

This seems to be caused by the IndentationFixer, try disabling this to confirm.

I don't think we can actually change this, you can (temp) disable this fixer or not run the CS fixer when you are experimenting ;)

I don't think we can actually change this

Could you elaborate this please?

Well, if we change this then the fixer will no longer indent comments (including the simple //), detecting if this commented code is possible but will slowdown the fixer.

I meant changing the behavior ;) (_working late makes me a dull boy_), the wrong indenting of comments must be fixed either way. Unless anyone else is willing to fix this I will take a stab at this in the weekend.

We could fix it in this way:

class Example
{
     public function getGoalChoices(CaseId $caseId)
     {
-//        'query_builder' => function (GoalRepository $repository) use ($options) {
+        //        'query_builder' => function (GoalRepository $repository) use ($options) {
-//        return $repository->createQueryBuilder('g')
+        //        return $repository->createQueryBuilder('g')
}

any thoughts? (not about way of implementing it, but direction of fixing it in that way or not)

when commenting code phpstorm comments code with // at the beginning of the line

OT, just a little note: You can change this in settings (Editor / Code Style / PHP / Other / Line comment at first column).

closing since i think i rather not write comments to complicate things or at least commented code like this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amitbisht511 picture amitbisht511  路  3Comments

ndench picture ndench  路  3Comments

UksusoFF picture UksusoFF  路  3Comments

aidantwoods picture aidantwoods  路  3Comments

grachevko picture grachevko  路  3Comments