prettier / prettier/plugin-pug

Bug: Trailing space incorrect behavior

Open
#524 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
208
Forks
49
Avg merge
4h 26m
Merged PRs (30d)
8

Description

Plugin Version

3.2.0

Prettier Version

3.3.3

Which frameworks are affected?
  • none
  • vue
  • angular
  • svelte
Node Version

21.7.2

Which operating systems have you used?
  • Linux
  • macOS
  • Windows
Prettier config
export default {
  plugins: ["@prettier/plugin-pug"],

  htmlWhitespaceSensitivity: "css",
  printWidth: 80,
  arrowParens: "avoid",
  bracketSameLine: false,
  semi: true,
  tabWidth: 2,
  useTabs: false,
  endOfLine: "auto",
  trailingComma: "es5",
  vueIndentScriptAndStyle: false,

  pugAttributeSeparator: "as-needed",
  pugFramework: "vue",
};
Input
h2 Link: 
  a(href="") Click

note trailing space "Link: "

Output or Error
h2 Link:
  |
  a(href="") Click

note trailing space is removed "Link:" and pipe doesn't have it either!

Expected Output
h2 Link:
  | 
  a(href="") Click

//- or perhaps 
h2
  | Link:
  |
  a(href=“”) Click

note trailing space after pipe "| " - the intended behavior

OR

Probably better move the text into child pipe and insert an extra pipe for that space

Additional Context

Prettier alters the result of the template which is not intended. Please look at https://pugjs.org/language/plain-text.html#whitespace-control

Also it doesn't respect htmlWhitespaceSensitivity: "strict" option and still removes any extra whitespace

Contributor guide

Open the contributing guide

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. Reproduce the Pug input with the listed plugin, Prettier, Vue, Node, and Windows setup, then trace the plugin’s plain-text and whitespace-control handling. Done means the trailing space is preserved according to the selected expected behavior and htmlWhitespaceSensitivity: "strict" is respected, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, pug, typescript
Domain
frontend, tooling, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.