-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
added react-scripts lint #2729
added react-scripts lint #2729
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
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.
See comments above.
It would also be great to add a step verifying react-scripts lint
works before and after ejecting as part of "simple" end-to-end test.
spawn.sync( | ||
'node', | ||
[ | ||
'node_modules/eslint/bin/eslint.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 would prefer that we use require.resolve
here rather than hardcode node_modules
path.
[ | ||
'node_modules/eslint/bin/eslint.js', | ||
'--config', | ||
'node_modules/eslint-config-react-app/index.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.
Same.
@gaearon updated PR (rebased) with your notes for require.resolve and simple e2e test. Found that on the close event listener, ESLint will send a code of 0 or 1 on successful finishes (0: ESLint found no lint errors, 1: ESLint found lint errors) so that code is not particularly useful. So what we can only mainly check is errors throughout and the closing signal. |
Apologies, what I meant is we should add |
@gaearon updated commit, let me know what you think |
@gaearon ping! |
Hmm, I'm really not sold on the benefit here. This can be handled on CI way more accurately as I'll leave it to your discretion, @gaearon. |
@Timer yeah, it's a bit weird to really test if linting works or not. Putting it in Is there a better way in the |
console.log('ESLint finished'); | ||
}); | ||
results.on('error', err => { | ||
console.log('Error running ESLint: ' + err); |
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 should exit with an exit code. Otherwise CI wouldn't fail.
console.log('ESLint closed with signal: ' + signal); | ||
return; | ||
} | ||
console.log('ESLint finished'); |
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 don't think we need to log this.
[ | ||
require.resolve('eslint/bin/eslint'), | ||
'--config', | ||
require.resolve('eslint-config-react-app'), |
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.
After ejecting this should somehow let it infer config from package.json.
This is for the case when build is taking minutes and you just want to do a quick lint check. |
@gaearon updated, apologies in advance for a bit of hand-holding through this |
Hello! I'm a bot that helps facilitate testing pull requests. Your pull request (commit a452a0f) has been released on npm for testing purposes. npm i [email protected]
# or
yarn add [email protected]
# or
create-react-app [email protected] folder/ Note that the package has not been reviewed or vetted by the maintainers. Only install it at your own risk! Thanks for your contribution! |
How is this going? |
For anyone interested, I solved this differently because I have some other code styles to follow. It's really not that challenging: Create an
Add a linting script in
That's it. Now you cna run |
Being able to run |
Agreed, we want to take this in some form. It's been a while so I don't quite remember why this PR does things in the way it does. Let me leave a comment. |
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.
See below: I don't quite understand why this is written with a try-catch, and I don't think it will work after ejecting.
|
||
try { | ||
eslintConfigPath = require.resolve('eslint-config-react-app'); | ||
} catch (e) { |
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.
When would this throw and why? I don't understand.
try { | ||
eslintConfigPath = require.resolve('eslint-config-react-app'); | ||
} catch (e) { | ||
eslintConfigPath = require.resolve('../../../package.json'); |
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.
Why would package.json
count as a valid config?
require.resolve('eslint/bin/eslint'), | ||
'--config', | ||
eslintConfigPath, | ||
'src/**/*.{js,jsx}', |
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.
Need to include .mjs
now that we support it.
It's interesting that this doesn't filter tests out. I guess we can say it's a feature. (Currently there's no way to lint tests.)
@@ -314,6 +317,9 @@ npm link "$root_path"/packages/eslint-config-react-app | |||
npm link "$root_path"/packages/react-dev-utils | |||
npm link "$root_path"/packages/react-scripts | |||
|
|||
# Test lint | |||
"$root_path"/packages/react-scripts/bin/react-scripts.js lint |
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 make sense to me. What is this testing?
After you eject, react-scripts
doesn't exist (it might on CI but you shouldn't rely on this—the point of ejecting is to wipe out react-scripts
on the next installs).
So the script clearly doesn't "still work" after ejecting. If you had "lint": "react-scripts lint"
before ejecting, it will stop working after.
@devonjs Thanks for your initial work with this! I think this PR might need somebody’s helping had to push this through. I’m sorry I didn’t get time to review it in more detail earlier. @trevordmiller If you want to pick this up given the above review and resubmit it with these points addressed we can definitely try to get it in! |
I would give a try to close this. Should I open a new PR to submit changes? |
@gaearon Thanks! Sorry, I'm currently swamped or else I would. I appreciate the invite though. @devonjs or @maciej-ka seem like they could maybe do it? |
@maciej-ka Sounds good! |
Please provide link to new PR. Thanks! :) |
Added react-script for linting with specifications in #1217 & #2625