diff --git a/packages/eslint-config-airbnb-base/rules/no-console-in-prod.js b/packages/eslint-config-airbnb-base/rules/no-console-in-prod.js new file mode 100644 index 0000000000..da1ddfec08 --- /dev/null +++ b/packages/eslint-config-airbnb-base/rules/no-console-in-prod.js @@ -0,0 +1,32 @@ +module.exports = { + meta: { + type: 'problem', + docs: { + description: 'Disallow console.log() in production environments', + category: 'Best Practices', + recommended: true, + }, + schema: [], + }, + create(context) { + return { + CallExpression(node) { + if ( + node.callee.object && + node.callee.object.name === 'console' && + node.callee.property && + node.callee.property.name === 'log' + ) { + const isProduction = process.env.NODE_ENV === 'production'; + + context.report({ + node, + message: isProduction + ? '❌ console.log() is not allowed in production. Use a proper logger instead.' + : '⚠️ Consider removing console.log() before pushing to production.', + }); + } + }, + }; + }, +};