@mimik/eslint-plugin-logger 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ logger.info('User logged in', { userId: 123 }, correlationId, { type: 'audit' })
|
|
|
87
87
|
- `message` must be a string (when passed as a literal)
|
|
88
88
|
- `correlationId` must be a string (when passed as a literal)
|
|
89
89
|
- `options` object must contain a `type` property with a string value
|
|
90
|
+
- When 2 arguments are passed and the 2nd is an object literal, it is treated as `(message, meta)` with a missing `correlationId`
|
|
90
91
|
- When 3 arguments are passed, the 2nd argument type determines the signature:
|
|
91
92
|
- Object literal → `(message, meta, correlationId)`
|
|
92
93
|
- Otherwise → `(message, correlationId, options)`
|
package/index.js
CHANGED
|
@@ -126,6 +126,7 @@ const plugin = {
|
|
|
126
126
|
tooManyArguments: 'logger.{{ level }}() accepts at most 4 arguments: (message, meta, correlationId, options). Found {{ count }}.',
|
|
127
127
|
messageNotString: 'logger.{{ level }}() message (1st argument) must be a string. Found {{ actualType }}.',
|
|
128
128
|
correlationIdNotString: 'logger.{{ level }}() correlationId must be a string. Found {{ actualType }}.',
|
|
129
|
+
missingCorrelationId: 'logger.{{ level }}() called with (message, meta) but missing required correlationId. Expected (message, meta, correlationId).',
|
|
129
130
|
optionsMissingType: 'logger.{{ level }}() options object must contain a "type" property.',
|
|
130
131
|
optionsTypeNotString: 'logger.{{ level }}() options "type" property must be a string.',
|
|
131
132
|
},
|
|
@@ -170,8 +171,18 @@ const plugin = {
|
|
|
170
171
|
validateStringArg(context, args[0], level, 'messageNotString');
|
|
171
172
|
|
|
172
173
|
if (args.length === MIN_ARGS) {
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
if (isObjectNode(args[1]) || args[1].type === 'ArrayExpression') {
|
|
175
|
+
// (message, {object}) or (message, [array]) — missing correlationId
|
|
176
|
+
context.report({
|
|
177
|
+
node,
|
|
178
|
+
messageId: 'missingCorrelationId',
|
|
179
|
+
data: { level },
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// (message, correlationId)
|
|
184
|
+
validateStringArg(context, args[1], level, 'correlationIdNotString');
|
|
185
|
+
}
|
|
175
186
|
}
|
|
176
187
|
else if (args.length === THREE_ARGS) {
|
|
177
188
|
// Disambiguate: (message, meta, correlationId) vs (message, correlationId, options)
|