Skip to content

Commit 427da56

Browse files
Create no-console-in-prod.js
1 parent 11f986f commit 427da56

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
meta: {
3+
type: 'problem',
4+
docs: {
5+
description: 'Disallow console.log() in production environments',
6+
category: 'Best Practices',
7+
recommended: true,
8+
},
9+
schema: [],
10+
},
11+
create(context) {
12+
return {
13+
CallExpression(node) {
14+
if (
15+
node.callee.object &&
16+
node.callee.object.name === 'console' &&
17+
node.callee.property &&
18+
node.callee.property.name === 'log'
19+
) {
20+
const isProduction = process.env.NODE_ENV === 'production';
21+
22+
context.report({
23+
node,
24+
message: isProduction
25+
? '❌ console.log() is not allowed in production. Use a proper logger instead.'
26+
: '⚠️ Consider removing console.log() before pushing to production.',
27+
});
28+
}
29+
},
30+
};
31+
},
32+
};

0 commit comments

Comments
 (0)