@@ -24,83 +24,86 @@ Object.keys(existingErrorMap).forEach(key =>
2424 * argument. 
2525 */ 
2626
27- module . exports  =  function ( context )  { 
28-   // we also allow literal strings and concatenated literal strings 
29-   function  getLiteralString ( node )  { 
30-     if  ( node . type  ===  'Literal'  &&  typeof  node . value  ===  'string' )  { 
31-       return  node . value ; 
32-     }  else  if  ( node . type  ===  'BinaryExpression'  &&  node . operator  ===  '+' )  { 
33-       const  l  =  getLiteralString ( node . left ) ; 
34-       const  r  =  getLiteralString ( node . right ) ; 
35-       if  ( l  !==  null  &&  r  !==  null )  { 
36-         return  l  +  r ; 
27+ module . exports  =  { 
28+   meta : { 
29+     schema : [ ] , 
30+   } , 
31+   create ( context )  { 
32+     // we also allow literal strings and concatenated literal strings 
33+     function  getLiteralString ( node )  { 
34+       if  ( node . type  ===  'Literal'  &&  typeof  node . value  ===  'string' )  { 
35+         return  node . value ; 
36+       }  else  if  ( node . type  ===  'BinaryExpression'  &&  node . operator  ===  '+' )  { 
37+         const  l  =  getLiteralString ( node . left ) ; 
38+         const  r  =  getLiteralString ( node . right ) ; 
39+         if  ( l  !==  null  &&  r  !==  null )  { 
40+           return  l  +  r ; 
41+         } 
3742      } 
43+       return  null ; 
3844    } 
39-     return  null ; 
40-   } 
4145
42-   return  { 
43-     CallExpression : function ( node )  { 
44-       // This could be a little smarter by checking context.getScope() to see 
45-       // how warning/invariant was defined. 
46-       const  isInvariant  = 
47-         node . callee . type  ===  'Identifier'  &&  node . callee . name  ===  'invariant' ; 
48-       if  ( ! isInvariant )  { 
49-         return ; 
50-       } 
51-       if  ( node . arguments . length  <  2 )  { 
52-         context . report ( node ,  '{{name}} takes at least two arguments' ,  { 
53-           name : node . callee . name , 
54-         } ) ; 
55-         return ; 
56-       } 
57-       const  format  =  getLiteralString ( node . arguments [ 1 ] ) ; 
58-       if  ( format  ===  null )  { 
59-         context . report ( 
60-           node , 
61-           'The second argument to {{name}} must be a string literal' , 
62-           { name : node . callee . name } 
63-         ) ; 
64-         return ; 
65-       } 
66-       if  ( format . length  <  10  ||  / ^ [ s \W ] * $ / . test ( format ) )  { 
67-         context . report ( 
68-           node , 
69-           'The {{name}} format should be able to uniquely identify this '  + 
70-             '{{name}}. Please, use a more descriptive format than: {{format}}' , 
71-           { name : node . callee . name ,  format : format } 
72-         ) ; 
73-         return ; 
74-       } 
75-       // count the number of formatting substitutions, plus the first two args 
76-       const  expectedNArgs  =  ( format . match ( / % s / g)  ||  [ ] ) . length  +  2 ; 
77-       if  ( node . arguments . length  !==  expectedNArgs )  { 
78-         context . report ( 
79-           node , 
80-           'Expected {{expectedNArgs}} arguments in call to {{name}} based on '  + 
81-             'the number of "%s" substitutions, but got {{length}}' , 
82-           { 
83-             expectedNArgs : expectedNArgs , 
46+     return  { 
47+       CallExpression : function ( node )  { 
48+         // This could be a little smarter by checking context.getScope() to see 
49+         // how warning/invariant was defined. 
50+         const  isInvariant  = 
51+           node . callee . type  ===  'Identifier'  &&  node . callee . name  ===  'invariant' ; 
52+         if  ( ! isInvariant )  { 
53+           return ; 
54+         } 
55+         if  ( node . arguments . length  <  2 )  { 
56+           context . report ( node ,  '{{name}} takes at least two arguments' ,  { 
8457            name : node . callee . name , 
85-             length : node . arguments . length , 
86-           } 
87-         ) ; 
88-       } 
58+           } ) ; 
59+           return ; 
60+         } 
61+         const  format  =  getLiteralString ( node . arguments [ 1 ] ) ; 
62+         if  ( format  ===  null )  { 
63+           context . report ( 
64+             node , 
65+             'The second argument to {{name}} must be a string literal' , 
66+             { name : node . callee . name } 
67+           ) ; 
68+           return ; 
69+         } 
70+         if  ( format . length  <  10  ||  / ^ [ s \W ] * $ / . test ( format ) )  { 
71+           context . report ( 
72+             node , 
73+             'The {{name}} format should be able to uniquely identify this '  + 
74+               '{{name}}. Please, use a more descriptive format than: {{format}}' , 
75+             { name : node . callee . name ,  format : format } 
76+           ) ; 
77+           return ; 
78+         } 
79+         // count the number of formatting substitutions, plus the first two args 
80+         const  expectedNArgs  =  ( format . match ( / % s / g)  ||  [ ] ) . length  +  2 ; 
81+         if  ( node . arguments . length  !==  expectedNArgs )  { 
82+           context . report ( 
83+             node , 
84+             'Expected {{expectedNArgs}} arguments in call to {{name}} based on '  + 
85+               'the number of "%s" substitutions, but got {{length}}' , 
86+             { 
87+               expectedNArgs : expectedNArgs , 
88+               name : node . callee . name , 
89+               length : node . arguments . length , 
90+             } 
91+           ) ; 
92+         } 
8993
90-       if  ( ! messages . has ( format ) )  { 
91-         context . report ( 
92-           node , 
93-           'Error message does not have a corresponding production '  + 
94-             'error code.\n\n'  + 
95-             'Run `yarn extract-errors` to add the message to error code '  + 
96-             'map, so it can be stripped from the production builds. '  + 
97-             "Alternatively, if you're updating an existing error "  + 
98-             'message, you can modify '  + 
99-             '`scripts/error-codes/codes.json` directly.' 
100-         ) ; 
101-       } 
102-     } , 
103-   } ; 
94+         if  ( ! messages . has ( format ) )  { 
95+           context . report ( 
96+             node , 
97+             'Error message does not have a corresponding production '  + 
98+               'error code.\n\n'  + 
99+               'Run `yarn extract-errors` to add the message to error code '  + 
100+               'map, so it can be stripped from the production builds. '  + 
101+               "Alternatively, if you're updating an existing error "  + 
102+               'message, you can modify '  + 
103+               '`scripts/error-codes/codes.json` directly.' 
104+           ) ; 
105+         } 
106+       } , 
107+     } ; 
108+   } , 
104109} ; 
105- 
106- module . exports . schema  =  [ ] ; 
0 commit comments