dangmai / prettier-plugin-apex

Code formatter for the Apex Programming Language
https://apex.dangmai.net
MIT License
256 stars 45 forks source link

Feature Request - Trailing Newline Removal Option for LWC and AURA in prettier-plugin-apex #1166

Closed Alfystar closed 9 months ago

Alfystar commented 9 months ago

Dear @dangmai,

I hope this message finds you well. I am writing to request a new feature for the "prettier-plugin-apex" tool. Currently, the plugin efficiently handles the formatting of Apex classes. However, when it comes to Lightning Web Components (LWC) and Aura components, the absence of an option to remove the trailing newline poses challenges during the CI-CD process.

As you may be aware, Salesforce's retrieve operation does not include the trailing newline in the retrieved code. Consequently, this leads to an unnecessary diff, complicating the CI-CD workflow. Therefore, I kindly request the addition of an option within the plugin to enable the removal of the trailing newline from both Apex classes, Lightning Web Components, and Aura components.

Implementing this feature would significantly improve the alignment of the plugin with Salesforce development practices and enhance the overall experience for users engaged in continuous integration and continuous deployment processes.

Thank you for your time and consideration. I appreciate the effort you put into maintaining this valuable tool.

Best regards, Emanuele

Current .prettierrc configuration

{
    "plugins": ["prettier-plugin-apex"],
    "printWidth": 180,
    "singleQuote": true,
    "trailingComma": "all",
    "bracketSpacing": false,
    "useTabs": true,
    "bracketSameLine": true,
    "apexInsertFinalNewline": false,
    "overrides": [
        {
            "files": "*.{trigger,cls}",
            "options": {
                "parser": "apex"
            }
        },
        {
            "files": "*.{apex}",
            "options": {
                "parser": "apex-anonymous"
            }
        },
        {
            "files": "**/lwc/**/*.html",
            "options": {
                "parser": "lwc"
            }
        },
        {
            "files": "*.{cmp,page,component,evt}",
            "options": {
                "parser": "html",
                "trailingComma": "none"
            }
        },
        {
            "files": "**/aura/**/*.js",
            "options": {
                "trailingComma": "none"
            }
        }
    ]
}

Additional information:

aheber commented 9 months ago

@Alfystar I'm sure @dangmai will have some more insight but I thought it would be worth mentioning that this plugin ONLY reads and formats Apex code, not Javascript which is what Aura and LWC components are.

Prettier (without plugins) handles formatting Javascript itself and chooses to always add the newline.

Here is a thread from a couple years ago talking about it, specifically mentioning Salesforce files. https://github.com/prettier/prettier/issues/6360#issuecomment-686620417

That comment mentions you could look at hooking the CLI behavior to add it back on retrieve (I haven't done that and the CLI has been entirely rewritten since that comment was posted, the solution will probably be different)

dangmai commented 9 months ago

Thanks @aheber for answering the question, all you've mentioned are correct - I really don't have the ability to make this change because Aura/LWC is formatted by Prettier core. They've also made it pretty clear that it's not a change they're planning to implement unfortunately.

Alfystar commented 9 months ago

Ok I see, I was hoping we could do something here since LWC and AURA own salesforce, so I saw a connection to it.

I will have to do, as many have suggested, a posthumous truncation of correctly formatted files within the CI/CD stream.

THANK YOU ANYWAY, you did a fantastic job!