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(expect-single-argument): fix error when providing no arguments an… #375

Merged

Conversation

TimZM
Copy link
Contributor

@TimZM TimZM commented Sep 18, 2024

Description

The change to the expect-single-argument rule in #373 crashes when you have an expect without a matcher, as pointed out by KayKadner on that PR. By using optional chaining this rule can now handle expect without a subsequent matcher.

How has this been tested?

I've added tests for cases where there is no matcher. These indeed threw an error before applying the fix in this PR.

Types of changes

  • Test change (non-breaking change which adds additional test scenarios)
  • Refactor change (non-breaking change updates coding styles)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have ran npm run test and everything passes
  • My code follows the code style of this project
  • I have updated the documentation where necessary
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests pass

Copy link

@KayKadner KayKadner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reply.

@@ -14,7 +14,7 @@ function create (context) {
message: 'Expect must have a single argument. More than one argument were provided.',
node
})
} else if (node.arguments.length === 0 && node.parent.property.name !== 'nothing') {
} else if (node.arguments.length === 0 && node.parent?.property?.name !== 'nothing') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parent-? is not needed, as the CallExpression is always child of something, at least an ExpressionStatement. But it also does not hurt. The property-? fixes it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed unnecessary. I've removed the optional chaining operator after the parent.

@TimZM TimZM changed the title fix(expect-single-argument): Fix error when providing no arguments an… fix(expect-single-argument): fix error when providing no arguments an… Sep 18, 2024
@TimZM TimZM force-pushed the fix/expect-single-argument-without-matcher branch from ef2c10c to f74d579 Compare September 18, 2024 16:16
@tlvince tlvince merged commit 48fb2f3 into tlvince:master Sep 18, 2024
1 check passed
Copy link

🎉 This PR is included in version 4.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants