@@ -39,76 +39,65 @@ module.exports = {
39
39
}
40
40
}
41
41
42
- // Path
43
- let pathString = '' ;
42
+ const defaultImportName = 'Assets' ;
43
+ const { deprecations, source} = context . options [ 0 ] ;
44
+ let localImportSpecifier ;
44
45
45
- function deprecationCheck ( node ) {
46
- if ( node ) {
47
- const check = isAssetsObject ( node ) ;
48
- if ( check && pathString !== '' ) {
49
- const deprecatedObject = getDeprecatedObject ( pathString ) ;
50
- if ( deprecatedObject ) {
51
- const { path , message , fix } = deprecatedObject ;
52
- reportDeprecatedAssets ( node , { path , message , fix } ) ;
46
+ function setLocalImportSpecifier ( node ) {
47
+ const importSource = node . source . value ;
48
+ if ( source === importSource ) {
49
+ const specifiers = node . specifiers ;
50
+ if ( specifiers ) {
51
+ localImportSpecifier = _ . find ( specifiers , specifier => specifier . imported . name === defaultImportName ) ;
52
+ if ( localImportSpecifier ) {
53
+ localImportSpecifier = localImportSpecifier . local . name ;
53
54
}
54
55
}
55
56
}
56
57
}
57
58
58
- function isAssetsObject ( node ) {
59
+ function getAssetString ( node , pathString = '' ) {
59
60
if ( node ) {
60
61
if ( node . object ) {
61
62
if ( node . property && node . property . name ) {
62
63
pathString = ( pathString === '' ) ? `${ node . property . name } ` : `${ node . property . name } .${ pathString } ` ;
63
- return isAssetsObject ( node . object ) ;
64
+ return getAssetString ( node . object , pathString ) ;
64
65
}
65
- } else if ( node . name === assetsName ) {
66
+ } else if ( node . name === localImportSpecifier ) {
66
67
pathString = `${ node . name } .${ pathString } ` ;
67
- return true ;
68
+ return pathString ;
68
69
}
69
70
}
70
- pathString = '' ;
71
- return false ;
72
- }
73
71
74
- const { deprecations} = context . options [ 0 ] ;
75
-
76
- function getDeprecatedObject ( path ) {
77
- return _ . find ( deprecations , { path} ) ;
72
+ return undefined ;
78
73
}
79
74
80
- function checkSpreadAttribute ( node ) {
81
- const spreadSource = utils . findValueNodeOfIdentifier ( node . argument . name , context . getScope ( ) ) ;
82
- if ( spreadSource && spreadSource . properties ) {
83
- _ . forEach ( spreadSource . properties , ( property ) => {
84
- deprecationCheck ( property ) ;
85
- } ) ;
75
+ function findAndReportDeprecation ( node , possibleDeprecation ) {
76
+ possibleDeprecation = possibleDeprecation . replace ( localImportSpecifier , defaultImportName ) ;
77
+ const deprecatedObject = _ . find ( deprecations , { path : possibleDeprecation } ) ;
78
+ if ( deprecatedObject ) {
79
+ reportDeprecatedAssets ( node , deprecatedObject ) ;
86
80
}
87
81
}
88
82
89
- // Import
90
- const { source} = context . options [ 0 ] ;
91
- const assetsName = 'Assets' ;
92
- let shouldCheckDeprecation = false ;
93
-
94
- function checkAssetsImport ( node ) {
95
- const importSource = node . source . value ;
96
-
97
- if ( source === importSource ) {
98
- const specifiers = node . specifiers ;
99
- if ( specifiers ) {
100
- shouldCheckDeprecation = _ . find ( specifiers , e => e . local . name === assetsName ) ;
101
- }
83
+ function testMemberDeprecation ( node ) {
84
+ let assetString = getAssetString ( node ) ;
85
+ if ( assetString ) {
86
+ findAndReportDeprecation ( node , assetString ) ;
102
87
}
103
88
}
104
89
105
90
return {
106
- ImportDeclaration : node => checkAssetsImport ( node ) ,
107
- // MemberExpression: node => shouldCheckDeprecation && deprecationCheck(node),
108
- VariableDeclarator : node => shouldCheckDeprecation && deprecationCheck ( node . init ) ,
109
- Property : node => shouldCheckDeprecation && deprecationCheck ( node . value ) ,
110
- JSXAttribute : node => shouldCheckDeprecation && node . value && deprecationCheck ( node . value . expression ) ,
111
- JSXSpreadAttribute : node => shouldCheckDeprecation && checkSpreadAttribute ( node ) ,
91
+ ImportDeclaration : node => setLocalImportSpecifier ( node ) ,
92
+ MemberExpression : node => localImportSpecifier && testMemberDeprecation ( node ) ,
93
+
94
+
95
+ // VariableDeclarator: node => testVariableDeclarator(node),
96
+ // JSXAttribute: node => testJSXAttribute(node),
97
+ // JSXOpeningElement: node => testJSXOpeningElement(node),
98
+ // JSXSpreadAttribute: node => testJSXSpreadAttribute(node),
99
+ // ObjectExpression: node => testObjectExpression(node),
100
+ // Property: node => testProperty(node),
112
101
} ;
113
102
} ,
114
103
} ;
0 commit comments