oca-addons-repo-template
oca-addons-repo-template copied to clipboard
Improve xml prettyfier
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]"
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?
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
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.