Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48b03f3

Browse files
committed
also wrap lowPriorityWarning
1 parent 416e258 commit 48b03f3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

scripts/eslint-rules/no-production-logging.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
'use strict';
1111

12+
const LOGGER_FN_NAMES = [
13+
'warning',
14+
'warningWithoutStack',
15+
'lowPriorityWarning',
16+
'lowPriorityWarningWithoutStack',
17+
];
18+
const DEV_EXPRESSION = '__DEV__';
19+
1220
module.exports = function(context) {
1321
function traverseIf(node) {
1422
switch (node.type) {
@@ -33,7 +41,7 @@ module.exports = function(context) {
3341
node = node.parent;
3442
if (
3543
node.type === 'IfStatement' &&
36-
traverseIf(node.test).includes('__DEV__')
44+
traverseIf(node.test).includes(DEV_EXPRESSION)
3745
) {
3846
return true;
3947
}
@@ -43,21 +51,20 @@ module.exports = function(context) {
4351
function report(node) {
4452
context.report({
4553
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`,
4755
data: {
4856
identifier: node.callee.name,
4957
},
5058
fix: function(fixer) {
5159
return [
52-
fixer.insertTextBefore(node.parent, 'if (__DEV__) {'),
60+
fixer.insertTextBefore(node.parent, `if (${DEV_EXPRESSION}) {`),
5361
fixer.insertTextAfter(node.parent, '}'),
5462
];
5563
},
5664
});
5765
}
5866

59-
const isLoggerFunctionName = name =>
60-
['warning', 'warningWithoutStack'].includes(name);
67+
const isLoggerFunctionName = name => LOGGER_FN_NAMES.includes(name);
6168

6269
return {
6370
meta: {

0 commit comments

Comments
 (0)