@@ -32,7 +32,11 @@ function getReactVersionFromContext(context) {
32
32
if ( settingsVersion === 'detect' ) {
33
33
settingsVersion = detectReactVersion ( ) ;
34
34
}
35
- confVer = settingsVersion ;
35
+ if ( typeof settingsVersion !== 'string' ) {
36
+ log ( 'Warning: React version specified in eslint-plugin-react-settings must be a string; ' +
37
+ `got “${ typeof settingsVersion } ”` ) ;
38
+ }
39
+ confVer = String ( settingsVersion ) ;
36
40
} else if ( ! warnedForMissingVersion ) {
37
41
log ( 'Warning: React version not specified in eslint-plugin-react settings. ' +
38
42
'See https://github.com/yannickcr/eslint-plugin-react#configuration.' ) ;
@@ -46,19 +50,31 @@ function getFlowVersionFromContext(context) {
46
50
let confVer = '999.999.999' ;
47
51
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
48
52
if ( context . settings . react && context . settings . react . flowVersion ) {
49
- confVer = context . settings . react . flowVersion ;
53
+ const flowVersion = context . settings . react . flowVersion ;
54
+ if ( typeof flowVersion !== 'string' ) {
55
+ log ( 'Warning: Flow version specified in eslint-plugin-react-settings must be a string; ' +
56
+ `got “${ typeof flowVersion } ”` ) ;
57
+ }
58
+ confVer = String ( flowVersion ) ;
50
59
} else {
51
60
throw 'Could not retrieve flowVersion from settings' ;
52
61
}
53
62
confVer = / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + $ / . test ( confVer ) ? `${ confVer } .0` : confVer ;
54
63
return confVer . split ( '.' ) . map ( part => Number ( part ) ) ;
55
64
}
56
65
66
+ function normalizeParts ( parts ) {
67
+ return Array . from ( { length : 3 } , ( _ , i ) => ( parts [ i ] || 0 ) ) ;
68
+ }
69
+
57
70
function test ( context , methodVer , confVer ) {
58
- methodVer = String ( methodVer || '' ) . split ( '.' ) . map ( part => Number ( part ) ) ;
59
- const higherMajor = methodVer [ 0 ] < confVer [ 0 ] ;
60
- const higherMinor = methodVer [ 0 ] === confVer [ 0 ] && methodVer [ 1 ] < confVer [ 1 ] ;
61
- const higherOrEqualPatch = methodVer [ 0 ] === confVer [ 0 ] && methodVer [ 1 ] === confVer [ 1 ] && methodVer [ 2 ] <= confVer [ 2 ] ;
71
+ const methodVers = normalizeParts ( String ( methodVer || '' ) . split ( '.' ) . map ( part => Number ( part ) ) ) ;
72
+ const confVers = normalizeParts ( confVer ) ;
73
+ const higherMajor = methodVers [ 0 ] < confVers [ 0 ] ;
74
+ const higherMinor = methodVers [ 0 ] === confVers [ 0 ] && methodVers [ 1 ] < confVers [ 1 ] ;
75
+ const higherOrEqualPatch = methodVers [ 0 ] === confVers [ 0 ]
76
+ && methodVers [ 1 ] === confVers [ 1 ]
77
+ && methodVers [ 2 ] <= confVers [ 2 ] ;
62
78
63
79
return higherMajor || higherMinor || higherOrEqualPatch ;
64
80
}
0 commit comments