From f59e927405f2dacd897df69661dba0305ecad03c Mon Sep 17 00:00:00 2001 From: abhishekdev <227926+abhishekdev@users.noreply.github.com> Date: Fri, 28 Jun 2019 14:35:39 -0400 Subject: [PATCH 1/2] version detection: Add tests - Warn only once for failure to detect react version Ref: #2276 --- tests/util/version.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/util/version.js b/tests/util/version.js index 5eacb4633f..ea8a09b490 100644 --- a/tests/util/version.js +++ b/tests/util/version.js @@ -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); From 8fbf50c142ed9710b57830faa92ef2f6460ef8c3 Mon Sep 17 00:00:00 2001 From: abhishekdev <227926+abhishekdev@users.noreply.github.com> Date: Fri, 28 Jun 2019 14:35:49 -0400 Subject: [PATCH 2/2] version detection: Do not throw a raw error after the first warning - Adjust the conditions to always assume a latest react version when e.code === 'MODULE_NOT_FOUND' - The `warnedForMissingVersion` flag only controls the warning message and not the handling of the error Ref: #2276 --- lib/util/version.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/util/version.js b/lib/util/version.js index 3e8af90c01..932866bc69 100644 --- a/lib/util/version.js +++ b/lib/util/version.js @@ -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;