- Notifications
You must be signed in to change notification settings - Fork 23
Add prettier support #447
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
Add prettier support #447
Conversation
| t.todo('cases', async t => { | ||
| const execRepo = (cmd, opts) => | ||
| execSync(cmd, { cwd: REPO_DIR, encoding: 'utf-8', ...opts }).trim() | ||
| const execRepo = (cmd, opts) => execSync(cmd, { cwd: REPO_DIR, encoding: 'utf-8', ...opts }).trim() |
Check warning
Code scanning / CodeQL
Shell command built from environment values
| This may warrant |
01438fb to ca038fe Compare Co-authored-by: Julian Møller Ellehauge <git@jumoel.com>
Co-authored-by: Julian Møller Ellehauge <git@jumoel.com>
jumoel left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 💅
Ensure that this isn't squash-merged, or the rev in .git-blame-ignore-revs will be wrong.
| Will rebase-merge preserve the commit sha? |
| 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. |
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. |
| @wraithgar Good call. Just dropped the |
| "lint": "{{ localNpmPath }} run eslint {{~#if prettier}} && {{ localNpmPath }} run prettier -- --check{{/if}}", | ||
| "lintfix": "{{ localNpmPath }} run eslint -- --fix {{~#if prettier}} && {{ localNpmPath }} run prettier -- --write{{/if}}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we've adopted prettier in most repos, we may to separate linting and styling.
We could add dedicated style and stylefix scripts, and have posttest run {{ localNpmPath }} run lint && {{ localNpmPath }} run style
| extends: [ | ||
| '@npmcli', | ||
| ...localConfigs, | ||
| {{#if prettier}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukekarrys @jumoel Is there a reason we're making prettier usage configurable? Are there repos we know we don't want to use prettier in? Do we want a gradual or coordinated rollout of prettier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I recall, it took some semi-manual effort to roll out prettier to a new repo due to the .git-blame-ignore-revs file and getting the right SHA after merging the PR. So it was made configurable with the goal of turning it on everywhere and then changing the default after that.
🤖 I have created a release *beep* *boop* --- ## [4.23.0](v4.22.0...v4.23.0) (2024-06-27) ### Features * [`60ee94f`](60ee94f) [#447](#447) add prettier support (@lukekarrys, @jumoel) ### Bug Fixes * [`b35bca5`](b35bca5) [#447](#447) run prettier (@lukekarrys) * [`8aef509`](8aef509) [#446](#446) dont conclude checks if they were never set (#446) (@lukekarrys) * [`9440c4f`](9440c4f) [#444](#444) pass releases to publish check (#444) (@lukekarrys) ### Dependencies * [`8252fb2`](8252fb2) [#452](#452) bump release-please from 16.10.2 to 16.12.0 (#452) (@dependabot[bot], @wraithgar) ### Chores * [`b07d17a`](b07d17a) [#448](#448) add .git-blame-ignore-revs for initial prettier (#448) (@lukekarrys) * [`210247e`](210247e) [#447](#447) add prettier:true to template-oss config (@lukekarrys, @jumoel) * [`1a073e4`](1a073e4) [#443](#443) bump @npmcli/template-oss to 4.22.0 (@lukekarrys) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR contains 4 commits:
prettiersupport to@npmcli/template-ossprettieron this repo by settingtemplateOSS.prettier: true770a10c add aDropped from this PR since SHAs won't match after rebase.git-blame-ignore-revsfile referencing the commit from item 3Once this lands, enabling
prettieron 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
lintandlintfixrun-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
lintandlintfixscripts we currently have also be responsible for runningprettier. 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 botheslintandprettier.We also explored using a combination of
postlintandpostlintfixfor this, but thenprettier --check(vialint->postlint) would get run beforeprettier --writewhich would defeat the purpose ofprettier --write.Other notable items are:
@github/prettier-configexcept for changingbracketSpacing: trueto match how we previously had eslint setup. This also setsarrowParens: "avoid"which seems like something we've never standardized on previously, so we opted to leave it as configured in the@githubconfig.eslint-config-prettierto overwrite all the eslint formatting rules we use. Alternatively we could remove them all from@npmcli/eslint-configon a semver major of that. I think it's easier to get more things onprettierbefore a decision on that is made.