Skip to content

Commit

Permalink
fix(valid-expect-in-promise): handle sparse arrays (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Jan 6, 2023
1 parent 35b0e6f commit 21e72c9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 50 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
92 changes: 46 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2730,12 +2730,12 @@ __metadata:
linkType: hard

"@typescript-eslint/eslint-plugin@npm:^5.0.0":
version: 5.47.0
resolution: "@typescript-eslint/eslint-plugin@npm:5.47.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,67 +2748,67 @@ __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"
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

"@typescript-eslint/scope-manager@npm:5.47.0":
version: 5.47.0
resolution: "@typescript-eslint/scope-manager@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/types": 5.47.0
"@typescript-eslint/visitor-keys": 5.47.0
checksum: f637268a4cb065a89bb53d72620cc553f8c0d9f00805d6e6aac558cc4d3c08f3329208b0b4d5566d21eb636b080d453e5890221baef0e4bc4d67251f07cccd0d
"@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.47.0":
version: 5.47.0
resolution: "@typescript-eslint/type-utils@npm:5.47.0"
"@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.47.0
"@typescript-eslint/utils": 5.47.0
"@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

"@typescript-eslint/types@npm:5.47.0":
version: 5.47.0
resolution: "@typescript-eslint/types@npm:5.47.0"
checksum: 5a856e190cc2103427dbe15ccbbf87238261b5ed0859390a9e55f93afc2057f79dcbb4ac0db4d35787466f5e73f271111d19b2e725cf444af41d30e09678bf7a
"@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"
"@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.47.0
"@typescript-eslint/visitor-keys": 5.47.0
"@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
Expand All @@ -2817,35 +2817,35 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: a9adfe8955b7dc9dfa9f43d450b782b83f506eaadae2a13f4e1bbe6c733be446d3edb26910954aec1bdc60d94ecc55c4e200d5b19bb24e6742f02329a4fb3e8c
checksum: 2444632243111e51bc83b56140514cb5978bef4d7151fede0dfcff8808afc1ad335b0c60ca86c2811bcc82273b87e59e2e0360bf1b8c014825ff818a1731d127
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":
version: 5.47.0
resolution: "@typescript-eslint/utils@npm:5.47.0"
"@typescript-eslint/utils@npm:5.48.0, @typescript-eslint/utils@npm:^5.10.0, @typescript-eslint/utils@npm:^5.38.1":
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.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
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: f168920eec6f77651107f190b4ecadd82951fe4e3c0321ff660ac7380f4315d5ae30a1b63b4d2818f5e6f007a3f34c5df202619c24ec3a7e2ef25b215ec7b813
checksum: 53f512ae61f72c2b29f2daf8adbc1f37c400cc71156557f69f0745b62c1265d99917a168245e2ee3d88ae458144818d1bf41ced4a764d7d9534b466b29d362fd
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.47.0":
version: 5.47.0
resolution: "@typescript-eslint/visitor-keys@npm:5.47.0"
"@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.47.0
"@typescript-eslint/types": 5.48.0
eslint-visitor-keys: ^3.3.0
checksum: 2191c079154bdfd1b85b8cd24baa6c0f55c73527c6c8460789483555b4eb5c72e3dc6d1aa4bbac2cf7b86b474588b45682a8deb151e9d903cf72c8f336141f1f
checksum: 8d41fb7c93b79df415b43c31da7c9007074d78ab6f16c2d318c23e7974b578ce510f466a9584bd67c526367666974091cb5cfbf6670d29e36fb4ab2e57137515
languageName: node
linkType: hard

Expand Down

0 comments on commit 21e72c9

Please sign in to comment.