eslint-plugin-require-logging
v1.0.3
Published
An ESLint plugin that requires logging in all functions
Downloads
52
Maintainers
Readme
eslint-plugin-require-logging
An ESLint plugin that requires logging statements in all functions.
Installation
You can install the plugin using npm:
npm install eslint-plugin-require-logging --save-dev
Usage
Add require-logging to the plugins section of your ESLint configuration file, and then configure the rule to suit your needs.
.eslintrc.json
{
"plugins": ["require-logging"],
"rules": {
"require-logging/require-logging": [
"warn",
{
"smallFunctionMaxLines": 5,
"smallFunctionLogs": { "debug": 1, "info": 1, "warn": 0, "error": 0, "verbose": 0 },
"largeFunctionLogs": { "debug": 2, "info": 1, "warn": 1, "error": 0, "verbose": 0 }
}
]
}
}
Rule Options
smallFunctionMaxLines
: The maximum number of lines for a function to be considered small.
smallFunctionLogs
: An object specifying the required number of log statements for small functions.
largeFunctionLogs
: An object specifying the required number of log statements for large functions.
Each log configuration object can have the following properties:
debug
: Number of required debug log statements.
info
: Number of required info log statements.
warn
: Number of required warn log statements.
error
: Number of required error log statements.
verbose
: Number of required verbose log statements.
Examples
Valid
function fetchData() {
console.debug('Fetching data...');
console.info('Data fetched');
return data;
}
const fetchDataFunc = function() {
Logger.debug('Fetching data...');
Logger.info('Data fetched');
return data;
};
Invalid
function fetchData() {
console.debug('Fetching data...');
return data;
}
// ESLint will report: "Function [fetchData] is missing required logging statements. Expected 1 info log(s), found 0."
License
MIT