-
Notifications
You must be signed in to change notification settings - Fork 90
Add prettier code formatting #753
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
* Prettier will always double quote a string containing an apostrophe.
package.json
Outdated
@@ -57,12 +59,26 @@ | |||
}, | |||
"devDependencies": { | |||
"coveralls": "~3.0.2", | |||
"husky": "^1.1.0", |
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.
Please use ~ dependencies (instead of ^)
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.
Fixed 20bd137
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 see husky has been fixed, but some others still:
"lint-staged": "^7.3.0",
"prettier": "^1.14.2",
Could you fix them in the same way, pls?
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.
Fixed 3536dbf
"should": "13.2.3", | ||
"timekeeper": "2.1.2", | ||
"watch": "~1.0.2" | ||
}, | ||
"husky": { |
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.
How this exactly works? I mean:
- Does some configuration needs to be do on the "Settings / Webhook" sections in the repository to have this working?
- How the "autoformated on commit" works? Adding an additional commit automatically with the fix?
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.
Kind of, Husky builds a local precommit hook for you on your local instance - there is no need to add anything extra to the repository on GitHub. It means that the code gets properly formatted prior commit.
see:
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.
Thanks for the links! I didn't know about pre-commit git hooks. Seems cool :)
NTC
package.json
Outdated
@@ -33,6 +34,7 @@ | |||
"test": "mocha --recursive 'test/**/*.js' --reporter spec --timeout 3000 --ui bdd --exit", | |||
"test:watch": "npm run test -- -w ./lib", | |||
"lint": "jshint lib/ --config .jshintrc && jshint test/ --config test/.jshintrc", | |||
"prettier": "prettier --single-quote --trailing-comma es5 --write **/*.js *.js", |
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.
The new npm target should have its corresponding entry under https://github.com/telefonicaid/iotagent-node-lib/tree/master/doc/usermanual.md#development-documentation
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.
Fixed 75c0c54 - Of course you shouldn't need to run this manually as Husky will do it for you.
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.
Looking to prettier CLI options, I'd suggest to included --tab-width 4
to keep the current indentation style.
I'd like to start a passionate discussion on indentation length ;), but the fact is that this repository code uses 4 from its very begining, so let's keep that.
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.
Fixed a4979bd + 998f379 - This should make the diff less messy.
On the whole I've gone with the defaults suggested by prettier themselves, but double/single quote is repo preference and trailing-comma es5 is a step to the future (it adds the trailing quote only where ecma5 accepts it
Ideally once node 6 support is deprecated this can be updated to be consistent for ecma6 and use let
and const
and arrow functions and so on, but at least it is a start (and won't break the code)
I have had a quick look to the diff of changes but it is very hard to get the detail in a +1,189 −1,005 lines PR :) To check if I'm understand correctly... it seems the only change is to standarize the indent to 2 whitespaces in each level (changing from current 4 spaces indent). Is that all? Or is there any other change done by this prettier library? |
Basically yes, prettier is an opinionated code formatter, it will standardize whitespace, break up long lines etc, but deliberately doesn't give you too many options to play with. Prettier needs to be run once over the whole codebase, the Husky |
package.json
Outdated
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier --parser flow --single-quote --trailing-comma es5 --write", |
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.
It would be great to avoid sentece repetition and just use:
"npm prettier",
However, I've realized that the sentence is not exaclly the same, --write
vs. --write **/*.js *.js
... Is there any solution to "factorize" common sentence in just one place to be used in both cases?
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.
If there is I haven't found it yet. lint-staged
is running prettier
across each individual JavaScript file within the commit, the npm run prettier
script is a convenience function for running across all files - it shouldn't need to be used much, but I find it useful to format my files locally whilst I'm working.
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.
Ok. Pitty.
NTC
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.
The only pending thing seems to be changing ^ -> ~ in a couple of new dependencies in packages.json. Appart from that, LGTM.
In the meanwhile, passing the ball to @dcalvoalonso to get also his opinion on this PR.
Nice job @jason-fox ! LGTM |
I have realized we have other 6 PRs that may suffer the style fixing. I wouldn't suggest for block the merge of this (some of the other PRs are quite old) but at least lest provide a "migration path" their authors. For instancia:
@jason-fox what do you think? Is the procedure complete and precise enough? |
@fgalan - yes that procedure makes sense, especially for small PRs. |
Yes... I was meaning 6 in this repo but of course, considered in a wider sense, there are more. Let's analyze the situation repo by repo. In particular, in this repo we have:
|
@fgalan @dcalvoalonso - I have just updated this PR to remove any conflicts from the 2.10.0 codebase. Could you re-review as necessary and merge or close so I no longer have to keep updating the PR? |
If this PR is merged other PRs will need adaptation to be merged. Originally we thought that this adaptation would be straightforward (we even define a procedure for that: #753 (comment)). However, that procedure overestimated the difficulties due to exception marks (see telefonicaid/fiware-sth-comet#471 (comment)). This can cause difficulties to other PRs authors and to close PRs with valuable functionality in the worst case. As at then end happened with telefonicaid/fiware-sth-comet#471 (comment)... his author never reopened a new PR for that :( Taking into account that past experience and the existence of important PRs yet to be merged (as #753 or #800) I'm afraid we cannot merge this one yet. However, I would't opt for closing it, as I think you have done a valuable work here and I would be a pitty lossing it (having said that if you feel more confortable closing this PR or don't want to invest extra effort updating it in the future, it's also fine). Sorry the inconveniences... |
Adds prettier and husky. All JavaScript files are autoformated on commit using the Git Hooks hook.
running
npm run prettier
will format all files with standardized whitespace.