-
Notifications
You must be signed in to change notification settings - Fork 929
style(*): Automate Code Formatting #90
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
5b2f7e8
to
3fbdb87
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.
This is probably fine, but what style is it using? It seems to be different than the internal google style for TypeScript (which e.g. prefers ' over "). It would be nice if we could be consistent so it's not too confusing for people that work in both worlds.
Also, why did you have to remove tslint.json? Is it conflicting with this style or something?
@mikelehen this is using the tool Prettier for formatting. Prettier is in the same realm of tools as Considering this is automatically runs on commit, you can write your code however you want it all gets standardized for the review. If there is some specific things we don't like about the style we can address those for sure. |
Fair point... I've been very impressed with clang-format so I'm biased towards it. I trust it to do the right thing in 99.8% of cases and I can live with the .2% where I'm annoyed with its formatting. I haven't used prettifier, so I'm nervous... and if we need to change settings or it changes behavior in the future, it'll create gratuitous diffs which make it harder to review code and pollutes the git history (so things like "git blame" are no longer useful). But I'm not actually opposed. I spot checked a few files and don't see anything that really concerns me. So I can go ahead and approve.... |
Oh! One last comment. If folks have large outstanding PRs, this may create a merge conflict nightmare... something to keep in mind. |
The styling itself looks reasonable to me. It's unclear to me why we shouldn't just leave the tslint.json file in though. Did the code pass all the lint checks before the reformat, but it doesn't afterward? Because if it didn't pass the checks before and it still doesn't afterward, I think we might as well just leave it there instead of having to add it back later when we address the lint errors. |
The removal of the tl;dr: It's only temporary till I can fix all the errors. |
@mikelehen brings up a good point though. @jsayol seeing as you have the large open PR in question, would you like me to hold off till we can get your PR merged? |
FWIW, fixing all the errors may be untenable. Internally we run tslint in such a way that it only complains about lines you actually changed. That way we don't regress, but it doesn't cause noise for all the existing violations (which grow over time as new rules are enabled, etc.) |
Haha, fair enough. I will be trying to fix as many as possible and making it so the linter only runs on changed files is a great idea. That said, I feel like, if we change tslint rules, that those should be accompanied by a fix for violating areas of the code. |
I think we can configure prettier to prefer single quotes, no? |
We can sure, if that's something we want it's super trivial to do. |
It'd be interesting to run some code through prettifier and then clang-format (and vice-versa?) to see where they conflict and then see if we want to change any settings to make them more similar. If nothing else, I'm pretty curious to see if they are significantly different in any interesting ways. I'm okay if we don't want to invest the time for that though. |
I could probably spin up a branch with clang-format, i'll get you a diff here in a bit |
True that. I had to disable tslint in my local environment since my IDE was complaining about "errors" in almost every single line and it was unusable.
Yeah, that might actually be a good idea. It's already going to be quite a bit of work to rebase and solve conflicts as it stands right now (I'll get to it first thing tomorrow morning) but with all these other proposed changes it might turn into a bit of a nightmare. Thank you both for taking me into account, btw :) Edit: I'm done rebasing PR #66. |
cdce379
to
3a3df33
Compare
@mikelehen I ran clang-format (default settings) on the codebase and pushed a branch, here is the diffs:
I personally think |
We've got @jsayol's PR in and this branch has been re-pushed with his changes. Pending some stylistic adjustments (Full adjustment options are here: https://github.com/prettier/prettier#options) this should be G2G. |
Style seems generally fine to me, would keep the tslint in though. |
I noticed a few things I'm not a big fan of:
Unfortunately none of these seem configurable. clang-format is much much more configurable it seems. I think item 3 may be a deal breaker (we need to figure out how to turn it off or verify that we're not minifying in such a way that it's impacted). But I don't feel strongly enough about the other 2 to push back too hard. |
I want to agree with @mikelehen on point 3 actually. When we stopped using Closure Compiler for storage the library went from ~30 kb to ~55 kb in uncompressed size, so I would like to introduce the Closure Compiler back into the storage build process at some point. Unless we have a way to keep keys in object literals as string literals, that doesn't seem possible. |
@sphippen I'm actually working on a PR (#94) to reduce the size of the bundles. Preliminary results are good and I've made some more progress today. I may have something decent to merge either later today or tomorrow. |
@mikelehen, I'll address point 3 because that seems to be the main blocker. We are currently using the package uglify-js to do minification. This internally does not do sub-property mangling by default. I have started looking into using Closure Compiler for minification but it seems like we have some things we'd need to fix first as the current version of closure compiler chokes on the webpack output. Having said that, I've seen some stuff about using tsickle to help properly format the typescript output for closure so I'll look into something with that to see if we can get the built size down more. #94 gets us to a much better place and the beta v1 of the UglifyJS Webpack Plugin uses uglify-es which I've seen examples where it outperforms closure. So lots to investigate in this area. |
3a3df33
to
c361123
Compare
@sphippen as of the release at 4.1.4, |
All, if there are no more blockers on this I'm going to merge this and start working on the linter fixes and the underscore convention. Please let me know if you have any other concerns. |
…in the build Something breaks in version 2.4.1 of typescript. We are pinning to 2.3.0 till those things can be triaged and fixed
Temporarily removing this file as we don't pass the checks
c361123
to
f95e1dc
Compare
Adding in automation for prettier code formatting and running prettier on all the files.
NOTE: I have also removed the
tslint.json
file in this PR as I am going to add in some automated validation for code style after this commit. I will reintroduce thetslint.json
and clean up the linter errors when I have an opportunity