no_unneeded_async_expect_function

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoUnneededAsyncExpectFunctionRule = rule.Rule{
	Name: "jest/no-unneeded-async-expect-function",
	Run: func(ctx rule.RuleContext, options []any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindCallExpression: func(node *ast.Node) {
				jestFnCall := jestUtils.ParseJestFnCall(node, ctx)
				if jestFnCall == nil ||
					jestFnCall.Kind != jestUtils.JestFnTypeExpect ||
					!hasPromiseExpectModifier(jestFnCall) {
					return
				}

				expectCall := jestFnCall.Head.Local.Node.Parent
				if expectCall == nil || expectCall.Kind != ast.KindCallExpression {
					return
				}

				args := expectCall.Arguments()
				if len(args) == 0 || !isAsyncFunction(args[0]) {
					return
				}

				awaited := getUnwrappedAwaitedExpression(args[0])
				if awaited == nil {
					return
				}

				sourceFile := ctx.SourceFile
				replacement := rslintUtils.TrimmedNodeText(sourceFile, awaited)
				ctx.ReportNodeWithFixes(
					args[0],
					buildNoAsyncWrapperForExpectedPromiseMessage(),
					rule.RuleFixReplace(sourceFile, args[0], replacement),
				)
			},
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL