Use Prettier for formatting JavaScript in Calendar
Categories
(Calendar :: General, task, P3)
Tracking
(Not tracked)
People
(Reporter: pmorris, Assigned: pmorris)
References
Details
Attachments
(7 files, 14 obsolete files)
1.38 KB,
patch
|
Details | Diff | Splinter Review | |
3.93 KB,
patch
|
Details | Diff | Splinter Review | |
6.91 MB,
patch
|
Details | Diff | Splinter Review | |
9.01 KB,
patch
|
Details | Diff | Splinter Review | |
1.32 KB,
patch
|
Details | Diff | Splinter Review | |
23.56 KB,
patch
|
Details | Diff | Splinter Review | |
25.10 KB,
patch
|
Details | Diff | Splinter Review |
An incremental step along the path of bug 1572047. Splitting out the calendar part as a separate effort. There's some calendar-specific discussion already on bug 1572047. The most relevant bits:
- Drop or turn off some eslint rules (generator-star-spacing, quote-props, object-curly-newline) that conflict with Prettier. Just use the Prettier defaults for these like m-c does.
- Use 2 space indent for calendar (per bug 1530221).
- Use a .prettierrc file for calendar-specific Prettier settings (e.g. line width).
Comment 1•5 years ago
|
||
https://hg.mozilla.org/try-comm-central/rev/996e7b3fa824d6b30d195dcedbc0e1bf4b679371#l1.12
isn't right.
That should be: for (let i = exdates.value.length - 1; i >- 0; i -= 1) {
- or i--.
for (let i = 10; i--;) { console.log(${i}\n
); } prints 9 to 0.
Comment 2•5 years ago
|
||
I guess, for (let i = 10; i--;)
check the look condition before it decrements, so it checks 10 down to 1 and runs with 9 to 0. --i
would give a different result. Tricky, huh?
Assignee | ||
Comment 3•5 years ago
•
|
||
Thanks Jorg for catching that. I did i > 0
when I should have done i >= 0
. Fixed in patches I'm about to upload. I'll be more careful with these atypical for loops. That tricky thing where --i
is not the same as i--
is why D. Crockford recommends always just using i -= 1
. Avoid the footguns. Maybe that's what threw me.
Assignee | ||
Comment 4•5 years ago
|
||
0 of 6: First apply this patch:
https://bug1573670.bmoattachments.org/attachment.cgi?id=9088722
from bug 1573670.
1 of 6: Then apply the patch I'm attaching here which turns on Prettier but keeps it from doing anything by ignoring all directories, etc.
Assignee | ||
Comment 5•5 years ago
|
||
2 of 6. Do settings before reformatting.
Assignee | ||
Comment 6•5 years ago
|
||
3 of 6: The big automatic reformatting pass. Details from the commit message:
These changes were achieved by:
(1) Using eslint to re-indent calendar code with 2 space
indent instead of 4.
Done by temporarily adding the following rule to the
calendar/.eslintrc.js file:
"indent-legacy": [2, 2, { SwitchCase: 1, }],
Then temporarily turning off Prettier by adding to that
file the rule:
"prettier/prettier": "off",
Then running |mach eslint calendar/ --fix|
(2) Reformatting the calendar code using Prettier.
Done by removing those two temporary additions from the
calendar/.eslintrc.js file and running
|mach eslint calendar/ --fix|.
Assignee | ||
Comment 7•5 years ago
|
||
4 of 6: This and the following patches fix some linting errors left after auto-formatting. This one moves existing "eslint-disable-" comments so they still work.
Assignee | ||
Comment 8•5 years ago
|
||
5 of 6: Fix an atypical for loop that Prettier didn't like.
Assignee | ||
Comment 9•5 years ago
|
||
6 of 6: Fix "no-useless-concat" eslint errors. Where the strings were separated on purpose for readability I usually kept them separate and added 'eslint-disable-' comments.
Comment 10•5 years ago
|
||
Comment 11•5 years ago
|
||
Comment 12•5 years ago
|
||
Comment 13•5 years ago
|
||
Comment 14•5 years ago
|
||
Comment 15•5 years ago
|
||
Assignee | ||
Comment 16•5 years ago
|
||
Thanks for the review. Here's the try run: https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=d3e70e5eb53ed2e356a5b0b35677bb97080fe86d
Assignee | ||
Comment 17•5 years ago
|
||
1 of 7
Assignee | ||
Comment 18•5 years ago
|
||
Assignee | ||
Comment 19•5 years ago
|
||
2 of 7
This is the same setting as before. 2 is error and all is the default.
I changed it back to 2 to minimize changes. (Although FWIW I find ["error", "all"] more easily comprehensible).
Assignee | ||
Comment 21•5 years ago
|
||
4 of 7
(In reply to Geoff Lankow (:darktrojan) from comment #12)
upgrade.v2 = upgrade.v1 = function(db, version) {
Let's just put db in the list of acceptable identifiers.
It was actually the .v1 and .v2 that were causing the linting error here. So I've left in the escape hatch comments for those.
Assignee | ||
Comment 23•5 years ago
•
|
||
6 of 7
Just turn it off for the whole file, this is a mess.
Done.
Assignee | ||
Comment 24•5 years ago
|
||
7 of 7 This patch addresses some ugly results of the auto-formatting. I'm no expert in SQL syntax, but I tried to follow the previous formatting. This often involved a // prettier-ignore
comment.
If a long multi-line string concatenation is a function argument, prettier wants to indent the lines after the first one to indicate that they are all part of the same function argument. But that gets in the way of being able to indent those following SQL norms.
Assignee | ||
Comment 25•5 years ago
|
||
Comment 26•5 years ago
|
||
Comment 27•5 years ago
|
||
Assignee | ||
Comment 32•5 years ago
|
||
Rebased.
Assignee | ||
Updated•5 years ago
|
Comment 35•5 years ago
|
||
Comment 36•5 years ago
|
||
Personally, I'd write it like this:
executeSimpleSQL(db, "UPDATE cal_recurrence SET tmp_date_tz = " +
"(SELECT e.flags FROM cal_events AS e " +
" WHERE e.id = cal_recurrence.item_id " +
" AND e.cal_id = cal_recurrence.cal_id " +
" UNION SELECT t.flags FROM cal_todos AS t " +
" WHERE t.id = cal_recurrence.item_id " +
" AND t.cal_id = cal_recurrence.cal_id)");
Assignee | ||
Comment 37•5 years ago
|
||
Revised to follow most of Jorgk's nit suggestion for indenting that SQL string in calStorageUpgrade.jsm, but with some adjustments to match similar examples in the file (e.g. the use of // prettier-ignore
).
Thanks for the timely reviews.
Assignee | ||
Updated•5 years ago
|
Comment 38•5 years ago
|
||
I'll land it when get home in a few hours.
Comment 39•5 years ago
|
||
Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/790fe3dbbfe7
Turn on Prettier but ignore all directories. r=darktrojan
https://hg.mozilla.org/comm-central/rev/22c568242aac
Adjust eslint and prettier config for reformatting. r=darktrojan
https://hg.mozilla.org/comm-central/rev/53a946e22342
Reformat calendar code with eslint and Prettier. r=darktrojan
https://hg.mozilla.org/comm-central/rev/22388fb0b676
Reposition 'eslint-disable-' comments so they work. r=darktrojan
https://hg.mozilla.org/comm-central/rev/91339a81c040
Fix 'no-useless-concat' eslint errors. r=darktrojan
https://hg.mozilla.org/comm-central/rev/ba6c06d9ea3a
Improve some unfortunate auto-formatting. r=darktrojan
https://hg.mozilla.org/comm-central/rev/8e5b49be96e3
Edit a for loop to satisfy Prettier. r=darktrojan
Updated•5 years ago
|
Description
•