Skip to content

Commit

Permalink
version detection: detect: only warn once
Browse files Browse the repository at this point in the history
Closes #2276.
  • Loading branch information
ljharb committed May 15, 2019
1 parent a659b63 commit bdd6192
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/util/version.js
Expand Up @@ -9,15 +9,20 @@ const error = require('./error');

let warnedForMissingVersion = false;

function resetWarningFlag() {
warnedForMissingVersion = false;
}

function detectReactVersion() {
try {
const reactPath = resolve.sync('react', {basedir: process.cwd()});
const react = require(reactPath);
return react.version;
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
if (!warnedForMissingVersion && e.code === 'MODULE_NOT_FOUND') {
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;
return '999.999.999';
}
throw e;
Expand Down Expand Up @@ -107,5 +112,6 @@ function testFlowVersion(context, methodVer) {

module.exports = {
testReactVersion,
testFlowVersion
testFlowVersion,
resetWarningFlag
};
1 change: 1 addition & 0 deletions tests/util/version.js
Expand Up @@ -15,6 +15,7 @@ describe('Version', () => {
process.chdir(base);
sinon.stub(console, 'error');
expectedErrorArgs = [];
versionUtil.resetWarningFlag();
});

afterEach(() => {
Expand Down

0 comments on commit bdd6192

Please sign in to comment.