oca-addons-repo-template icon indicating copy to clipboard operation
oca-addons-repo-template copied to clipboard

Improve xml prettyfier

Open sbidoul opened this issue 1 year ago • 3 comments

prettier's xml pluggin now supports a much better XML autoformatting mode. See https://github.com/prettier/plugin-xml/issues/138#issuecomment-724547415.

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:
          - "[email protected]"
          - "@prettier/[email protected]"

sbidoul avatar Nov 04 '23 09:11 sbidoul

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?

yajo avatar Nov 06 '23 09:11 yajo

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

sbidoul avatar Nov 06 '23 23:11 sbidoul

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[bot] avatar May 19 '24 12:05 github-actions[bot]