eslint-logging-rules
v1.0.2
Published
A custom ESLint plugin providing rules to enforce best practices for error handling, logging, and consistent code structure in JavaScript/Node.js projects.
Downloads
11
Readme
Custom ESLint Rules Plugin
A custom ESLint plugin providing rules to enforce best practices for error handling, logging, and consistent code structure in JavaScript/Node.js projects.
catch-rule
: Ensures all Promises have a proper.catch
block to handle errors.custom-fields-rule
: Enforces the inclusion of custom fields (timestamp, application, system, severity, reason, category) in logs.json-log-rule
: Validates that logs are in a consistent JSON format for easier parsing by log management tools.return-rule
: Ensures functions explicitly return a value.then-rule
: Enforces consistent structure for.then
chains in Promises, preventing deeply nested chains and ensuring correct returns.
npm install eslint-logging-rules --save-dev
import eslintPluginCustomRules from "eslint-logging-rules"; // Import your custom rules plugin
- Enable the rules you want to enforce in the rules section:
{
plugins: {
customRules: eslintPluginCustomRules,
},
rules: {
"customRules/return-rule": "warn",
"customRules/json-log-rule": "warn",
"customRules/custom-fields-rule": "warn",
"customRules/catch-rule": "warn",
"customRules/then-rule": "warn",
},
},