prettier / prettier/plugin-xml

Bug: Double Apostrophe in <value> URI Formatting Issue

Open
#838 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
278
Forks
46
Avg merge
1m
Merged PRs (30d)
13

Description

Description:
I encountered a problem with the @prettier/plugin-xml plugin. When an XML file contains the text:

<value>&apos;&apos;</value>

Image

Prettier rewrites it as:

<value>
    &apos; &apos;
</value>

Image

This formatting adds an unwanted space between the apostrophes, which disrupts the appearance of our system.

Steps to Reproduce:

  1. Create an XML file with the following content:
    <root>
        <value>&apos;&apos;</value>
    </root>
    
  2. Run Prettier with the @prettier/plugin-xml plugin.
  3. Observe the formatted output.

Expected Behavior:
The content of the <value> tag should remain <value>&apos;&apos;</value> without adding spaces.

Actual Behavior:
The content of the <value> tag is rewritten as:

<value>
    &apos; &apos;
</value>

Additional Information:
In other cases, when there is only one apostrophe, Prettier formats correctly by keeping the line together:

<values>
    <field>ITA_IFM_ActivityDescription__c</field>
    <value xsi:type="xsd:string">MEDIA COMPLESSITA&apos;</value>
</values>

This leads us to believe it is a minor bug. Could you please provide feedback?

Prettier Configuration:

{
    "plugins": ["prettier-plugin-apex", "@prettier/plugin-xml"],
    "printWidth": 600,
    "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"}
        },
        {
            "files": "**/aura/**/*.{auradoc,design,app}",
            "options": {"parser": "angular"}
        },
        {
            "files": "**/*.xml",
            "options": {
                "parser": "xml",
                "useTabs": false,
                "tabWidth": 4,
                "xmlWhitespaceSensitivity": "preserve",
                "embeddedLanguageFormatting": "off",
                "xmlSelfClosingSpace": false
            }
        }
    ]
}

and this is our package.json

{
  "name": "***",
  "version": "1.0.0",
  "author": "***",
  "devDependencies": {
    "@prettier/plugin-xml": "^3.4.1",
    "prettier": "^3.4.2",
    "prettier-plugin-apex": "^2.2.2"
  },
  "repository": {
    "type": "****",
    "url": "****"
  },
  "scripts": {
    "prettier": "prettier"
  },
  "dependencies": {
    "sfdx-plugin-source-read": "^1.4.0"
  }
}

Thanks in advice, i'm here if you need anything else 😊

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the issue. Start by reproducing the XML example with Prettier and @prettier/plugin-xml, then locate the XML formatter and its existing regression tests. Done means formatting adjacent ' entities without inserting a space while preserving the reported behavior for other XML text.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.