diff --git a/rules/throw-new-error.js b/rules/throw-new-error.js index 5c509795cb..723ec45c07 100644 --- a/rules/throw-new-error.js +++ b/rules/throw-new-error.js @@ -1,5 +1,8 @@ 'use strict'; -const {switchCallExpressionToNewExpression} = require('./fix/index.js'); +const { + switchCallExpressionToNewExpression, + fixSpaceAroundKeyword, +} = require('./fix/index.js'); const messageId = 'throw-new-error'; const messages = { @@ -27,7 +30,10 @@ const create = context => ({ return { node, messageId, - fix: fixer => switchCallExpressionToNewExpression(node, context.sourceCode, fixer), + * fix(fixer) { + yield * fixSpaceAroundKeyword(fixer, node, context.sourceCode); + yield * switchCallExpressionToNewExpression(node, context.sourceCode, fixer); + } }; }, }); diff --git a/test/snapshots/throw-new-error.mjs.md b/test/snapshots/throw-new-error.mjs.md index 6cacad0b0b..903b034a02 100644 --- a/test/snapshots/throw-new-error.mjs.md +++ b/test/snapshots/throw-new-error.mjs.md @@ -549,7 +549,7 @@ Generated by [AVA](https://avajs.dev). `␊ 1 | function foo() {␊ - 2 | new returnnew [globalThis][0].Error('message');␊ + 2 | return new [globalThis][0].Error('message');␊ 3 | }␊ ` diff --git a/test/snapshots/throw-new-error.mjs.snap b/test/snapshots/throw-new-error.mjs.snap index 15e21ff961..84e6045ed9 100644 Binary files a/test/snapshots/throw-new-error.mjs.snap and b/test/snapshots/throw-new-error.mjs.snap differ