@noctcore/eslint-plugin-observability
Structured-logging discipline rules: context objects over interpolated messages, no sensitive fields
in logs, no error-detail loss, and declared event identifiers.
Docs: noctcore.github.io/eslint-plugins/packages/observability
Not a good fit for a codebase that logs through console by design, or whose logger cannot carry a
context object.
Requirements
- ESLint 9 or 10, flat config (
eslint.config.js) only.
configs.recommended registers the plugin and sets rule severities, nothing else. It sets no
files and no parser, so it applies to whatever files the rest of your config lints. To lint
TypeScript, add a files pattern and @typescript-eslint/parser, as in the quick start.
Install
bun add -D @noctcore/eslint-plugin-observability @typescript-eslint/parser # or npm i -D / pnpm add -D
Quick start
// eslint.config.js
import tsParser from '@typescript-eslint/parser';
import observability from '@noctcore/eslint-plugin-observability';
export default [
{
...observability.configs.recommended,
files: ['**/*.{ts,tsx}'],
languageOptions: { parser: tsParser },
},
// Optional: tune a preset rule's options.
{
files: ['**/*.{ts,tsx}'],
rules: {
'noctcore-observability/structured-log-arguments': ['error', { loggers: ['log', 'audit'] }],
},
},
];
Opt-in rules
Three rules are left out of recommended. audit-pii-declared is inert until auditCallees names
your audit writes. require-event-field and typed-event-names enforce a convention (a declared
event identifier on every log line) rather than a defect every codebase has, and
typed-event-names needs the module that declares the names:
// eslint.config.js
export default [
// ...the quick start's entries, then:
{
files: ['**/*.{ts,tsx}'],
languageOptions: { parser: tsParser },
rules: {
'noctcore-observability/audit-pii-declared': ['error', {
auditCallees: ['auditService.log'],
registeredFields: ['email', 'newEmail'],
}],
'noctcore-observability/require-event-field': 'error',
'noctcore-observability/typed-event-names': ['error', {
eventNamesModule: 'src/log-events.ts',
}],
},
},
];
Rules
✅ on in recommended (error) · 🔘 opt-in: not on in recommended, enable it yourself · ⚙️ needs options · 🔧 --fix · 💡 suggestions · 💭 needs type info · ❌ deprecated
| Rule |
Description |
Preset |
⚙️ |
🔧 |
💡 |
💭 |
audit-pii-declared |
A PII-shaped key written into an audit payload must be declared, either registered for scrubbing on purge or declared non-PII. |
🔘 |
⚙️ |
|
|
|
no-error-detail-loss |
A catch block that reports a failure must not reduce the error to only e.message / String(e) / ${e}. Log the error itself so its stack and cause survive. |
✅ |
|
|
|
|
no-sensitive-fields-in-logs |
A logger call must not reference an identifier, property, or object key whose name matches a sensitive-field denylist (password, token, secret, ...). Redact it before logging. |
✅ |
|
|
|
|
require-event-field |
A logger call must carry a stable event identifier in its structured payload, so log searches, dashboards and alerts do not match on message text. |
🔘 |
|
|
|
|
structured-log-arguments |
A logger call must not interpolate dynamic values into the message string (a template literal with expressions). Pass a static message and a structured context object instead. |
✅ |
|
|
|
|
typed-event-names |
The event field of a logger call must be a name declared in the project event names module, so a typo or a stale name fails at lint time. |
🔘 |
⚙️ |
|
|
|
Severity policy
Every rule is error or off, never warn: a warning is a rule nobody obeys. See the
severity policy.