77const Components = require ( '../util/Components' ) ;
88const docsUrl = require ( '../util/docsUrl' ) ;
99const isAssignmentLHS = require ( '../util/ast' ) . isAssignmentLHS ;
10+ const report = require ( '../util/report' ) ;
1011
1112const DEFAULT_OPTION = 'always' ;
1213
@@ -44,6 +45,13 @@ function evalParams(params) {
4445 } ) ) ;
4546}
4647
48+ const messages = {
49+ noDestructPropsInSFCArg : 'Must never use destructuring props assignment in SFC argument' ,
50+ noDestructContextInSFCArg : 'Must never use destructuring context assignment in SFC argument' ,
51+ noDestructAssignment : 'Must never use destructuring {{type}} assignment' ,
52+ useDestructAssignment : 'Must use destructuring {{type}} assignment'
53+ } ;
54+
4755module . exports = {
4856 meta : {
4957 docs : {
@@ -53,12 +61,7 @@ module.exports = {
5361 url : docsUrl ( 'destructuring-assignment' )
5462 } ,
5563
56- messages : {
57- noDestructPropsInSFCArg : 'Must never use destructuring props assignment in SFC argument' ,
58- noDestructContextInSFCArg : 'Must never use destructuring context assignment in SFC argument' ,
59- noDestructAssignment : 'Must never use destructuring {{type}} assignment' ,
60- useDestructAssignment : 'Must use destructuring {{type}} assignment'
61- } ,
64+ messages,
6265
6366 schema : [ {
6467 type : 'string' ,
@@ -96,14 +99,12 @@ module.exports = {
9699 sfcParams . push ( params ) ;
97100
98101 if ( params [ 0 ] && params [ 0 ] . destructuring && components . get ( node ) && configuration === 'never' ) {
99- context . report ( {
100- node,
101- messageId : 'noDestructPropsInSFCArg'
102+ report ( context , messages . noDestructPropsInSFCArg , 'noDestructPropsInSFCArg' , {
103+ node
102104 } ) ;
103105 } else if ( params [ 1 ] && params [ 1 ] . destructuring && components . get ( node ) && configuration === 'never' ) {
104- context . report ( {
105- node,
106- messageId : 'noDestructContextInSFCArg'
106+ report ( context , messages . noDestructContextInSFCArg , 'noDestructContextInSFCArg' , {
107+ node
107108 } ) ;
108109 }
109110 }
@@ -125,9 +126,8 @@ module.exports = {
125126 )
126127 && ! isAssignmentLHS ( node ) ;
127128 if ( isPropUsed && configuration === 'always' ) {
128- context . report ( {
129+ report ( context , messages . useDestructAssignment , 'useDestructAssignment' , {
129130 node,
130- messageId : 'useDestructAssignment' ,
131131 data : {
132132 type : node . object . name
133133 }
@@ -158,9 +158,8 @@ module.exports = {
158158 isPropUsed && configuration === 'always'
159159 && ! ( ignoreClassFields && isInClassProperty ( node ) )
160160 ) {
161- context . report ( {
161+ report ( context , messages . useDestructAssignment , 'useDestructAssignment' , {
162162 node,
163- messageId : 'useDestructAssignment' ,
164163 data : {
165164 type : node . object . property . name
166165 }
@@ -206,9 +205,8 @@ module.exports = {
206205 ) ;
207206
208207 if ( SFCComponent && destructuringSFC && configuration === 'never' ) {
209- context . report ( {
208+ report ( context , messages . noDestructAssignment , 'noDestructAssignment' , {
210209 node,
211- messageId : 'noDestructAssignment' ,
212210 data : {
213211 type : node . init . name
214212 }
@@ -219,9 +217,8 @@ module.exports = {
219217 classComponent && destructuringClass && configuration === 'never'
220218 && ! ( ignoreClassFields && node . parent . type === 'ClassProperty' )
221219 ) {
222- context . report ( {
220+ report ( context , messages . noDestructAssignment , 'noDestructAssignment' , {
223221 node,
224- messageId : 'noDestructAssignment' ,
225222 data : {
226223 type : node . init . property . name
227224 }
0 commit comments