Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect indent when methods are chained to inline new instance #435

Open
paustint opened this issue Oct 29, 2021 · 3 comments
Open

Incorrect indent when methods are chained to inline new instance #435

paustint opened this issue Oct 29, 2021 · 3 comments

Comments

@paustint
Copy link

paustint commented Oct 29, 2021

Sorry for the cryptic title!

Everything is indented as if the new keyword does not exist.

# Prettier options (if any):
{
  "trailingComma": "none",
  "apexInsertFinalNewline": false,
  "singleQuote": true,
  "printWidth": 140,
  "overrides": [
    {
      "files": "**/classes/**/*.cls",
      "options": { "tabWidth": 4 }
    },
    {
      "files": "**/lwc/**/*.html",
      "options": { "parser": "lwc", "tabWidth": 4 }
    },
    {
      "files": "*.{cmp,page,component}",
      "options": { "parser": "html", "tabWidth": 4 }
    }
  ]
}

Input:

new Flow.Interview.Termination_Handle_Legal_Comments_and_Chatter_Posts(new Map<String, Object>{ 'varCaseId' => currCase.Id, 'varAccountId' => currCase.AccountId, 'varType' => chatterType }).start();

Actual output:

new Flow.Interview.Termination_Handle_Legal_Comments_and_Chatter_Posts(
        new Map<String, Object>{ 'varCaseId' => currCase.Id, 'varAccountId' => currCase.AccountId, 'varType' => chatterType }
    )
    .start();

Additional example

new Flow.Interview.Termination_Handle_Legal_Comments_and_Chatter_Posts(
        new Map<String, Object>{
            'varCaseId' => currCase.Id,
            'varAccountId' => currCase.AccountId,
            'varSalesRep' => currCase.Sales_Rep__c,
            'varType' => chatterType
        }
    )
    .start();

Expected output:

// prettier-ignore
new Flow.Interview.Termination_Handle_Legal_Comments_and_Chatter_Posts(
        new Map<String, Object>{ 'varCaseId' => currCase.Id, 'varAccountId' => currCase.AccountId, 'varType' => chatterType }
)
.start();

Additional information (please fill this out):

  • OS: OSX
  • Version: "prettier-plugin-apex": "^1.10.0"
@dangmai
Copy link
Owner

dangmai commented Oct 29, 2021

Thanks for the issue! This is indeed a difficult one to write a title for 🤣 I'll take a look at this soon-ish, right now I'm rewriting this library in TypeScript so formatting changes need to take a bit of a back seat, but hopefully that won't take too long.

@paustint
Copy link
Author

@dangmai - No problem! I just wanted to let you know about the bug with no expectations beyond that. You are an excellent maintainer and THANK YOU for this library and the ongoing work you put into it.

As for Typescript, that is awesome! The only JavaScript I write these days is for Salesforce, but aside from that I am 100% sold on using TypeScript for everything because it is so amazing. 😍

@dangmai
Copy link
Owner

dangmai commented May 13, 2022

Looking at this issue now, there's actually some complexity to it. Your expected output has .start() on the same level as the parent expression, which makes it difficult to understand that it's a child expression. I would actually rather go with how Prettier upstream (for JS) handles this kind of complexity, example here.

Basically, if there's only 1 method call, it's always attached directly to the parent expression with no line break, no matter how long it is. If there are more than 1, new lines with another level of indentation is added.

Going down this route will also make it less of a cognitive switch when looking at formatted JS code and formatted Apex code, because they will have the same formatting behavior.

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

No branches or pull requests

2 participants