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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded checks #638

Merged
merged 4 commits into from Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/rules/prefer-to-have-length.ts
Expand Up @@ -40,8 +40,7 @@ export default createRule({
if (
!matcher ||
!isParsedEqualityMatcherCall(matcher) ||
!argument ||
argument.type !== AST_NODE_TYPES.MemberExpression ||
argument?.type !== AST_NODE_TYPES.MemberExpression ||
!isSupportedAccessor(argument.property, 'length') ||
argument.property.type !== AST_NODE_TYPES.Identifier
) {
Expand Down
4 changes: 1 addition & 3 deletions src/rules/require-to-throw-message.ts
Expand Up @@ -30,9 +30,7 @@ export default createRule({
const { matcher, modifier } = parseExpectCall(node);

if (
matcher &&
matcher.arguments &&
matcher.arguments.length === 0 &&
matcher?.arguments?.length === 0 &&
['toThrow', 'toThrowError'].includes(matcher.name) &&
(!modifier ||
!(modifier.name === ModifierName.not || modifier.negation))
Expand Down
7 changes: 3 additions & 4 deletions src/rules/utils.ts
Expand Up @@ -300,11 +300,10 @@ interface ParsedExpectMember<
* Represents a `MemberExpression` that comes after an `ExpectCall`.
*/
interface ExpectMember<
PropertyName extends ExpectPropertyName = ExpectPropertyName,
Parent extends TSESTree.Node | undefined = TSESTree.Node | undefined
PropertyName extends ExpectPropertyName = ExpectPropertyName
> extends KnownMemberExpression<PropertyName> {
object: ExpectCall | ExpectMember;
parent: Parent;
parent: TSESTree.Node;
}

export const isExpectMember = <
Expand All @@ -326,7 +325,7 @@ export type ParsedEqualityMatcherCall<
Argument extends TSESTree.Expression = TSESTree.Expression,
Matcher extends EqualityMatcher = EqualityMatcher
> = Omit<ParsedExpectMatcher<Matcher>, 'arguments'> & {
// todo: probs should also type node parent as CallExpression
parent: TSESTree.CallExpression;
arguments: [Argument];
};

Expand Down
5 changes: 2 additions & 3 deletions src/rules/valid-expect.ts
Expand Up @@ -230,7 +230,7 @@ export default createRule<
return;
}

if (matcher.node.parent && isExpectMember(matcher.node.parent)) {
if (isExpectMember(matcher.node.parent)) {
context.report({
messageId: 'modifierUnknown',
data: { modifierName: matcher.name },
Expand All @@ -250,9 +250,8 @@ export default createRule<
const parentNode = matcher.node.parent;

if (
!modifier ||
!parentNode ||
!parentNode.parent ||
!modifier ||
modifier.name === ModifierName.not
) {
return;
Expand Down