9
9
10
10
'use strict' ;
11
11
12
+ const LOGGER_FN_NAMES = [
13
+ 'warning' ,
14
+ 'warningWithoutStack' ,
15
+ 'lowPriorityWarning' ,
16
+ 'lowPriorityWarningWithoutStack' ,
17
+ ] ;
18
+ const DEV_EXPRESSION = '__DEV__' ;
19
+
12
20
module . exports = function ( context ) {
13
21
function traverseIf ( node ) {
14
22
switch ( node . type ) {
@@ -33,7 +41,7 @@ module.exports = function(context) {
33
41
node = node . parent ;
34
42
if (
35
43
node . type === 'IfStatement' &&
36
- traverseIf ( node . test ) . includes ( '__DEV__' )
44
+ traverseIf ( node . test ) . includes ( DEV_EXPRESSION )
37
45
) {
38
46
return true ;
39
47
}
@@ -43,21 +51,20 @@ module.exports = function(context) {
43
51
function report ( node ) {
44
52
context . report ( {
45
53
node : node ,
46
- message : `We don't emit warnings in production builds. Wrap {{identifier}}() in an "if (__DEV__ ) {}" check` ,
54
+ message : `We don't emit warnings in production builds. Wrap {{identifier}}() in an "if (${ DEV_EXPRESSION } ) {}" check` ,
47
55
data : {
48
56
identifier : node . callee . name ,
49
57
} ,
50
58
fix : function ( fixer ) {
51
59
return [
52
- fixer . insertTextBefore ( node . parent , ' if (__DEV__ ) {' ) ,
60
+ fixer . insertTextBefore ( node . parent , ` if (${ DEV_EXPRESSION } ) {` ) ,
53
61
fixer . insertTextAfter ( node . parent , '}' ) ,
54
62
] ;
55
63
} ,
56
64
} ) ;
57
65
}
58
66
59
- const isLoggerFunctionName = name =>
60
- [ 'warning' , 'warningWithoutStack' ] . includes ( name ) ;
67
+ const isLoggerFunctionName = name => LOGGER_FN_NAMES . includes ( name ) ;
61
68
62
69
return {
63
70
meta : {
0 commit comments