Skip to content

Commit 8ef86c5

Browse files
committed
[Fix] version errors should log to stderr, not stdout
Fixes #2082
1 parent 4583342 commit 8ef86c5

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/util/error.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
/**
4+
* Logs out a message if there is no format option set.
5+
* @param {String} message - Message to log.
6+
*/
7+
function error(message) {
8+
if (!/\=-(f|-format)=/.test(process.argv.join('='))) {
9+
// eslint-disable-next-line no-console
10+
console.error(message);
11+
}
12+
}
13+
14+
module.exports = error;

lib/util/version.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'use strict';
66

77
const resolve = require('resolve');
8-
const log = require('./log');
8+
const error = require('./error');
99

1010
let warnedForMissingVersion = false;
1111

@@ -16,7 +16,7 @@ function detectReactVersion() {
1616
return react.version;
1717
} catch (e) {
1818
if (e.code === 'MODULE_NOT_FOUND') {
19-
log('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
19+
error('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
2020
'but the "react" package is not installed. Assuming latest React version for linting.');
2121
return '999.999.999';
2222
}
@@ -33,12 +33,12 @@ function getReactVersionFromContext(context) {
3333
settingsVersion = detectReactVersion();
3434
}
3535
if (typeof settingsVersion !== 'string') {
36-
log('Warning: React version specified in eslint-plugin-react-settings must be a string; ' +
36+
error('Warning: React version specified in eslint-plugin-react-settings must be a string; ' +
3737
`got “${typeof settingsVersion}”`);
3838
}
3939
confVer = String(settingsVersion);
4040
} else if (!warnedForMissingVersion) {
41-
log('Warning: React version not specified in eslint-plugin-react settings. ' +
41+
error('Warning: React version not specified in eslint-plugin-react settings. ' +
4242
'See https://github.com/yannickcr/eslint-plugin-react#configuration.');
4343
warnedForMissingVersion = true;
4444
}
@@ -52,7 +52,7 @@ function getFlowVersionFromContext(context) {
5252
if (context.settings.react && context.settings.react.flowVersion) {
5353
const flowVersion = context.settings.react.flowVersion;
5454
if (typeof flowVersion !== 'string') {
55-
log('Warning: Flow version specified in eslint-plugin-react-settings must be a string; ' +
55+
error('Warning: Flow version specified in eslint-plugin-react-settings must be a string; ' +
5656
`got “${typeof flowVersion}”`);
5757
}
5858
confVer = String(flowVersion);

0 commit comments

Comments
 (0)