49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/**
|
|
* @file no-console.js
|
|
* Forbid console usage in website code.
|
|
*
|
|
* Use ConsoleLogger instead:
|
|
* import { logger } from '@/lib/infrastructure/logging/logger'
|
|
*/
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
description: 'Forbid console.* usage (use ConsoleLogger wrapper instead)',
|
|
category: 'Logging',
|
|
recommended: true,
|
|
},
|
|
schema: [],
|
|
messages: {
|
|
noConsole:
|
|
'Do not use console. Use the project logger instead (ConsoleLogger). Import: `logger` from `@/lib/infrastructure/logging/logger`.',
|
|
},
|
|
},
|
|
|
|
create(context) {
|
|
const filename = context.getFilename();
|
|
|
|
// Allow console within the logging infrastructure itself.
|
|
// (ConsoleLogger implements the console adapter.)
|
|
if (
|
|
filename.includes('/lib/infrastructure/logging/') ||
|
|
filename.includes('/lib/infrastructure/EnhancedErrorReporter') ||
|
|
filename.includes('/lib/infrastructure/GlobalErrorHandler') ||
|
|
filename.includes('/lib/infrastructure/ErrorReplay') ||
|
|
filename.includes('/eslint-rules/')
|
|
) {
|
|
return {};
|
|
}
|
|
|
|
return {
|
|
MemberExpression(node) {
|
|
// console.log / console.error / console.warn / console.info / console.debug / console.group* ...
|
|
if (node.object && node.object.type === 'Identifier' && node.object.name === 'console') {
|
|
context.report({ node, messageId: 'noConsole' });
|
|
}
|
|
},
|
|
};
|
|
},
|
|
};
|