-
Notifications
You must be signed in to change notification settings - Fork 135
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 - an opinionated code formatter #932
Conversation
Can be useful here: https://www.npmjs.com/package/pretty-quick |
d0afb16
to
c4c92f9
Compare
c4c92f9
to
98c1d48
Compare
What still needs to be done for this to be merged? Prettier is so convenient 😍 |
@ahstro I think the path for this starts to be clear; we've converted codebase to ES6, consolidated different Eslint configs and we're working on removing stuff from Gulp setup, too. Wanna help out with this? :-) |
98c1d48
to
cccea86
Compare
We have some choices of different strategies here — any preferences which way to go?
Thoughts? |
cccea86
to
66ebc1e
Compare
I tested with some files and unrelated Prettier changes are so much noise that I think we're better off with option 2. One big mega PR we can do once we're doing PRs mainly to Prettified files so that we don't end up in rebase nightmare. I'll changes settings in this PR to that effect. Lemme know if you have thoughts or prefer otherwise! You can test the noise level by checking this branch, make some whitespace changes in any file and commit it and see the git log/diff. |
"pre-commit": "npm run -s install-dependencies && npx lint-staged" | ||
} | ||
}, | ||
"lint-staged": { |
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.
An alternative for lint-staged
could be pretty-quick
but its geared towards Prettier only. With lint-staged we can also run linter on 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.
Yes, seems good to be able to have it doing general linting too. Although we also have linting in npm run lint:watch
and in the webpack dev server... (for client files), linting everywhere... (not to mention my editor is doing it too).
Personally, I would not add the git hooks to my own local setup, I don't know why but they feel invasive, maybe I can learn to love them though. But not much unlinted makes it through the 3 lint stages above anyway.
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.
Hehe yeah. We should drop linting either here or in webpack dev-server+lint:watch. I like the simplicity of this setup and since I have continuous linting in editor, I don't really need the dev-server linting. I appreciate it might be easier to approach for new devs/volunteers, tho.
What do you think?
In future I'd like to add Stylelint to lint *.less files so it would get added here, too.
Once everything is in Prettier, we might be able to remove these Eslint rules from our config, since Prettier-eslint config turns them
For now, we need to keep them since not every file is Prettified. |
I actually don't mind mega PRs formatting change so much, I tend to find a way to run the prettier on my other PRs before trying to rebase/merge, so that it's more-or-less in the right shape anyway. Might be more fiddly getting the exact prettier config to use. But perhaps others are less happy doing PR fiddling, and so maybe your option 2 is best. I guess once we rebase our other PRs ontop, we could turn the |
I'm happy to do mega PR if you all are fine with it. I don't have that much to rebase as you all have. ;-) |
a75bf17
to
164adfe
Compare
e64c0d8
to
6de6e6e
Compare
Rebased. |
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.
Interesting stuff! Never used this prettier before (if i don't count a random typescript tutorial 2 days ago).
How can we use this feature?
When i add the /** @format */
at the beginning of the ./modules/users/server/controllers/users.profile.server.controller.js
and commit the change, i get a whole bunch of space-before-function-paren
linter errors; as if the eslint and the prettier are fighting. I would expect it to do the formatting for me and finish gracefully.
And is it possible to format everything without adding the /** @format */
piece?
I don't have much idea about the 3 options of running prettier, but I like the option 3 for the reason that all the code is consistently formatted at all times. I haven't pondered it much though.
Yes, I indeed changed it to that in the latest commit but didn't update the PR description yet. 🤦♂ I initially added |
Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier
54bf1e7
to
cce1811
Compare
I squashed the commits until now, removed some conflicting eslint rules and performed the prettier reformat-files on md, json, html and js files. A few notes: Are we ready for such a large change? Please, review the additional removed eslint rules efb6b86, see that you're happy with the rest, too. We'll still want to squash those additional eslint rules into the "configuration" commit and maybe squash together the reformatting commits as a single separate commit. Please try to run the app and see that it still works as expected. |
We may want to undo reformatting of md files in |
Thanks, @mrkvon — on cursory looking Eslint config changes look good.
Should we just add those md & html files to eslintignore for now? Alternatively, we could add What do you think? |
c57268e
to
7d471b8
Compare
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 can't press "approve" since I opened this PR but your changes look great!
Let's do this! 💪
I've spot-checked different files, tested linter locally with npm run lint
and running this locally works.
Also IDE integration with both Eslint and Prettier seems to work:
When I modify the file, Prettier adds that comma back.
Also committing file makes Prettier add comma back.
When committing a js file and letting Prettier run on it, I see this:
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
...so suppose we can remove it. :-) OK to merge as is and remove later, or if you remove please test that committing+Prettier still works.
Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier
7d471b8
to
1a43c4e
Compare
I suppose the We get warned rightfully. I find it scary indeed that there are changes which get committed and which a developer has no control over. It's just something I'll need to get used to. 🙂 I wonder whether to squash the four formatting commits into one (md, html, js, json). I'm inclined to do it, but I'd like a second opinion. Probably doesn't matter anyways. 🙂 |
1a43c4e
to
9f5912d
Compare
I've squashed the commits a bit, so there are 2 commits left: config and formatting. I think it would make sense to keep it that way and use the Rebase and merge button. |
One huge reformat commit seems fine instead of splitting by format.. Might make rebasing easier? I also thought precommit hook needs the git add but the warning made me think it might make it on our behalf? |
The idea that commits Prettified files on your behalf is to provide convenience. :-) I have it set in editor myself, so it reformats as I type or safe files. You'll still get chance to see the edits before pushing and then finally before merging. |
Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier
9f5912d
to
95db69b
Compare
@simison Indeed, your understanding is correct. I've just tested that with the The change was included with the latest |
With that done, let's merge. Kudos @simison 🎉 And let's see how rebasing after this will go... |
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.
Perfect! 👍 Thanks for testing the git-thing.
Feel free to merge.
Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier
Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier
* Add Thread component for /messages/<username> * Marginally nicer tribes-in-common code * Minor formatting update * Style refinements, more flex, less row * Indentation fix * Implement infinite scroller for chat thread * Update package lock * Some code tidying * Mark messages as read * Add message sending and scrolling to bottom * Small code tidy * Don't send empty messages * Save message draft in local storage * Don't add fake messages on initial fetch * Still show message input when no messages * Add "You haven't been talking yet" bit in messages * Add message for non-public user * Add "Your profile seems quite empty" bit * Use lodash like lodash/func not lodash.func I was wrong! * Add quick replies * Remove premature optimization Should probably use useMemo there anyway * Preserve position on resize and styling fixes * More styled-components, less inline style * Extra a few components into their own files * Add Prettier - an opinionated code formatter (#932) Lint and prettify staged files in pre-commit hook Reformat js, md, html and json files Remove eslint rules that conflict with prettier * Reformat messages thread files with prettier * Add message when user does not exist * Minor tidy * Put all messages text into i18n * A little refactor * Use loading indictor ... and fixup some imports * Add initial message thread tests * Update translations Not sure I should add this as some of the changes look odd... * Add note about fake mongo id generator * Move more general components into better places * Implement paginated messages loading * Fix tests to use new paginated API * Remove comment It's actually too hard to write a pagination test for now because there is no scrollHeight in jsdom as it's not actually doing the layout stuff, so can't really test that bit. Would be nice to have a way to test the _logic_ though... * Add some documentation about InfiniteMessages * Remove undeeded @todos * Redirect back to inbox if visiting self thread * Remove old angular messages stuff * Remove redundant error handling * Use mongolib to generate test id * Revert translations to master * Don't use translation function with dynamic text * Remove unused thread dimensions directive * Fix messages-read API response * Remove trailing <br> inside TrEditor Moving it a bit closer to the source * Show monkeybox for the correct chat user * Refocus input after sending a message * Fix link to profile in Monkeybox * Always show reply box for existing conversations * Add Monkeybox "Languages" heading to i18n Co-authored-by: Mikael Korpela <mikael@ihminen.org>
Eslint rules still need work, since now "prettier" rules are applied everywhere.
https://prettier.io/docs/en/eslint.html
Resolves #858
Testing
git commit
, Prettier should process those files.