npm package: @mimik/eslint-plugin-logger
Description: Validation of logger call parameters for mimik services
Author: mimik technology inc
Latest version: 1.0.4

# @mimik/eslint-plugin-logger

ESLint plugin that validates logger call arguments for mimik services.

## Installation

```bash
npm install --save-dev @mimik/eslint-plugin-logger
```

## Usage

Add the plugin to your `eslint.config.js`:

```js
import loggerPlugin from '@mimik/eslint-plugin-logger';

export default [
  {
    plugins: { logger: loggerPlugin },
    rules: {
      'logger/validate-logger-args': 'error',
    },
  },
];
```

## Rule: `validate-logger-args`

Validates that logger calls (on default-imported modules) use the correct argument signatures.

### Valid Signatures

All three access patterns are supported:

```js
import logger from '@mimik/sumologic-winston-logger';

// Dot notation
logger.info('User logged in', correlationId);

// Bracket notation with string literal
logger['info']('User logged in', correlationId);

// Bracket notation with variable (any variable name)
logger[level]('User logged in', correlationId);
logger[severity]('User logged in', correlationId);
```

The four argument signatures:

```js
// (message, correlationId)
logger.info('User logged in', correlationId);

// (message, meta, correlationId)
logger.info('User logged in', { userId: 123 }, correlationId);

// (message, correlationId, options)
logger.info('User logged in', correlationId, { type: 'audit' });

// (message, meta, correlationId, options)
logger.info('User logged in', { userId: 123 }, correlationId, { type: 'audit' });
```

### Arguments

| Argument | Type | Required | Description |
|---|---|---|---|
| `message` | `string` | Yes | Log message |
| `meta` | `object` | No | Metadata object with additional context |
| `correlationId` | `string` | Yes | Correlation ID for request tracing |
| `options` | `object` | No | Options object, must contain a `type` string property |

### Supported Log Levels

`error`, `warn`, `info`, `verbose`, `debug`, `silly`

### What Gets Checked

- The rule only applies to **default imports** (e.g. `import logger from '...'`)
- Named imports (`import { logger } from '...'`) are ignored
- Supports dot notation (`logger.info`), bracket notation with a string literal (`logger['info']`), and bracket notation with a variable (`logger[level]`)
- For bracket notation with a string literal, the value must be a recognized log level
- For bracket notation with a variable, the call is always validated (the variable is assumed to hold a valid level)
- Minimum 2 arguments, maximum 4
- `message` must be a string (when passed as a literal)
- `correlationId` must be a string (when passed as a literal)
- `options` object must contain a `type` property with a string value
- When 2 arguments are passed and the 2nd is an object or array literal, it is treated as `(message, meta)` with a missing `correlationId`
- When 3 arguments are passed, the 2nd argument type determines the signature:
  - Object literal → `(message, meta, correlationId)`
  - Otherwise → `(message, correlationId, options)`

## API Reference

The plugin exports a single object with the following shape:

```js
{
  rules: {
    'validate-logger-args': { meta, create(context) }
  }
}
```

### Error Messages

| Message ID | Description |
|---|---|
| `tooFewArguments` | Fewer than 2 arguments passed |
| `tooManyArguments` | More than 4 arguments passed |
| `messageNotString` | First argument is a non-string literal |
| `correlationIdNotString` | correlationId argument is a non-string literal |
| `missingCorrelationId` | 2nd argument is an object or array — correlationId is missing |
| `optionsNotObject` | Options argument is a literal instead of an object |
| `optionsMissingType` | Options object does not contain a `type` property |
| `optionsTypeNotString` | Options `type` property is a non-string literal |

## License

MIT