-
Notifications
You must be signed in to change notification settings - Fork 377
Add tslint-plugin-prettier and apply code formatting #2810
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
Conversation
|
Hmm, |
|
PatternFly-React preview: https://patternfly-react-pr-2810.surge.sh |
|
Ok, this should be all set now. I ran |
boaz0
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.
🎊 🎉
898b126 to
43a4fd4
Compare
|
Rebased on master |
|
Let's try to do get this in post code-freeze next week after one final rebase. Things are a little hectic now. |
|
Fair enough 🙂 |
43a4fd4 to
51a85c0
Compare
|
(moved this comment to the bottom to track latest commits) |
|
Hmm.. @redallen I'm having trouble parsing the errors in the CircleCI log, do you know why this would be failing CI? I didn't make any different configuration changes compared to before the rebase. |
|
@mturley During Charts has been touched a lot lately, so I'd recheck the merge conflicts for that file. Worst case, checkout master's version and then relint the file. |
Hmm, that's what I did (I cherry-picked only the config changes and relinted the whole repo). I'll take a closer look at that file, thanks! |
| // Note: theme is required by voronoiContainerMixin, but @types/victory is missing a prop type | ||
| // @ts-ignore | ||
| return <VictoryVoronoiContainer className={chartClassName} labelComponent={chartLabelComponent} theme={theme} {...rest} />; | ||
| return ( |
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.
Ahh, @redallen it looks like it was this @ts-ignore not being applied anymore because the offending code was moved down a line by prettier. I'll add a prettier-ignore on the same line, and we might have to do that in the future where we need @ts-ignore on a long line.
It's weird that we can't just ts-ignore multiple lines... looks like an open issue: microsoft/TypeScript#19573
51a85c0 to
fb5072e
Compare
fb5072e to
e771fff
Compare
|
I rebased this on the latest master, and squashed it into 3 commits to make it easier to rebase in case we need to do so again:
|
e771fff to
4105d86
Compare
|
@dgutride do you think it would make sense to try and merge this (after a final rebase) immediately after this week's code freeze ends, to minimize conflicts with other PRs? It doesn't change our dist, but it touches a lot of files. |
redallen
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.
LGTM
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.
Not a fan of how Prettier reformats the code. Some code is less readable, IMO -- formatted for a reason. Although, the yarn lint:ts --fix is much needed. Those changes in chart changes look ok.
|
@dlabrecq what formatting opinions of Prettier do you dislike? We can reconfigure it: https://prettier.io/docs/en/options.html. I'm not really concerned about how the code is formatted as long as it's formatted consistently. Messy indentation was my main gripe. |
|
I do agree somewhat that Prettier tries too much to fit the most code into every line, but I think maybe that could be helped by lowering the print-width option. They actually recommend that you don't exceed 80 characters on that option (see the yellow box at the top of the options docs), and we have it set to 120. I would be open to shortening this to 80 or 100 (and then obviously there would be many lines which would end up longer than that). |
5891669 to
e201d19
Compare
|
@mturley I often use separate lines when I destructure multiple items or sometimes when importing long names, but that's just my preference to make things more readable. It's not a big deal, just not a fan. I am a big fan of running |
|
I agree actually, those sound like good reasons to disagree with Prettier. We could lower the print width to make that less of an issue, and in extreme cases we could use |
b9d71eb to
cccb4d7
Compare
|
@dlabrecq I'll bug you just one last time (I know you're not thinking of this as a big deal), but just for comparison's sake I made a few separate branches and ran the same process with the print-width set to 100 characters (mturley@c5fbfe4) and set to 80 characters (mturley@fc02c3b). The lower the print-width, the more readable a lot of code gets, but files end up larger in terms of lines of code. Do you have an opinion on whether either of these would be better than the 120-character width in this PR? |
dlabrecq
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.
Looks better. Still some odd indentations in some places, but not a deal breaker.
| ? height > defaultSize | ||
| ? value + (height - defaultSize) * scale | ||
| : value - (defaultSize - height) * scale | ||
| : width > defaultSize |
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.
This indentation looks much better compared to the others I noted
| | 'triangleUp' | ||
| | 'dash' | ||
| | 'threshold' | ||
| | Function; |
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.
Better...
| ? defaultPadding.top * 0.5 + (defaultPadding.bottom * 0.5 - defaultPadding.bottom) - 25 | ||
| : title | ||
| ? -defaultPadding.bottom + 60 | ||
| : -defaultPadding.bottom; |
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.
This indentation looks a little off?
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.
It looks like Prettier will indent a nested ternary if it is nested within the true-branch (foo ? bar ? 1 : 2 : 3) but not if it is trailing / nested in the false-branch (foo ? 1 : bar ? 2 : 3). This is a bit weird but seems reasonable to me... to be honest though, maybe we should avoid nested ternary expressions unless we use parentheses to make them more clear. Maybe that would help here.
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.
Looks like this is a subject of debate in Prettier: prettier/prettier#5814 (blog post explaining their decision to do it that way: https://prettier.io/blog/2018/11/07/1.15.0.html#flatten-else-branch-for-nested-ternaries-5039-by-suchipi-5272-by-duailibe-5333-by-ikatyang)
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.
Huh. Adding parens around the second expression there, Prettier removes them. Maybe that's a case where // prettier-ignore would be useful if we need an exception to make that code extra clear.
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.
I didn't realize // prettier-ignore was available. That could be quite useful for those couple of weird issues
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.
Agreed. You can even configure a .prettierignore file to ignore entire files/directories if necessary
cccb4d7 to
b1f6012
Compare
b1f6012 to
4e1b48c
Compare
|
Your changes have been released in:
Thanks for your contribution! 🎉 |

What:
Because we realized that some important code-formatting-related TSLint rules are broken, @redallen and I decided that it would be appropriate to add Prettier to our linter, and run it on existing code.
This PR:
tslint-plugin-prettierwhich runs Prettier as part of TSLint (currently these errors do not fail the CI checks, but eventually when other TSLint errors are resolved they probably should)tslint-config-prettierwhich was removed in Improve linting #2787, this disables TSLint rules which would conflict with Prettieryarn prettierscript which contributors can run to automatically format their codeyarn prettierandyarn lint:ts --fix. This cleans up all of our indentation issues and other small formatting gripes.Hopefully this will help to make our code a little more readable and consistent going forward!
cc @redallen
Closes #2362 (for real this time)