-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
[chore] Added prettier formatting to src and test #2676
Conversation
Ah checks failed because I forgot to run |
e057d5b
to
a920527
Compare
Also fixing a failing snapshot test in |
Woah, that's a lot of stuff. Perhaps we can limit it to just the src and test directory for now? This is going to bust a lot of PRs otherwise. Also, can we extract the prettier config to a .prettierrc.json file. Editor plugins will be able to pick up on the config that way. |
Heh, totally fair, it's a pretty large diff 😅 I'll try to restrict And hmm I've usually found that editors that have |
That'll be going away in the next major, so I wouldn't worry about it. I'd go with the JSON .prettierrc for now. I think that has broader support, so it's more likely for someone to pick up in their editor. |
49f4551
to
59a328f
Compare
I've updated the PR to run module.exports = {
extends: ['react-app', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': ['error', require('./.prettierrc.json')]
},
overrides: [
{
files: 'test/**/*.js',
env: {
jest: true,
},
},
],
} where {
"semi": false,
"singleQuote": true
} and the .prettierignore is:
Running ➜ redux git:(add_prettier) ✗ ./node_modules/.bin/prettier 'examples/**/*.js'
➜ redux git:(add_prettier) ✗ But running it through ➜ redux git:(add_prettier) ✗ yarn examples:lint
yarn run v1.1.0
$ eslint examples
/Users/adityavohra7/Documents/Github/redux/examples/async/src/components/Picker.js
7:53 error Delete `⏎···········` prettier/prettier
9:29 error Insert `·(` prettier/prettier
12:18 error Delete `)` prettier/prettier
13:7 error Insert `))` prettier/prettier
19:30 error Replace `⏎····PropTypes.string.isRequired⏎··` with `PropTypes.string.isRequired` prettier/prettier
/Users/adityavohra7/Documents/Github/redux/examples/async/src/components/Posts.js
4:17 error Replace `posts` with `·posts·` prettier/prettier
5:7 error Replace `⏎····{posts.map((post,·i)·=>⏎······<li·key={i}>{post.title}</li>⏎····)}⏎··` with `{posts.map((post,·i)·=>·<li·key={i}>{post.title}</li>)}` prettier/prettier
/Users/adityavohra7/Documents/Github/redux/examples/async/src/containers/App.js
46:16 error Insert `⏎·········` prettier/prettier
47:1 error Delete `······`
...
... I think this might be due to how Do we have any preferences on how we want to run |
package.json
Outdated
@@ -15,7 +15,7 @@ | |||
], | |||
"scripts": { | |||
"clean": "rimraf lib dist es coverage", | |||
"lint": "eslint src test build", | |||
"lint": "eslint src test build && prettier --write '{src,test}/**/*.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.
I might extract this to a separate script. The act of cleaning up code and linting it for errors is really two separate things. In fact, it probably should be in reverse order so that the linting is on the transformed code. I'd extract it out and add it to the prepare
script before the lint command.
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 doesn't error out if there were changes though. Isn't it better to use --list-different
which errors out? The prettier documentation specifically mentions this flag for CI purposes.
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.
What if we used both --write
and --list-different
? As you said, --list-different
will exit non-zero when prettier
finds that the formatting of at least one file was different than what it should be. And --write
will actually fix that formatting so users don't have to run it themselves (one less iteration for a redux dev). All this while still exiting non-zero so CI will fail if there were any formatting changes.
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.
Wouldn't this be confusing if you run the format command and get errors thrown when you actually expect them to be fixed in place?
In the spirit of redux I'd prefer the approach of @timdorr to create an extra command (or rather two). One for formatting in place for development and one side-effect free that just checks for errors for CI. This would also make more sense since we don't run eslint with the --fix
flag
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.
@eps1lon, it doesn't actually throw errors per se, it just exits non-zero printing what files were different/changed:
➜ redux git:(add_prettier) ./node_modules/.bin/prettier --write --list-different '{src,test}/**/*.js'
src/applyMiddleware.js
➜ redux git:(add_prettier) echo $?
1
@eps1lon, so you're suggesting a side-effect free addition to the lint command (something like prettier --list-different '{src,test}/**/*.js'
), and a format
helper utility run script (something like prettier --write '{src,test}/**/*.js'
), that devs can run during dev time?
@timdorr, you're suggesting no addition to the lint
script, but creating the same format
script and having it run before lint
in the prepare
script?
Those seem a little contradictory, but I'm probably misunderstanding something 😅
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.
One format
script entry with --write
for devs and one format:check
with --list-different
. And
add format:check
to the CI scripts.
59a328f
to
beda2f0
Compare
Friendly bump! Let me know if there's anything I should change! |
Just a question: Do you know if |
Yup! Looks like it does. With this diff: diff --git a/src/bindActionCreators.js b/src/bindActionCreators.js
index b44d6ff..6b02dfd 100644
--- a/src/bindActionCreators.js
+++ b/src/bindActionCreators.js
@@ -27,7 +27,7 @@ function bindActionCreator(actionCreator, dispatch) {
*/
export default function bindActionCreators(actionCreators, dispatch) {
if (typeof actionCreators === 'function') {
- return bindActionCreator(actionCreators, dispatch)
+ return bindActionCreator(actionCreators, dispatch);
}
if (typeof actionCreators !== 'object' || actionCreators === null) { Running the
Just running ➜ redux git:(add_prettier) ✗ ./node_modules/.bin/prettier --list-different '{src,test}/**/*.js'
src/bindActionCreators.js
➜ redux git:(add_prettier) ✗ echo $?
1 |
OK, I think this is good to go. I do want to wait until we get Thanks for the hard work so far! |
@timdorr sounds good! Thanks for the feedback throughout the review! 😊 |
|
Sure! I'll try to update this soon! 😄 |
beda2f0
to
06a651e
Compare
06a651e
to
ea4b26f
Compare
Updated! Let me know if you have any questions! |
Bump! Let me know if there's anything I should change! |
I'm good with this. @markerikson did you want to provide any input, or should we ship it? |
I haven't looked at this in detail, but I have no particular complaints about running everything through Prettier. |
Than ship it we shall. Thanks, @adityavohra7! |
Those are pretty volatile, so that would probably be more trouble than it's worth. I'd also like to keep them simple to use, so additional tooling would go against that goal. |
@timdorr, makes sense! Thanks once again for helping throughout this PR 😊 |
Wise words from the immortal @vjeux himself https://twitter.com/Vjeux/status/951538552675868673
Is there a specific reason for not wanting I've also been using |
Same reason we don't lint them. They're (almost) all built with Create React App and have that tooling built-in. I'd rather use the tooling from CRA than have to maintain that ourselves. |
This branch attempts to add
prettier
to this project viaeslint
. The motivation behind doing this is mostly to have easily configurable and consistent JS formatting across the entire project. I chose the values for theprettier
options used (semi
andsingleQuote
) based on what I thought the codebase was leaning towards. All other options assume their default values. Let me know if I should configure anything differently! I also ranyarn lint --fix
.