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

Handle react version detect errors #2336

Merged
merged 2 commits into from Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/util/version.js
Expand Up @@ -20,10 +20,12 @@ function detectReactVersion() {
const react = require(reactPath); // eslint-disable-line import/no-dynamic-require
return react.version;
} catch (e) {
if (!warnedForMissingVersion && e.code === 'MODULE_NOT_FOUND') {
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
if (e.code === 'MODULE_NOT_FOUND') {
if (!warnedForMissingVersion) {
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
'but the "react" package is not installed. Assuming latest React version for linting.');
warnedForMissingVersion = true;
warnedForMissingVersion = true;
}
return '999.999.999';
}
throw e;
Expand Down
9 changes: 9 additions & 0 deletions tests/util/version.js
Expand Up @@ -44,6 +44,15 @@ describe('Version', () => {
];
});

it('warns only once for failure to detect react ', () => {
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);

expectedErrorArgs = [
['Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.']
];
});

it('assumes latest version if flow-bin is not installed', () => {
assert.equal(versionUtil.testFlowVersion(context, '999.999.999'), true);

Expand Down