eslint-plugin-pino
raw JSON → 1.0.3 verified Sat Apr 25 auth: no javascript
ESLint plugin for enforcing correct pino logger usage patterns in Node.js applications. Currently at version 1.0.3 (released Oct 2024), maintained actively, with TypeScript type declarations included. Unlike generic ESLint rules, this plugin targets pino-specific conventions such as requiring object arguments before message strings in logging calls. It provides auto-fixable rules and a recommended configuration. Requires ESLint >=7.0.0 and Node >=14.0.0.
Common errors
error Error: Plugin 'pino' was conflicted between '...' and '...' ↓
cause Duplicate plugin declaration in ESLint config (e.g., in both plugins and extends).
fix
Remove the duplicate plugin entry; keep only in
plugins array or only in extends. error Invalid option '...' for rule 'pino/correct-args-position' ↓
cause The rule does not accept any options in v1.0.0.
fix
Remove the options object from the rule configuration: just set
"pino/correct-args-position": "error". error TypeError: Cannot read properties of undefined (reading 'type') ↓
cause The rule encounters an AST node that is not a CallExpression (e.g., a member expression not followed by call).
fix
Ensure the logger method is called with parentheses; e.g.,
logger.info without parentheses will be ignored but may cause unexpected errors in older versions. error ESLint: Configuration for rule 'pino/no-undefined-args' is invalid ↓
cause Rule was removed in v1.0.0.
fix
Replace 'pino/no-undefined-args' with 'pino/correct-args-position'.
Warnings
gotcha Rule only checks calls on pino logger instances; it cannot detect if a variable is a pino logger unless it's named 'logger' or recognized via type inference. ↓
fix Ensure your pino logger variable is named `logger` or use TypeScript types for inference.
deprecated The rule `no-undefined-args` was deprecated in v0.5.0 and removed in v1.0.0; use `correct-args-position` instead. ↓
fix Replace 'pino/no-undefined-args' with 'pino/correct-args-position' in your ESLint config.
gotcha Auto-fix may reorder arguments incorrectly if there are multiple objects or function calls; manual review recommended. ↓
fix Review auto-fix changes, especially in complex expressions.
breaking Plugin now exports as ESM; CommonJS `require()` works but may cause issues in some Node versions prior to v16. ↓
fix If using `require`, ensure Node >=14 or switch to ES import.
gotcha The `recommended` config only includes `correct-args-position`. Other rules must be added manually. ↓
fix Check documentation for additional rules and add them explicitly if needed.
Install
npm install eslint-plugin-pino yarn add eslint-plugin-pino pnpm add eslint-plugin-pino Imports
- default wrong
const pinoPlugin = require('eslint-plugin-pino')correctimport pinoPlugin from 'eslint-plugin-pino' - rules
import { rules } from 'eslint-plugin-pino' - configs wrong
import configs from 'eslint-plugin-pino'correctimport { configs } from 'eslint-plugin-pino'
Quickstart
// .eslintrc.json
{
"plugins": ["pino"],
"rules": {
"pino/correct-args-position": "error"
}
}
// Example file: logger.js
import pino from 'pino';
const logger = pino();
// ✅ Correct
logger.info({userId: 123}, 'User logged in');
// ❌ Incorrect
logger.info('User logged in', {userId: 123});
// Run: npx eslint . --fix