-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[test] Introduce prettier into CI pipeline #12564
Conversation
We do, we have an eslint plugin for it. Now, TypeScript handling is different. We don't run eslint on TypeScript, but I'm wondering if we shouldn't. |
So how do I trigger this? `yarn test` did not throw which does run lint if
I remember correctly.
For typescript we should use tslint I think.
…On Fri, Aug 17, 2018, 19:34 Olivier Tassinari ***@***.***> wrote:
does not verify that contributors check their format.
We do, we have an eslint plugin for it. Now, TypeScript handling is
different. We don't run eslint on TypeScript, but I'm wondering if we
shouldn't.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12564 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALuPzwyrgXOy_pDuFY4uKsgJFjdNbEMhks5uRv6XgaJpZM4WBwp2>
.
|
It's definitely broken: https://discuss.circleci.com/t/saving-cache-stopped-working-warning-skipping-this-step-disabled-in-configuration/24423.
|
# Files changed on this branch | ||
CHANGED_FILES=$(git diff --name-only master...) | ||
# Files that should have been formatted while working on this branch | ||
FORMATTED_FILES=$(yarn --silent prettier:files | grep "$CHANGED_FILES") |
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.
Do we run prettier twice here? Would it be faster to run it once and to execute git diff --exit-code
?
Also, I think that we scope the new check to the TypeScript files :).
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.
find
always did pipe *.d.ts
and *.tsx
to the prettier
script. eslint
only processes jsx?
files though as far as I know.
I was never really a fan of eslint-plugin-prettier
. Mostly this comes down to personal preference but also some actual minor issues: eslint
has no parser for ts
files which makes eslint --fix
with eslint-plugin-prettier
useless for ts files. eslint-plugin-prettier
allows prettier
configuration with .eslintrc
which is ignored by ide plugins.
prettier:files
is just a helper method at the moment which lists files that should be formatted. It is not actually running prettier --write
.
prettier --write
should never be used in a CI environment. That's the hole purpose of --list-different
. Combine --write
with git diff
while reducing I/O operations.
It was intended that the new check enforces a consistent code style across ts and js file. Just like the existing prettier
scripts already formats tsx?
files.
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.
Now I understood what you mean. Since we run prettier via eslint
we would run it here again on all jsx?
files. I removed eslint-plugin-prettier
to removed this redundancy.
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.
eslint --fix
I never used that. I have never been satisfied with the output.
I was never really a fan of eslint-plugin-prettier
Most people configure their editor to run eslint. The advantage of this plugin is that you know up front that you need to run prettier, it's just like another eslint rule. At least, it's my workflow. I don't automatically run prettier on save. This data is interesting: https://npm-stat.com/charts.html?package=eslint-plugin-prettier&package=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.
Well prettier supports more than jsx?
while eslint only runs on jsx?
. Typescript support might explain some difference.
I didn't think about editor integration though and while I also don't use formatOnSave I do frequently press the format hotkey.
fb4ac72
to
55f217f
Compare
A file can be formatted without knowledge about other files. For this reason we only check the format for files which were changed compared to master. A broken format that was merged into master will not be picked up by CI until the file was changed again. This can be a good thing since this will not trigger CI errors in unrelated builds and since we are only talking about code style this a manageable tradeoff especially because formatting can be very expensive.
55f217f
to
69e63ed
Compare
@eps1lon Ok, let's try this workflow without |
It saves ~20s in the lint duration. |
I realize that this might be bad time since CircleCI is broken but I encountered various other problems while working on this so I wanted to get it out.
This package currently uses prettier to format its code but does not verify that contributors check their format. With this change the CI pipeline will check changed files for their format.
While
find
enables piping togrep
to check for changed files only it does not match its behavior toeslint
andprettier
.Prettier
has its own--ignore-path
argument andprettier:files
could be removed in favor ofprettier --ignore-path .eslintignore "**/*:{d.ts,js,tsx}"
.However this caused performance degradation caused by prettier/prettier#4989. Timing both variants reveals little over 2x the runtime of the original command:
Another issue is that the checked files changed:
Since using
--ignore-path
considers the same files aseslint
we should switch at some point to--ignore-path
.I have another iteration that uses
--ignore-path
at least in ci since the slower runtime is negligible since we only run on the changed files.For an explanation as to why
prettier
only runs on changed files and not on all see the commit message of 7d42ca0.