K-Phoen / backstage-plugin-confluence

Confluence plugins for backstage
MIT License
58 stars 15 forks source link

Enforce Prettier Format; Format All #181

Open rmartine-ias opened 1 year ago

rmartine-ias commented 1 year ago

When pulling in a few patches (first, second), I was encountering merge conflicts because both do significant auto-formatting. This patch makes a few changes:

  1. Adds installing pre-commit hooks to the README, so everyone should have consistent formatting (1 formats to removing spaces in import {Thing} from package, which having the pre-commit hooks installed would fix)
  2. Enforces prettier code style in CI, by adding a yarn lint:prettier target and running it concurrently with yarn lint:all
  3. Fixes existing non-compliant code by running a full pass of prettier --ignore-path .gitignore --write .
  4. Adds YAML files to lint-staged config

Together, this should make sure future patches are much smaller.

I chose to use --ignore-path to set the .gitignore as the .prettierignore. This is a tradeoff. Editors are not aware of this option, as it is set in the package.json scripts and not in the prettier config (https://github.com/prettier/prettier/issues/8192). Since Prettier 3 is not released, stable Prettier can't have multiple ignore paths (https://github.com/prettier/prettier/pull/14332). Since there is no .prettierignore in this project, I figured having just the one set to .gitignore should be fine.

(The alternative, which we do, is duplicating all of .gitignore in .prettierignore, and then having additional things that we want checked into git but not linted also specified in .prettierignore. This is very annoying to me, and I hope https://github.com/prettier/prettier/issues/8192 is done so we can have .gitignore and a non-duplicated .prettierignore set as ignore files in config and auto-picked up by editors and CLI prettier.)

The only significant changes made are in README.md and package.json -- everything else is formatting, and isolated to a formatting commit.