Skip to content

Commit e2e246a

Browse files
ljharbgolopot
authored andcommitted
version detection: detect: only warn once
Closes jsx-eslint#2276.
1 parent ef1d3e2 commit e2e246a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/util/version.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ const error = require('./error');
99

1010
let warnedForMissingVersion = false;
1111

12+
function resetWarningFlag() {
13+
warnedForMissingVersion = false;
14+
}
15+
1216
function detectReactVersion() {
1317
try {
1418
const reactPath = resolve.sync('react', {basedir: process.cwd()});
1519
const react = require(reactPath);
1620
return react.version;
1721
} catch (e) {
18-
if (e.code === 'MODULE_NOT_FOUND') {
22+
if (!warnedForMissingVersion && e.code === 'MODULE_NOT_FOUND') {
1923
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
2024
'but the "react" package is not installed. Assuming latest React version for linting.');
25+
warnedForMissingVersion = true;
2126
return '999.999.999';
2227
}
2328
throw e;
@@ -107,5 +112,6 @@ function testFlowVersion(context, methodVer) {
107112

108113
module.exports = {
109114
testReactVersion,
110-
testFlowVersion
115+
testFlowVersion,
116+
resetWarningFlag
111117
};

tests/util/version.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Version', () => {
1515
process.chdir(base);
1616
sinon.stub(console, 'error');
1717
expectedErrorArgs = [];
18+
versionUtil.resetWarningFlag();
1819
});
1920

2021
afterEach(() => {

0 commit comments

Comments
 (0)