Skip to content

[RFC] add prettier to eslint#8595

Merged
brad-decker merged 2 commits intodevelopfrom
prettier
Nov 2, 2020
Merged

[RFC] add prettier to eslint#8595
brad-decker merged 2 commits intodevelopfrom
prettier

Conversation

@brad-decker
Copy link
Copy Markdown
Contributor

@brad-decker brad-decker commented May 14, 2020

rationale

Eslint helps to make sure that everyone follows convention, but it doesn't take an opinionated approach to do so. Prettier has some stringent rules that they are rather inflexible on, but in my experience, it results in code formatting. that is universal and enforced on save. It, by default, attempts to keep code fitting within the average width of a half screen code window (80 col) but also maximizes the amount of code per line with the legibility as its primary concern.

The following PR has been split up into commits to make the diff manageable. Looking for feedback on how we can modify this setup to meet the needs of the entire team.

Link to .prettierrc.yml in feature branch: https://github.com/MetaMask/metamask-extension/blob/prettier/.prettierrc.yml

@rekmarks pointed out in slack the changes to the eslint config, copy pasted:

Disabled/attenuated:
indent
no-mixed-operators
no-confusing-arrow
react/jsx-closing-tag-location
react/jsx-wrap-multilines
Added:
react/self-closing-comp

NEW RULE UPDATES AFTER REBASE
disabled: wrap-regex
attenuated: lines-around-comment (prettier has some rules around this that conflict with the default eslint rule config)

Strategy for merging
Once we all agree on the changes and the settings, I can split this into multiple PRs using the following strategy:

For the first PR add prettier, eslint-prettier plugin, and update rules, use overrides by folder path to disable the prettier rules, and revert the changes to the eslint rules that were required to the code. So this should result in only .eslintignore, .eslintrc, package.json and yarn.lock changing.

I can then have successive PRs for each subpath of the application so that the changes can be reviewed in chunks and if we find anything I can pause the progress of merging PRs, fix the eslint config and update any issues resulting from that in previously merged work.

The final PR would remove the overrides altogether.

I think there would be additional steps to lift this configuration to the eslint-config package and distribute prettier with it, then we'd need to gradually adopt it in all of the other repositories. If that's a thing we want to do after using it in extension codebase.

