question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prettier suddenly Does not format Visualforce .page files

See original GitHub issue

Summary

Does not format Visualforce .page files.

Steps To Reproduce:

  1. Create a Salesforce DX project in VS Code with the Salesforce Extension Pack installed.
  2. Follow the Prettier Code Formatter instructions.
  3. In Settings, set Editor: Default Formatter to Prettier.
  4. In Settings, check Editor:Format on Save.
  5. Create a Visualfoce page with the following code
<apex:page controller="myAccountController"  lightningStylesheets="true">
    <apex:form>
        <apex:pageBlock title="Edit Account">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{! Account.Name }" ignoreEditPermissionForRendering="true"/>

    <apex:inputField value="{! Account.Phone }" ignoreEditPermissionForRendering="true"/>
    <apex:inputField value="{! Account.Industry }" ignoreEditPermissionForRendering="true"/>
    <apex:inputField value="{! Account.AnnualRevenue }" ignoreEditPermissionForRendering="true"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton action="{! save }" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
        </apex:form>


</apex:page>
  1. Save the Visualforce .page file

Expected result

Prettier formats the document.

Actual result

Error shows at bottom of window, with message that Prettier cannot format the file.

Additional information

prettier visualforce

VS Code Version: Version: 1.57.1 (user setup)

SFDX CLI Version: sfdx-cli/7.107.0 win32-x64 node-v14.17.1

OS and version: OS: Windows_NT x64 10.0.19041

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
xyccommented, Jul 12, 2021

If you are using Prettier as the code formatter for visualforce, you should also add the following glob pattern to your .vscode/settings.json file.

"prettier.documentSelectors": ["*/.page"]

Otherwise, if you are using the formatter from visualforce language server, add the following setting to override the default formatter setting.

"[visualforce]": {
    "editor.defaultFormatter": "salesforce.salesforcedx-vscode-visualforce"
}
0reactions
jonny-hartecommented, Jul 13, 2021

Thanks @xyc the glob pattern didnt work but the below did.

"prettier.documentSelectors": ["**/*.{cmp,page,component}"],

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code Prettier plugin for Apex not formatting ...
Type 'Beautify File' in the search box and select it. Select 'HTML' from out of the three options which are getting populated.
Read more >
Why does Prettier not format code in VS Code? - Stack Overflow
Select File -> Preferences -> Settings ( Ctrl + comma ) and search form formatter; Set Prettiers as Default formatter. enter image ...
Read more >
Prettier for Apex Errors - Salesforce Developer Community
I'm new to Apex and programming in general, so wanted to use a code formatter to help me get used to formatting standards....
Read more >
Inconsistent Formatting between Prettier and Org · Issue #4162
Create an Aura/LWC. Prettier files. Commit to Repo. Deploy to Org. Retrieve from Org. Review source control panel in VSCode. Expected result. No...
Read more >
Prettier for SFDX: Format Apex and LWC
Add Prettier to your SFDX project and configure it for Apex, Visualforce and LWC. Automatically format your code on type and save.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found