Skip to content

Commit 0215c38

Browse files
authored
Merge pull request jsx-eslint#2336 from abhishekdev/handle-react-detect-errors
[Fix] Handle react version detect errors
2 parents d6832d6 + 8fbf50c commit 0215c38

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/util/version.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ function detectReactVersion() {
2020
const react = require(reactPath); // eslint-disable-line import/no-dynamic-require
2121
return react.version;
2222
} catch (e) {
23-
if (!warnedForMissingVersion && e.code === 'MODULE_NOT_FOUND') {
24-
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
23+
if (e.code === 'MODULE_NOT_FOUND') {
24+
if (!warnedForMissingVersion) {
25+
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
2526
'but the "react" package is not installed. Assuming latest React version for linting.');
26-
warnedForMissingVersion = true;
27+
warnedForMissingVersion = true;
28+
}
2729
return '999.999.999';
2830
}
2931
throw e;

tests/util/version.js

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ describe('Version', () => {
4444
];
4545
});
4646

47+
it('warns only once for failure to detect react ', () => {
48+
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);
49+
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);
50+
51+
expectedErrorArgs = [
52+
['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.']
53+
];
54+
});
55+
4756
it('assumes latest version if flow-bin is not installed', () => {
4857
assert.equal(versionUtil.testFlowVersion(context, '999.999.999'), true);
4958

0 commit comments

Comments
 (0)