Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: produce valid code when when fixing properties accessed with square brackets #1131

Merged
merged 6 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(prefer-todo): support fixing indexed property access
  • Loading branch information
G-Rath committed May 28, 2022
commit 5ecd4dd080dbbcbdb7d75da31e90d506959f83f5
10 changes: 10 additions & 0 deletions src/rules/__tests__/prefer-todo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,15 @@ ruleTester.run('prefer-todo', rule, {
output: 'test.todo("i need to write this test");',
errors: [{ messageId: 'emptyTest' }],
},
{
code: `test["skip"]("i need to write this test", function() {});`,
output: 'test[\'todo\']("i need to write this test");',
errors: [{ messageId: 'emptyTest' }],
},
{
code: `test[\`skip\`]("i need to write this test", function() {});`,
output: 'test[\'todo\']("i need to write this test");',
errors: [{ messageId: 'emptyTest' }],
},
],
});
20 changes: 9 additions & 11 deletions src/rules/prefer-todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ function createTodoFixer(
jestFnCall: ParsedJestFnCall,
fixer: TSESLint.RuleFixer,
) {
const fixes = [
fixer.replaceText(jestFnCall.head.node, `${jestFnCall.head.local}.todo`),
];

if (jestFnCall.members.length) {
fixes.unshift(
fixer.removeRange([
jestFnCall.head.node.range[1],
jestFnCall.members[0].range[1],
]),
);
const text =
jestFnCall.members[0].type === AST_NODE_TYPES.Identifier
? 'todo'
: "'todo'";

return [fixer.replaceText(jestFnCall.members[0], text)];
}

return fixes;
return [
fixer.replaceText(jestFnCall.head.node, `${jestFnCall.head.local}.todo`),
];
}

const isTargetedTestCase = (jestFnCall: ParsedJestFnCall): boolean => {
Expand Down