@@ -39,76 +39,56 @@ module.exports = {
3939 }
4040 }
4141
42- // Path
43- let pathString = '' ;
42+ const defaultImportName = 'Assets' ;
43+ const { deprecations, source} = context . options [ 0 ] ;
44+ let localImportSpecifier ;
4445
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} ) ;
53- }
54- }
55- }
46+ function setLocalImportSpecifier ( node ) {
47+ localImportSpecifier = utils . getLocalImportSpecifier ( node , source , defaultImportName ) ;
5648 }
5749
58- function isAssetsObject ( node ) {
50+ function getAssetString ( node , pathString = '' ) {
5951 if ( node ) {
6052 if ( node . object ) {
6153 if ( node . property && node . property . name ) {
6254 pathString = ( pathString === '' ) ? `${ node . property . name } ` : `${ node . property . name } .${ pathString } ` ;
63- return isAssetsObject ( node . object ) ;
55+ return getAssetString ( node . object , pathString ) ;
6456 }
65- } else if ( node . name === assetsName ) {
57+ } else if ( node . name === localImportSpecifier ) {
6658 pathString = `${ node . name } .${ pathString } ` ;
67- return true ;
59+ return pathString ;
6860 }
6961 }
70- pathString = '' ;
71- return false ;
72- }
73-
74- const { deprecations} = context . options [ 0 ] ;
7562
76- function getDeprecatedObject ( path ) {
77- return _ . find ( deprecations , { path} ) ;
63+ return undefined ;
7864 }
7965
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- } ) ;
66+ function findAndReportDeprecation ( node , possibleDeprecation ) {
67+ possibleDeprecation = possibleDeprecation . replace ( localImportSpecifier , defaultImportName ) ;
68+ const deprecatedObject = _ . find ( deprecations , { path : possibleDeprecation } ) ;
69+ if ( deprecatedObject ) {
70+ reportDeprecatedAssets ( node , deprecatedObject ) ;
8671 }
8772 }
8873
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- }
74+ function testMemberDeprecation ( node ) {
75+ const assetString = getAssetString ( node ) ;
76+ if ( assetString ) {
77+ findAndReportDeprecation ( node , assetString ) ;
10278 }
10379 }
10480
10581 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 ) ,
82+ ImportDeclaration : node => ! localImportSpecifier && setLocalImportSpecifier ( node ) ,
83+ MemberExpression : node => localImportSpecifier && testMemberDeprecation ( node ) ,
84+
85+
86+ // VariableDeclarator: node => testVariableDeclarator(node),
87+ // JSXAttribute: node => testJSXAttribute(node),
88+ // JSXOpeningElement: node => testJSXOpeningElement(node),
89+ // JSXSpreadAttribute: node => testJSXSpreadAttribute(node),
90+ // ObjectExpression: node => testObjectExpression(node),
91+ // Property: node => testProperty(node),
11292 } ;
11393 } ,
11494} ;
0 commit comments