Skip to content

Commit

Permalink
fix(valid-expect-in-promise): handle sparse arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jan 6, 2023
1 parent d566516 commit bb666f7
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 28 deletions.
11 changes: 11 additions & 0 deletions src/rules/__tests__/valid-expect-in-promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ ruleTester.run('valid-expect-in-promise', rule, {
return number + 1;
});
expect([,,await promise,,]).toHaveLength(1);
});
`,
dedent`
it('is valid', async () => {
const promise = loadNumber().then(number => {
expect(typeof number).toBe('number');
return number + 1;
});
expect([[await promise]]).toHaveLength(1);
});
`,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-spy-on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRule, getNodeName } from './utils';

const findNodeObject = (
node: TSESTree.CallExpression | TSESTree.MemberExpression,
): TSESTree.LeftHandSideExpression | null => {
): TSESTree.Expression | null => {
if ('object' in node) {
return node.object;
}
Expand Down
6 changes: 3 additions & 3 deletions src/rules/valid-expect-in-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const isPromiseMethodThatUsesValue = (

if (
firstArg.type === AST_NODE_TYPES.ArrayExpression &&
firstArg.elements.some(nod => isIdentifier(nod, name))
firstArg.elements.some(nod => nod && isIdentifier(nod, name))
) {
return true;
}
Expand Down Expand Up @@ -128,14 +128,14 @@ const isValueAwaitedInElements = (
): boolean => {
for (const element of elements) {
if (
element.type === AST_NODE_TYPES.AwaitExpression &&
element?.type === AST_NODE_TYPES.AwaitExpression &&
isIdentifier(element.argument, name)
) {
return true;
}

if (
element.type === AST_NODE_TYPES.ArrayExpression &&
element?.type === AST_NODE_TYPES.ArrayExpression &&
isValueAwaitedInElements(name, element.elements)
) {
return true;
Expand Down
111 changes: 87 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2729,13 +2729,13 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/eslint-plugin@npm:^5.0.0":
version: 5.47.0
resolution: "@typescript-eslint/eslint-plugin@npm:5.47.0"
"@typescript-eslint/eslint-plugin@npm:^5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/eslint-plugin@npm:5.48.0"
dependencies:
"@typescript-eslint/scope-manager": 5.47.0
"@typescript-eslint/type-utils": 5.47.0
"@typescript-eslint/utils": 5.47.0
"@typescript-eslint/scope-manager": 5.48.0
"@typescript-eslint/type-utils": 5.48.0
"@typescript-eslint/utils": 5.48.0
debug: ^4.3.4
ignore: ^5.2.0
natural-compare-lite: ^1.4.0
Expand All @@ -2748,24 +2748,24 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: fd867eb2b668d1f476fd28d38c2df2a680bf510a265a6e714b28d8f77e7a37e74e32294b70262a6fd1aec99ddb2fddef0212c862b4465ca4f83bb1172476f6e7
checksum: cb9cd62fd56670414795e30d30c9fa11ec7ad3a8b0abda48dd17625053a1c26ba1767184b096149bdd0ccb457bec6392306f22211b75f802f4b27366398d16eb
languageName: node
linkType: hard

"@typescript-eslint/parser@npm:^5.0.0":
version: 5.47.0
resolution: "@typescript-eslint/parser@npm:5.47.0"
"@typescript-eslint/parser@npm:^5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/parser@npm:5.48.0"
dependencies:
"@typescript-eslint/scope-manager": 5.47.0
"@typescript-eslint/types": 5.47.0
"@typescript-eslint/typescript-estree": 5.47.0
"@typescript-eslint/scope-manager": 5.48.0
"@typescript-eslint/types": 5.48.0
"@typescript-eslint/typescript-estree": 5.48.0
debug: ^4.3.4
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
peerDependenciesMeta:
typescript:
optional: true
checksum: 5c864ca74b86ca740c73e5b87d90d43bb832b20ba6be0a39089175435771527722a7bf0a8ef7ddbd64b85235fbb7f6dbe8ae55a8bc73c6242f5559d580a8a80c
checksum: 41d5ce5c8742d286fb083523295a4f186e57bbe4e3da63b6b2de1edbafbcbf6d5225ed3405da2c56e2b0fe1d52bb72babc37508d2ee9b86f6fadad3c4a7950d0
languageName: node
linkType: hard

Expand All @@ -2779,20 +2779,30 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/type-utils@npm:5.47.0":
version: 5.47.0
resolution: "@typescript-eslint/type-utils@npm:5.47.0"
"@typescript-eslint/scope-manager@npm:5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/scope-manager@npm:5.48.0"
dependencies:
"@typescript-eslint/typescript-estree": 5.47.0
"@typescript-eslint/utils": 5.47.0
"@typescript-eslint/types": 5.48.0
"@typescript-eslint/visitor-keys": 5.48.0
checksum: 96c0ce33d613490690ae6f34e4152f05dbddf3196a6dec89afba4a63cd2d828ae23a98262920b521fe461e7655d38f3a01e9e43588c12392a27bf8cb4f8ae201
languageName: node
linkType: hard

"@typescript-eslint/type-utils@npm:5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/type-utils@npm:5.48.0"
dependencies:
"@typescript-eslint/typescript-estree": 5.48.0
"@typescript-eslint/utils": 5.48.0
debug: ^4.3.4
tsutils: ^3.21.0
peerDependencies:
eslint: "*"
peerDependenciesMeta:
typescript:
optional: true
checksum: 504b3e883ac02cb8e69957b706e76cb79fa2192aa62702c2a658119f28f8f50f1e668efb62318e85aeda6522e1d948b59382cae4ef3300a3f4eea809a87dec26
checksum: 0d57e3bbcaa46e29b588b86b2271341b264f063e71ff5b6d4d35f50f2fe11bd6cdc3c4c95d78493fd17673ecdbd712992b84da1600947ed3bf6ae09de7b99464
languageName: node
linkType: hard

Expand All @@ -2803,6 +2813,13 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/types@npm:5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/types@npm:5.48.0"
checksum: fa27bd9ec7ec5f256b79a371bb05cfbc26902b6a395f38b0cff0e281633ebd76775ad18e41be1bb156868859287295f6833a2a671da57c6347ac7c6bc08a553b
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:5.47.0":
version: 5.47.0
resolution: "@typescript-eslint/typescript-estree@npm:5.47.0"
Expand All @@ -2821,7 +2838,43 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:5.47.0, @typescript-eslint/utils@npm:^5.10.0, @typescript-eslint/utils@npm:^5.38.1":
"@typescript-eslint/typescript-estree@npm:5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/typescript-estree@npm:5.48.0"
dependencies:
"@typescript-eslint/types": 5.48.0
"@typescript-eslint/visitor-keys": 5.48.0
debug: ^4.3.4
globby: ^11.1.0
is-glob: ^4.0.3
semver: ^7.3.7
tsutils: ^3.21.0
peerDependenciesMeta:
typescript:
optional: true
checksum: 2444632243111e51bc83b56140514cb5978bef4d7151fede0dfcff8808afc1ad335b0c60ca86c2811bcc82273b87e59e2e0360bf1b8c014825ff818a1731d127
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:5.48.0, @typescript-eslint/utils@npm:^5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/utils@npm:5.48.0"
dependencies:
"@types/json-schema": ^7.0.9
"@types/semver": ^7.3.12
"@typescript-eslint/scope-manager": 5.48.0
"@typescript-eslint/types": 5.48.0
"@typescript-eslint/typescript-estree": 5.48.0
eslint-scope: ^5.1.1
eslint-utils: ^3.0.0
semver: ^7.3.7
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
checksum: 53f512ae61f72c2b29f2daf8adbc1f37c400cc71156557f69f0745b62c1265d99917a168245e2ee3d88ae458144818d1bf41ced4a764d7d9534b466b29d362fd
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:^5.38.1":
version: 5.47.0
resolution: "@typescript-eslint/utils@npm:5.47.0"
dependencies:
Expand Down Expand Up @@ -2849,6 +2902,16 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.48.0":
version: 5.48.0
resolution: "@typescript-eslint/visitor-keys@npm:5.48.0"
dependencies:
"@typescript-eslint/types": 5.48.0
eslint-visitor-keys: ^3.3.0
checksum: 8d41fb7c93b79df415b43c31da7c9007074d78ab6f16c2d318c23e7974b578ce510f466a9584bd67c526367666974091cb5cfbf6670d29e36fb4ab2e57137515
languageName: node
linkType: hard

"JSONStream@npm:^1.0.4, JSONStream@npm:^1.3.5":
version: 1.3.5
resolution: "JSONStream@npm:1.3.5"
Expand Down Expand Up @@ -4655,9 +4718,9 @@ __metadata:
"@types/jest": ^29.0.0
"@types/node": ^14.18.26
"@types/prettier": ^2.0.0
"@typescript-eslint/eslint-plugin": ^5.0.0
"@typescript-eslint/parser": ^5.0.0
"@typescript-eslint/utils": ^5.10.0
"@typescript-eslint/eslint-plugin": ^5.48.0
"@typescript-eslint/parser": ^5.48.0
"@typescript-eslint/utils": ^5.48.0
babel-jest: ^29.0.0
babel-plugin-replace-ts-export-assignment: ^0.0.2
dedent: ^0.7.0
Expand Down

0 comments on commit bb666f7

Please sign in to comment.