Skip to content

Commit

Permalink
Output a warning if React version is missing in settings
Browse files Browse the repository at this point in the history
Resolves #1789
  • Loading branch information
alexzherdev authored and ljharb committed Jun 27, 2018
1 parent f80e744 commit 8738e59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/rules/jsx-space-before-closing.js
Expand Up @@ -7,6 +7,7 @@

const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');
const docsUrl = require('../util/docsUrl');
const log = require('../util/log');

let isWarnedForDeprecation = false;

Expand Down Expand Up @@ -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;
}
};
Expand Down
14 changes: 14 additions & 0 deletions 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;
8 changes: 8 additions & 0 deletions lib/util/version.js
Expand Up @@ -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));
Expand Down

0 comments on commit 8738e59

Please sign in to comment.