Skip to content

Commit 2bd6cba

Browse files
Fix: incorrect no-deprecated-report-api autofix if > 5 arguments passed
1 parent 937bafa commit 2bd6cba

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/rules/no-deprecated-report-api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ module.exports = {
4747
fix (fixer) {
4848
const openingParen = sourceCode.getTokenBefore(node.arguments[0]);
4949
const closingParen = sourceCode.getLastToken(node);
50-
const keyNames = node.arguments.length === 5
50+
const keys = node.arguments.length >= 5
5151
? ['node', 'loc', 'message', 'data', 'fix']
5252
: ['node', 'message', 'data', 'fix'];
5353

5454
return fixer.replaceTextRange(
5555
[openingParen.range[1], closingParen.range[0]],
56-
'{' + node.arguments.map((arg, index) => `${keyNames[index]}: ${sourceCode.getText(arg)}`).join(', ') + '}'
56+
`{${node.arguments.slice(0, 5).map((arg, index) => `${keys[index]}: ${sourceCode.getText(arg)}`).join(', ')}}`
5757
);
5858
},
5959
});

tests/lib/rules/no-deprecated-report-api.js

+17
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,22 @@ ruleTester.run('no-deprecated-report-api', rule, {
214214
`,
215215
errors: [ERROR],
216216
},
217+
{
218+
code: `
219+
module.exports = {
220+
create(context) {
221+
context.report(theNode, theLocation, theMessage, theData, theFix, somethingElse, somethingElse, somethingElse);
222+
}
223+
};
224+
`,
225+
output: `
226+
module.exports = {
227+
create(context) {
228+
context.report({node: theNode, loc: theLocation, message: theMessage, data: theData, fix: theFix});
229+
}
230+
};
231+
`,
232+
errors: [ERROR],
233+
},
217234
],
218235
});

0 commit comments

Comments
 (0)