npm / template-oss

a template package for npm CLI team development
Other
26 stars 19 forks source link

Add prettier support #447

Closed lukekarrys closed 6 months ago

lukekarrys commented 6 months ago

This PR contains 4 commits:

  1. 9ca6167 adding prettier support to @npmcli/template-oss
  2. d020c1d enabling prettier on this repo by setting templateOSS.prettier: true
  3. 685dd64 running prettier to format this repo
  4. 770a10c add a .git-blame-ignore-revs file referencing the commit from item 3 Dropped from this PR since SHAs won't match after rebase

Once this lands, enabling prettier on another repo will involve updating to the new version of @npmcli/template-oss, and then running steps 2-4 which should be handled by a new script in https://github.com/npm/stafftools (or another tool).


The most important part of item 1 is the implementation of the lint and lintfix run-scripts. They now look like this:

{
    "lint": "npm run eslint && npm run prettier -- --check",
    "lintfix": "npm run eslint -- --fix && npm run prettier -- --write"
}

The goal here was to have the same lint and lintfix scripts we currently have also be responsible for running prettier. The tradeoff is that if linting fails, then formatting via prettier doesn't run. I think this is ok since it allows for a single script to handle both eslint and prettier.

We also explored using a combination of postlint and postlintfix for this, but then prettier --check (via lint->postlint) would get run before prettier --write which would defeat the purpose of prettier --write.


Other notable items are:

wraithgar commented 6 months ago

This may warrant .git-blame-ignore-revs

wraithgar commented 6 months ago

Will rebase-merge preserve the commit sha?

lukekarrys commented 6 months ago

I checked on npm/cli for a recent multiple commit PR that was rebased and even a rebase merge will also change the sha.

For this PR I will probably land it, temporarily change branch protections, and then force push a new commit to main referencing the correct commit.

For other repos I think the prettier application and git-blame-ignore-revs creation will need to be multiple PRs.

wraithgar commented 6 months ago

For other repos I think the prettier application and git-blame-ignore-revs creation will need to be multiple PRs.

Let's practice it here then. Don't bother disabling the branch protections. Search for past "lint everything" commits to this repo, including the one from this PR, and make a new PR adding them. That way we can live the process we'll be using going forward.

lukekarrys commented 6 months ago

@wraithgar Good call. Just dropped the .git-blame-ignore-revs commit from the PR and will make a followup adding the SHA for the prettier formatting commit as well as any other lint commits I can find.

wraithgar commented 6 months ago

It seems appropriate that @jumoel or @reggi approve this.