Skip to content
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 #7857

Merged
merged 1 commit into from
Mar 9, 2024
Merged

Add prettier #7857

merged 1 commit into from
Mar 9, 2024

Conversation

Minion3665
Copy link
Member

Prettier is a code formatter for javascript/typescript. It's relatively
common to see complaints about style in pull requests or inconsistent
style getting in to Collabora Online. Also, without a formatter it's
harder for editors to automatically format code in sensible and
consistent ways

Prettier doesn't have many options, but those which it does have I have
set to the closest values to current behavior (e.g. single quotes) in
order to minimize unnecessary changes. There'll still be a lot of
changes, but in my opinion this is preferable to no formatter as we only
pay the cost once but get benefits continuing on into the future

I have decided to format everything in a single commit, as it will make it easier to ignore in blames in the future and less annoying in the future. It's annoying now, and I'm sorry for that. When reviewing, you'll probably want to look at individual commits - I don't imagine the full diff view will be particularly helpful.

Copy link
Contributor

@eszkadev eszkadev left a comment

Choose a reason for hiding this comment

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

we can't do that big code refactor which will cause lots of conflicts when cherry-picking,

can we do this for new files only currently?

@mmeeks
Copy link
Contributor

mmeeks commented Dec 20, 2023

Great initiative - but of course the blames are also really useful for assigning blame ;-) Luckily we will be moving more code to typescript incrementally, so would love to see a consistent style at that stage as well as for new files =)

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from fea5caf to ed56851 Compare December 20, 2023 10:47
@Minion3665 Minion3665 changed the title Add prettier and format Add prettier Dec 20, 2023
@Minion3665
Copy link
Member Author

Minion3665 commented Dec 20, 2023

Thanks for the suggestions! I've added an ignore file containing everything that would be changed, I've opted to leave these 3 files (which already match the new formatting) out of the new ignore file

$ make prettier-write
browser/node_modules/.bin/prettier \
	--config browser/.prettierrc \
	--ignore-path browser/.prettierignore \
	--ignore-path browser/.beforeprettier \
	--write \
	browser/src browser/js browser/admin/src
browser/src/copyright.js 68ms (unchanged)
browser/src/Leaflet.js 14ms (unchanged)
browser/admin/src/Admin.js 8ms (unchanged)

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from ed56851 to 5f24ff2 Compare December 20, 2023 10:53
@Minion3665 Minion3665 requested a review from eszkadev December 20, 2023 10:57
@Minion3665
Copy link
Member Author

this still has a big problem: node versions... our CI is currently using an old version of node that isn't supported by prettier. I'm talking to people about how we can upgrade that, but one option could be to use a github workflow for this. It's not preferable because it'll waste CI time (see also: #7850) but it's something we could do more immediately... then again, I'm not sure how hard node will be to update

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch 2 times, most recently from cef19cd to 5f24ff2 Compare December 20, 2023 14:36
@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from 5f24ff2 to 081ee68 Compare January 17, 2024 13:46
@timar
Copy link
Member

timar commented Jan 23, 2024

I added Node v20 to the Tinderbox container, and I think I'll clone that for all CI for co-24.04 onwards.

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch 2 times, most recently from e604b6d to a668232 Compare January 29, 2024 09:48
@Minion3665
Copy link
Member Author

I added Node v20 to the Tinderbox container, and I think I'll clone that for all CI for co-24.04 onwards.

the build is still failing for the same issue - I'm not sure if it's added and only not being used? It may be worth checking if 24.04 CI shares the same issue and fixing it there if it does

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from a668232 to 7701b04 Compare February 28, 2024 12:33
@Minion3665 Minion3665 marked this pull request as ready for review February 28, 2024 12:44
@Minion3665 Minion3665 dismissed eszkadev’s stale review February 28, 2024 13:52

I've done the requested change

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch 2 times, most recently from 8a17cf3 to c390a59 Compare March 4, 2024 10:31
@mmeeks
Copy link
Contributor

mmeeks commented Mar 4, 2024

Seems reasonable to me =) But I'll leave to a JS person. Thanks Skyler.

Copy link
Contributor

@eszkadev eszkadev left a comment

Choose a reason for hiding this comment

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

Nice, but maybe let's wait for CI test (unit + cypress step) to be sure it will not fail all the builds

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from c390a59 to 9be8fc9 Compare March 5, 2024 10:21
@Minion3665 Minion3665 mentioned this pull request Mar 5, 2024
6 tasks
@Minion3665
Copy link
Member Author

Nice, but maybe let's wait for CI test (unit + cypress step) to be sure it will not fail all the builds

@eszkadev that makes sense, I've pulled the .editorconfig stuff into its own change so we can merge it first, as it doesn't have an effect on the build: #8455

@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch 5 times, most recently from a99bf60 to feaca43 Compare March 8, 2024 17:57
Prettier is a code formatter for javascript/typescript. It's relatively
common to see complaints about style in pull requests or inconsistent
style getting in to Collabora Online. Also, without a formatter it's
harder for editors to automatically format code in sensible and
consistent ways

Prettier doesn't have many options, but those which it does have I have
set to the closest values to current behavior (e.g. single quotes) in
order to minimize unnecessary changes

This commit doesn't format all existing files. Doing so would cause
blames, cherry-picks and diffs to become much less useful. Instead, we
use browser/.beforeprettier to list all files that would need to be
changed, and this file is ignored. You are encouraged but not required
to set your editor's equivalent of 'editor.formatOnSaveMode' to only
format changed lines

This commit also does format of docstatefunctions.js, previously it did
not in to check that an incorrectly-formatted file could fail CI. Now it
does to make sure that formatting fixes the issue. This file was chosen
because it is very new and very small.

Change-Id: Ie6067f34aa658f887e149a08aebd0180b2354005
Signed-off-by: Skyler Grey <[email protected]>
@Minion3665 Minion3665 force-pushed the private/skyler/add-prettier branch from feaca43 to 92d01ca Compare March 8, 2024 18:26
@Minion3665 Minion3665 requested a review from eszkadev March 8, 2024 18:27
@Minion3665
Copy link
Member Author

CI is back up to having checks, and I've modified the commit to make sure it doesn't format any files before our CI runs prettier. In other words: it can now fail, so that's good. I think we should merge this soon.

I note also that when we do merge it we need to be sure that we either rerun CI for or manually format currently open and green PRs that add new files (or CI will start complaining about them after they get merged if they have formatting issues)

@eszkadev eszkadev merged commit a40be54 into master Mar 9, 2024
9 checks passed
@eszkadev eszkadev deleted the private/skyler/add-prettier branch March 9, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants