Skip to content

Commit

Permalink
[Fix] version errors should log to stderr, not stdout
Browse files Browse the repository at this point in the history
Fixes #2082
  • Loading branch information
ljharb committed Dec 11, 2018
1 parent 4583342 commit 8ef86c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions lib/util/error.js
@@ -0,0 +1,14 @@
'use strict';

/**
* Logs out a message if there is no format option set.
* @param {String} message - Message to log.
*/
function error(message) {
if (!/\=-(f|-format)=/.test(process.argv.join('='))) {
// eslint-disable-next-line no-console
console.error(message);
}
}

module.exports = error;
10 changes: 5 additions & 5 deletions lib/util/version.js
Expand Up @@ -5,7 +5,7 @@
'use strict';

const resolve = require('resolve');
const log = require('./log');
const error = require('./error');

let warnedForMissingVersion = false;

Expand All @@ -16,7 +16,7 @@ function detectReactVersion() {
return react.version;
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
log('Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
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.');
return '999.999.999';
}
Expand All @@ -33,12 +33,12 @@ function getReactVersionFromContext(context) {
settingsVersion = detectReactVersion();
}
if (typeof settingsVersion !== 'string') {
log('Warning: React version specified in eslint-plugin-react-settings must be a string; ' +
error('Warning: React version specified in eslint-plugin-react-settings must be a string; ' +
`got “${typeof settingsVersion}”`);
}
confVer = String(settingsVersion);
} else if (!warnedForMissingVersion) {
log('Warning: React version not specified in eslint-plugin-react settings. ' +
error('Warning: React version not specified in eslint-plugin-react settings. ' +
'See https://github.com/yannickcr/eslint-plugin-react#configuration.');
warnedForMissingVersion = true;
}
Expand All @@ -52,7 +52,7 @@ function getFlowVersionFromContext(context) {
if (context.settings.react && context.settings.react.flowVersion) {
const flowVersion = context.settings.react.flowVersion;
if (typeof flowVersion !== 'string') {
log('Warning: Flow version specified in eslint-plugin-react-settings must be a string; ' +
error('Warning: Flow version specified in eslint-plugin-react-settings must be a string; ' +
`got “${typeof flowVersion}”`);
}
confVer = String(flowVersion);
Expand Down

0 comments on commit 8ef86c5

Please sign in to comment.