File tree 2 files changed +20
-2
lines changed 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
'use strict' ;
6
6
7
+ const resolve = require ( 'resolve' ) ;
7
8
const log = require ( './log' ) ;
8
9
9
10
let warnedForMissingVersion = false ;
@@ -12,7 +13,23 @@ function getReactVersionFromContext(context) {
12
13
let confVer = '999.999.999' ;
13
14
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
14
15
if ( context . settings . react && context . settings . react . version ) {
15
- confVer = context . settings . react . version ;
16
+ let settingsVer = context . settings . react . version ;
17
+ if ( settingsVer === 'detect' ) {
18
+ try {
19
+ const reactPath = resolve . sync ( 'react' , { basedir : process . cwd ( ) } ) ;
20
+ const react = require ( reactPath ) ;
21
+ settingsVer = react . version ;
22
+ } catch ( e ) {
23
+ if ( e . code === 'MODULE_NOT_FOUND' ) {
24
+ log ( 'Warning: React version was set to "detect" in eslint-plugin-react settings, ' +
25
+ 'but the "react" package is not installed. Assuming latest React version for linting.' ) ;
26
+ settingsVer = '999.999.999' ;
27
+ } else {
28
+ throw e ;
29
+ }
30
+ }
31
+ }
32
+ confVer = settingsVer ;
16
33
} else if ( ! warnedForMissingVersion ) {
17
34
log ( 'Warning: React version not specified in eslint-plugin-react settings. ' +
18
35
'See https://github.com/yannickcr/eslint-plugin-react#configuration.' ) ;
Original file line number Diff line number Diff line change 28
28
"doctrine" : " ^2.1.0" ,
29
29
"has" : " ^1.0.3" ,
30
30
"jsx-ast-utils" : " ^2.0.1" ,
31
- "prop-types" : " ^15.6.2"
31
+ "prop-types" : " ^15.6.2" ,
32
+ "resolve" : " ^1.8.1"
32
33
},
33
34
"devDependencies" : {
34
35
"babel-eslint" : " ^8.2.5" ,
You can’t perform that action at this time.
0 commit comments