@brad-decker brad-decker requested a review from kumavis as a code owner May 14, 2020 21:37
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [5d223ea]
Page Load Metrics (576 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298236115
domContentLoaded3276885749445
load3296895769445
domInteractive3276875749445

@MetaMask MetaMask deleted a comment from brad-decker May 14, 2020
@MetaMask MetaMask deleted a comment from brad-decker May 14, 2020
@brad-decker
Copy link
Copy Markdown
Contributor Author

@whymarrh this was opened while you were out, I got some initial responses in slack about some of the changes -- would love to hear your thoughts if you get time between fires/tasks.

@whymarrh
Copy link
Copy Markdown
Contributor

We should revisit this once #8982 is completed!

@brad-decker
Copy link
Copy Markdown
Contributor Author

@Gudahtt @whymarrh @rekmarks this has been updated... I actually did the work in a new branch off master then cherry picked the commit into this branch so it's worth looking again at changes. In addition to the rule changes mentioned in the original message, i had to also disable wrap-regex and modified lines-around-comment.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [23e5166]
Page Load Metrics (449 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint309140168
domContentLoaded28468344813464
load28568444913465
domInteractive28368244713464

@rekmarks
Copy link
Copy Markdown
Member

@brad-decker I unfortunately created a bunch of merge conflict for you with #9290.

Overall, I think this is a significant improvement. My one serious quibble is the addition of lines after comments and the removal of lines before comments. That feels backwards to me. Is that behavior not configurable?

@brad-decker
Copy link
Copy Markdown
Contributor Author

@rekmarks i'll play with it a little more to see if I can finagle it.

@brad-decker
Copy link
Copy Markdown
Contributor Author

@rekmarks so did some further digging.. the only place there is an actual issue with our default setting for lines-around-comments is here:

image

Prettier doesn't like a space after an object block declaration, it has nothing to do with the comment itself it just happens to conflict with the lines-around-comment rule. I don't think we really want a space before this comment in this case, so I think I have finagled the eslint rules now to very closely match our intention without interfering with prettiers automatic optimization of line breaks. I'll push up the new diff soon.

@brad-decker
Copy link
Copy Markdown
Contributor Author

Alright. scripts/background.js was one of the worst offenders of weird comment spacing. Now can confirm that no whitespace changes happened due to lines-around-comment. furthermore, this reduced the total number of added lines by ~1500 so, thanks for pushing on this @rekmarks

@rekmarks
Copy link
Copy Markdown
Member

nit: some of the files in send-eth-with-private-key-test disable eslint inline. Let's remove the inline disables and keep the .eslintignore addition.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [9476507]
Page Load Metrics (406 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint2991442010
domContentLoaded26762840411656
load26963040611656
domInteractive26762840411656

Comment on lines 6 to 15
const directionTargetGenerator = ({ top, left, height, width }) => {
const horizontalMiddle = left + (width / 2)
const verticalMiddle = top + (height / 2)
const horizontalMiddle = left + width / 2
const verticalMiddle = top + height / 2
return {
up: { x: horizontalMiddle, y: top - height },
down: { x: horizontalMiddle, y: top + (height * 2) },
down: { x: horizontalMiddle, y: top + height * 2 },
left: { x: left - width, y: verticalMiddle },
right: { x: left + (width * 2), y: verticalMiddle },
right: { x: left + width * 2, y: verticalMiddle },
middle: { x: horizontalMiddle, y: verticalMiddle },
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting to bookmark multiplication/division parenthesis example.

@whymarrh
Copy link
Copy Markdown
Contributor

I've created a tracking issue for v4 of our ESLint config: MetaMask/eslint-config#67

We should be able to put most of the config changes into that so that v4 allows us to standardize prettier across all of the repos.

@whymarrh
Copy link
Copy Markdown
Contributor

whymarrh commented Sep 1, 2020

I remember seeing a PR made to prettier itself—are we waiting on that to update this? (No rush, just tryna understand.)

@brad-decker
Copy link
Copy Markdown
Contributor Author

@whymarrh I can champion the PR and try and get some people to review it but ultimately when or if that merges is out of our control. My personal, selfish, preference would be to accept the unfortunate change to no-mixed-operators as bookmarked by @rekmarks for now until such a time as I am able to get that PR over the finish line.

I don't have a preference for order of operations here in term of what gets merged where first, just want to make sure I'm doing everything I need to do to progress this PR the way the team feels is the most comfortable.

@brad-decker
Copy link
Copy Markdown
Contributor Author

Also, for reference, this is the PR: prettier/prettier#9026

@brad-decker
Copy link
Copy Markdown
Contributor Author

🎉 rebased.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [5bdc5ec]
Page Load Metrics (388 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint29423442
domContentLoaded29059938610350
load29259938810350
domInteractive29059838610350

@brad-decker
Copy link
Copy Markdown
Contributor Author

🎉 and again. I can do this all day, folks. 💻 ☕

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [30d94db]
Page Load Metrics (563 ± 114 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaintNaNNaNNaNNaNNaN
domContentLoaded3671114561236114
load3691126563238114
domInteractive3671113561236114

@danjm danjm added this to the v8.1.next? milestone Nov 2, 2020
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [55ad3eb]
Page Load Metrics (524 ± 122 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28124482211
domContentLoaded2371132522254122
load2391134524254122
domInteractive2371132522254122

@darkwing
Copy link
Copy Markdown
Contributor

darkwing commented Nov 2, 2020

Config looks good to me!

.eslintrc.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an explanation somewhere for why these three rules were disabled? 🤔

.prettierrc.yml Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should enable semicolons here or in a follow-up. Our TypeScript eslint config demands it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up, please 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, okay, fine!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [eadbf30]
Page Load Metrics (390 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30503552
domContentLoaded24365538914770
load24465639014770
domInteractive24265438914770

@brad-decker brad-decker force-pushed the prettier branch 2 times, most recently from b3b9b0f to 5cc0bff Compare November 2, 2020 23:00
Copy link
Copy Markdown
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this merged before anything else happens!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [843eebd]
Page Load Metrics (411 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint2911140199
domContentLoaded23868440913465
load23968541113465
domInteractive23768340913465

@brad-decker brad-decker merged commit 2ebf875 into develop Nov 2, 2020
@brad-decker brad-decker deleted the prettier branch November 2, 2020 23:41
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants