Skip to content

Commit 03192ef

Browse files
committed
Output a warning if React version is missing in settings
Resolves jsx-eslint#1789
1 parent f80e744 commit 03192ef

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 no-console */
10+
console.log(message);
11+
/* eslint-enable no-console */
12+
}
13+
}
14+
15+
module.exports = log;

lib/util/version.js

Lines changed: 8 additions & 0 deletions
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)