chore(eslint): payload-logger proper usage works with template literals (#8660)
Improves this https://github.com/payloadcms/payload/pull/8578 to work with template literals as well, This is invalid: ```ts this.payload.logger.error('Failed to create database', err) ``` But this is valid: ```ts this.payload.logger.error(`Failed to create database ${dbName}`, err) ``` This PR fixes that <img width="577" alt="image" src="https://github.com/user-attachments/assets/b867da53-4f81-4b1b-8423-598e0419946a">
This commit is contained in:
@@ -14,6 +14,10 @@ ruleTester.run('no-improper-payload-logger-error', rule, {
|
||||
{
|
||||
code: "payload.logger.error('Some error message')",
|
||||
},
|
||||
// Valid: payload.logger.error with a templated string
|
||||
{
|
||||
code: 'payload.logger.error(`Some error message`)',
|
||||
},
|
||||
// Valid: *.payload.logger.error with object
|
||||
{
|
||||
code: "this.payload.logger.error({ msg: 'another message', err })",
|
||||
@@ -33,6 +37,15 @@ ruleTester.run('no-improper-payload-logger-error', rule, {
|
||||
},
|
||||
],
|
||||
},
|
||||
// Invalid: payload.logger.error with both templated string and error
|
||||
{
|
||||
code: 'payload.logger.error(`Some error message`, err)',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'improperUsage',
|
||||
},
|
||||
],
|
||||
},
|
||||
// Invalid: *.payload.logger.error with both string and error
|
||||
{
|
||||
code: "this.payload.logger.error('Some error message', error)",
|
||||
|
||||
Reference in New Issue
Block a user