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

Improve xml prettyfier #224

Open
sbidoul opened this issue Nov 4, 2023 · 3 comments
Open

Improve xml prettyfier #224

sbidoul opened this issue Nov 4, 2023 · 3 comments
Labels
enhancement New feature or request no stale Use this label to prevent the automated stale action from closing this PR/Issue.

Comments

@sbidoul
Copy link
Member

sbidoul commented Nov 4, 2023

prettier's xml pluggin now supports a much better XML autoformatting mode. See prettier/plugin-xml#138 (comment).

Below are my findings on how to make it work.

You need a .prettierrc.cjs instead of .prettierrc.yml, so prettier can load the plugin even when run from pre-commit:

/** @type {import('prettier').Config} */
const config = {
  plugins: [require.resolve("@prettier/plugin-xml")],
  bracketSpacing: false,
  printWidth: 88,
  proseWrap: "always",
  semi: true,
  trailingComma: "es5",
  xmlWhitespaceSensitivity: "preserve",
};

module.exports = config;

And the pre-commit config needs to be adapted like so:

  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v3.0.3
    hooks:
      - id: prettier
        name: prettier + plugin-xml
        additional_dependencies:
          - "prettier@3.0.3"
          - "@prettier/plugin-xml@3.2.2"
@sbidoul sbidoul added the enhancement New feature or request label Nov 4, 2023
@yajo
Copy link
Member

yajo commented Nov 6, 2023

You need a .prettierrc.cjs instead of .prettierrc.yml, so prettier can load the plugin even when run from pre-commit

Prettier was always able to load the XML plugin until now. Did something relevant change in that regard?

@sbidoul
Copy link
Member Author

sbidoul commented Nov 6, 2023

Apparently prettier 3 changed module discovery in a way that is incompatible with pre-commit. It's a rabbit hole and this approach is the best I could find

Copy link

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label May 19, 2024
@sbidoul sbidoul added no stale Use this label to prevent the automated stale action from closing this PR/Issue. and removed stale PR/Issue without recent activity, it'll be soon closed automatically. labels May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request no stale Use this label to prevent the automated stale action from closing this PR/Issue.
Projects
None yet
Development

No branches or pull requests

2 participants