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

Crash the build during CI whenever linter warnings are encountered #944

Merged
merged 4 commits into from
Dec 3, 2016
Merged

Crash the build during CI whenever linter warnings are encountered #944

merged 4 commits into from
Dec 3, 2016

Conversation

excitement-engineer
Copy link
Contributor

Fixes issue #906.

Whenever someone runs the build script with the environmental variable CI set to true then it will crash when any linter warnings are encountered.

CI=true npm run build

I have tested this locally by generating an app using create-react-app and the updated react-scripts. Is this enough or should there be an automated way of testing this functionality? If so, can anyone give some advice on how to go about testing this?

I am also struggling to find the best location to document this feature. I considered updating the npm run build section of the README with this information however, I am afraid that explaining this feature in that location will only detract from the clarity to the reader. Perhaps I should create a new section in the user guide where this is explained, any thoughts?

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

Thanks! Maybe add a paragraph to https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#continuous-integration?

Can you post a screenshot of what the log looks like with warnings?

@gaearon gaearon added this to the 0.8.0 milestone Oct 28, 2016
@excitement-engineer
Copy link
Contributor Author

Here is a screenshot of the output:)

screen shot 2016-10-28 at 20 02 39

@excitement-engineer
Copy link
Contributor Author

I have updated the docs, let me know what you think!


If you find yourself doing this often in development, please [file an issue](https://github.com/facebookincubator/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows.
The build command will check for linter warning and fail if any are found.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be "linter warnings".

@@ -142,6 +142,11 @@ function build(previousSizeMap) {
process.exit(1);
}

if (process.env.CI && stats.compilation.warnings.length) {
printErrors('Failed to compile. Note, the build has crashed because it is being run with the environment variable CI set to true. In this mode the build crashes when any warnings are encountered.', stats.compilation.warnings);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, the build has crashed because it is being run with the environment variable CI set to true.

I think this wording makes it sound like having the CI env variable set to true is the problem, not the warnings themself. I hope people won't "fix" this by trying to set the env variable to false...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good comment! We wouldn't want this message to cause any confusion. I will rephrase it:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to remove the description! People can refer to the updated README for more information about running builds in CI:) Do you agree?

@fson
Copy link
Contributor

fson commented Dec 3, 2016

👍

@fson fson merged commit cdd17a6 into facebook:master Dec 3, 2016
@scholtzm
Copy link
Contributor

scholtzm commented Dec 4, 2016

This patch triggers build errors even when webpack emits a warning, e.g.:

This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.

Since I have no access to webpack.config.js, I can't use module.noParse.

I also tried to import the main js file from the src directory, but my bundle now includes import statements - it's not processed by webpack at all.

Is there a proper way to fix this besides ejecting?

@fson
Copy link
Contributor

fson commented Dec 4, 2016

I think we might have to change the way we catch the ESLint errors here – failing for any Webpack warning is not good, because mostly harmless warnings are sometimes also triggered by UglifyJS etc. Is there a way we can only catch ESLint errors?

@fson
Copy link
Contributor

fson commented Dec 4, 2016

@scholtzm Can you open a new issue about this problem so we can keep track of it? A merged pull request can't be reopened.

@scholtzm
Copy link
Contributor

scholtzm commented Dec 4, 2016

Yep, was going to suggest it as well.

@excitement-engineer
Copy link
Contributor Author

That is a side affect I did not take into account:( I hope this gets fixed soon! Thanks a lot for finding this bug @scholtzm!

@jayphelps
Copy link
Contributor

jayphelps commented Dec 14, 2016

FWIW I didn't see this addition to the docs (totally my fault), and the error was not clear that this was because of process.env.CI was set (we didn't know it was). Consider logging an explicit error message describing something like When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically. I can totally see in hindsight why this was done, but it was pretty frustrating trying to figure out what was different about my local machine. Just one user's experience 💃

@gaearon
Copy link
Contributor

gaearon commented Dec 14, 2016

@jayphelps 👍 Wanna send a PR?

@excitement-engineer
Copy link
Contributor Author

Great feedback! This error message was included in the original PR but I removed it because I thought that just having it in the docs was enough, but I guess I was wrong ;)

@gaearon
Copy link
Contributor

gaearon commented Dec 14, 2016

Yeah. I think @jayphelps’s wording is more clear than originally was in the PR so I’d be glad to get that in.

@excitement-engineer
Copy link
Contributor Author

Yep, I agree:)

alexdriaguine pushed a commit to alexdriaguine/create-react-app that referenced this pull request Jan 23, 2017
…acebook#944)

* Added functionality to crash the build during CI whenever linter warnings are encountered.

* Updated the docs with a description on how to use the build in CI

* Fixed small typo

* Fixed description of build error.
jayphelps added a commit to jayphelps/create-react-app that referenced this pull request Feb 8, 2017
@mikew
Copy link

mikew commented Mar 26, 2017

Any thought on reconsidering this? I've received flak when trying to add similar functionality to linters, with their reasoning being the rules can be configured to be an error or a warning. Turning a warning into an error doesn't make a whole lot of sense.

And that logic still applies here: eslint lets you configure things to be errors or warnings. It's great that you consider unused vars to be an error. Then make it an error in the first place.

@gaearon
Copy link
Contributor

gaearon commented Mar 26, 2017

We intentionally show lint errors very obtrusively (e.g. undefined variable doesn't let you see the app at all—it's treated as a built crash). So making making more minor issues errors would be too disruptive.

randycoulman pushed a commit to CodingZeal/create-react-app that referenced this pull request May 8, 2017
…acebook#944)

* Added functionality to crash the build during CI whenever linter warnings are encountered.

* Updated the docs with a description on how to use the build in CI

* Fixed small typo

* Fixed description of build error.
@varnav
Copy link
Contributor

varnav commented Jun 1, 2017

Okay, how to make the build NOT to crash during build with CI set to true?

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants