简体   繁体   中英

PhpStorm Coding Style: align anonymous function

I am currently trying to use the PEAR Coding Standards and I can't get anonymous functions to align correctly in function calls. Here is an example :

What is recommended by the standards:

test(
    function () {
        return "";
    }
);

This works by default.

However, as soon as I have more than one parameter, PhpStorm unindents the function content and closing brace :

test(
    "test", function () {
return "";
}
);

But what is recommended by the standards is the following :

test(
    "test", function () {
        return "";
    }
);

Note: When enabling "Function declaration parameters" > "Align when multiline", I have the correct alignment if I put each parameter on its own line :

test(
    "test", 
    function () {
        return "";
    }
);

I couldn't find a way to make this possible without having to put each parameter on its own line, would someone if this is possible/how to do it ?

Note 2 : I loaded the PEAR Coding Style using the "Predefined Style" already implemented out of the box in PhpStorm and only did little tweaks.

Note 3 : I am using PHPCS to check my code. Here are the errors I get with the PhpStorm-formatted code :

4 | ERROR | [x] Line indented incorrectly; expected at least 8 spaces, found 4 (PEAR.WhiteSpace.ScopeIndent.Incorrect)

5 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0 (PEAR.WhiteSpace.ScopeIndent.IncorrectExact)

5 | ERROR | [x] Multi-line function call not indented correctly; expected 4 spaces but found 0 | | (PEAR.Functions.FunctionCallSignature.Indent)

5 | ERROR | [x] Closing brace indented incorrectly; expected 4 spaces, found 0 (PEAR.WhiteSpace.ScopeClosingBrace.Indent)

Line 4 is the line where the return ""; is.

Unfortunately there's no setting to adjust for that case. It looks like a bug similar to https://youtrack.jetbrains.com/issue/WI-32914 , https://youtrack.jetbrains.com/issue/WI-25700 and https://youtrack.jetbrains.com/issue/WI-35221 . Feel free to add a comment with your example at eg https://youtrack.jetbrains.com/issue/WI-32914 or submit your own bug report

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM