@@ -32,7 +32,11 @@ function getReactVersionFromContext(context) {
3232 if ( settingsVersion === 'detect' ) {
3333 settingsVersion = detectReactVersion ( ) ;
3434 }
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 ) ;
3640 } else if ( ! warnedForMissingVersion ) {
3741 log ( 'Warning: React version not specified in eslint-plugin-react settings. ' +
3842 'See https://github.com/yannickcr/eslint-plugin-react#configuration.' ) ;
@@ -46,19 +50,31 @@ function getFlowVersionFromContext(context) {
4650 let confVer = '999.999.999' ;
4751 // .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
4852 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 ) ;
5059 } else {
5160 throw 'Could not retrieve flowVersion from settings' ;
5261 }
5362 confVer = / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + $ / . test ( confVer ) ? `${ confVer } .0` : confVer ;
5463 return confVer . split ( '.' ) . map ( part => Number ( part ) ) ;
5564}
5665
66+ function normalizeParts ( parts ) {
67+ return Array . from ( { length : 3 } , ( _ , i ) => ( parts [ i ] || 0 ) ) ;
68+ }
69+
5770function 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 ] ;
6278
6379 return higherMajor || higherMinor || higherOrEqualPatch ;
6480}
0 commit comments