From 8738e5917709c0cba0e7dd45289356f8a1d77384 Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Tue, 26 Jun 2018 22:32:27 -0700 Subject: [PATCH] Output a warning if React version is missing in settings Resolves #1789 --- lib/rules/jsx-space-before-closing.js | 11 +++++------ lib/util/log.js | 14 ++++++++++++++ lib/util/version.js | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 lib/util/log.js diff --git a/lib/rules/jsx-space-before-closing.js b/lib/rules/jsx-space-before-closing.js index 4f76e98b55..a436fe9e09 100644 --- a/lib/rules/jsx-space-before-closing.js +++ b/lib/rules/jsx-space-before-closing.js @@ -7,6 +7,7 @@ const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket'); const docsUrl = require('../util/docsUrl'); +const log = require('../util/log'); let isWarnedForDeprecation = false; @@ -75,15 +76,13 @@ module.exports = { }, Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { + if (isWarnedForDeprecation) { return; } - /* eslint-disable no-console */ - console.log('The react/jsx-space-before-closing rule is deprecated. ' + - 'Please use the react/jsx-tag-spacing rule with the ' + - '"beforeSelfClosing" option instead.'); - /* eslint-enable no-console */ + log('The react/jsx-space-before-closing rule is deprecated. ' + + 'Please use the react/jsx-tag-spacing rule with the ' + + '"beforeSelfClosing" option instead.'); isWarnedForDeprecation = true; } }; diff --git a/lib/util/log.js b/lib/util/log.js new file mode 100644 index 0000000000..ac3bfe8c3a --- /dev/null +++ b/lib/util/log.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 log(message) { + if (!/\=-(f|-format)=/.test(process.argv.join('='))) { + // eslint-disable-next-line no-console + console.log(message); + } +} + +module.exports = log; diff --git a/lib/util/version.js b/lib/util/version.js index 252d4f592d..97f96ae8ed 100644 --- a/lib/util/version.js +++ b/lib/util/version.js @@ -4,11 +4,19 @@ */ 'use strict'; +const log = require('./log'); + +let warnedForMissingVersion = false; + function getReactVersionFromContext(context) { let confVer = '999.999.999'; // .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings) if (context.settings.react && context.settings.react.version) { confVer = context.settings.react.version; + } else if (!warnedForMissingVersion) { + log('Warning: React version not specified in eslint-plugin-react settings. ' + + 'See https://github.com/yannickcr/eslint-plugin-react#configuration.'); + warnedForMissingVersion = true; } confVer = /^[0-9]+\.[0-9]+$/.test(confVer) ? `${confVer}.0` : confVer; return confVer.split('.').map(part => Number(part));