Skip to content

Commit 20779ff

Browse files
authored
Merge pull request jsx-eslint#1857 from alexzherdev/1789-warn-version
Output a warning if React version is missing in settings
2 parents f80e744 + 8738e59 commit 20779ff

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

lib/rules/jsx-space-before-closing.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');
99
const docsUrl = require('../util/docsUrl');
10+
const log = require('../util/log');
1011

1112
let isWarnedForDeprecation = false;
1213

@@ -75,15 +76,13 @@ module.exports = {
7576
},
7677

7778
Program: function() {
78-
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
79+
if (isWarnedForDeprecation) {
7980
return;
8081
}
8182

82-
/* eslint-disable no-console */
83-
console.log('The react/jsx-space-before-closing rule is deprecated. ' +
84-
'Please use the react/jsx-tag-spacing rule with the ' +
85-
'"beforeSelfClosing" option instead.');
86-
/* eslint-enable no-console */
83+
log('The react/jsx-space-before-closing rule is deprecated. ' +
84+
'Please use the react/jsx-tag-spacing rule with the ' +
85+
'"beforeSelfClosing" option instead.');
8786
isWarnedForDeprecation = true;
8887
}
8988
};

lib/util/log.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 log(message) {
8+
if (!/\=-(f|-format)=/.test(process.argv.join('='))) {
9+
// eslint-disable-next-line no-console
10+
console.log(message);
11+
}
12+
}
13+
14+
module.exports = log;

lib/util/version.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
*/
55
'use strict';
66

7+
const log = require('./log');
8+
9+
let warnedForMissingVersion = false;
10+
711
function getReactVersionFromContext(context) {
812
let confVer = '999.999.999';
913
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
1014
if (context.settings.react && context.settings.react.version) {
1115
confVer = context.settings.react.version;
16+
} else if (!warnedForMissingVersion) {
17+
log('Warning: React version not specified in eslint-plugin-react settings. ' +
18+
'See https://github.com/yannickcr/eslint-plugin-react#configuration.');
19+
warnedForMissingVersion = true;
1220
}
1321
confVer = /^[0-9]+\.[0-9]+$/.test(confVer) ? `${confVer}.0` : confVer;
1422
return confVer.split('.').map(part => Number(part));

0 commit comments

Comments
 (0)