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

use prettier to format all of js,json files #1883

Merged
merged 1 commit into from Oct 19, 2018

Conversation

chentsulin
Copy link
Contributor

Introduction

Use prettier and husky + lint-staged precommit hook to auto format all of js, json files

Proposed solution

Follow @tgriesser's .prettierrc config and npm scripts in knex/knex#2697

@ricardograca
Copy link
Member

Nice work. I'll check it out ASAP and report back.

@ricardograca ricardograca added this to To Do in Version 0.14.0 via automation Aug 21, 2018
@ricardograca ricardograca moved this from To Do to In progress in Version 0.14.0 Aug 21, 2018
Copy link
Member

@crunchtime-ali crunchtime-ali left a comment

Choose a reason for hiding this comment

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

ok, thank you for clarifying.
Besides that the PR LGTM.

Copy link
Member

@ricardograca ricardograca left a comment

Choose a reason for hiding this comment

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

Finally, if you could change bracketSpacing to false I think it would help to cut down the number of lines touched by this PR.

Still, I'm not entirely convinced I prefer this over Standard.js, so can you explain its advantages and what the development workflow looks like with this? Do I have to install any IDE plugins? Run a script before committing?

.prettierrc Outdated
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if this was set to "none". Also, can you set semi: false?

iterator,
initialValue,
context
) {
Copy link
Member

Choose a reason for hiding this comment

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

Wow. I really hate how the function arguments are split into individual lines like this. Makes no sense for such a small number of arguments. Is it possible to avoid this?

lib/base/collection.js Show resolved Hide resolved
const args = Array.from(arguments);

return Promise.mapSeries(listeners, listener => listener.apply(this, args.slice(1)));
return Promise.mapSeries(listeners, (listener) =>
listener.apply(this, args.slice(1))
Copy link
Member

Choose a reason for hiding this comment

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

This is weird. Splitting a single line fat arrow function into multiple lines makes its intention a bit ambiguous: e.g. was it supposed to be returning something or was it supposed to return undefined? Did the author made a mistake?

throw new TypeError(`Cannot accept incompatible options: method=insert, patch=${options.patch}`);
throw new TypeError(
`Cannot accept incompatible options: method=insert, patch=${
options.patch
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely super weird 😕 Why is the options.patch in a single line by itself? Is there like a 80 column max line length limit or something?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it wraps per default at 80 columns however you can set it via printWidth to a more reasonable amount. I suggest 120 columns. This should fix most of your aforementioned problems. How many columns do you suggest @ricardograca

Copy link
Member

Choose a reason for hiding this comment

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

👍 120 sounds good to me as well. 80 is definitely too narrow.

Copy link
Member

Choose a reason for hiding this comment

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

@chentsulin Can you please set printWidth: 120 and run prettier on the codebase again?

lib/base/model.js Show resolved Hide resolved
lib/base/model.js Outdated Show resolved Hide resolved
lib/bookshelf.js Show resolved Hide resolved
@chentsulin chentsulin force-pushed the prettier branch 2 times, most recently from c66d786 to e17aea3 Compare September 17, 2018 16:07
@chentsulin
Copy link
Contributor Author

Added those config:

"bracketSpacing": false,
"semi": false,
"printWidth": 120

@ricardograca
Copy link
Member

@chentsulin Can you address the last remaining comment above? I can do that after merging this, but I'd like to avoid several multi-thousand lines PRs if possible.

@chentsulin
Copy link
Contributor Author

@ricardograca

I set trailingComma to none, semi to true, those changes save ~4000 line changes.

Before:

2018-10-19 12 17 12

After

2018-10-19 12 22 09

@ricardograca
Copy link
Member

Many thanks!

@ricardograca ricardograca merged commit 7a49f0e into bookshelf:master Oct 19, 2018
Version 0.14.0 automation moved this from In progress to Done Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants