no_focused_tests

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoFocusedTestsRule = rule.Rule{
	Name: "jest/no-focused-tests",
	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.JestFnTypeDescribe &&
						jestFnCall.Kind != jestUtils.JestFnTypeTest) {
					return
				}

				if strings.HasPrefix(jestFnCall.Name, "f") {
					callExpr := node.AsCallExpression()
					if callExpr == nil {
						return
					}

					callee := ast.SkipParentheses(callExpr.Expression)
					if callee == nil {
						return
					}

					calleeRange := rslintUtils.TrimNodeTextRange(ctx.SourceFile, callee)
					if jestFnCall.Head.Type == jestUtils.JEST_IMPORT_MODE && jestFnCall.Name != jestFnCall.Head.Local.Value {
						reportNode := jestFnCall.Head.Local.Node
						if reportNode == nil {
							reportNode = callee
						}

						ctx.ReportNode(reportNode, buildErrorFocusedTestMessage())
					} else {
						reportNode := jestFnCall.Head.Local.Node
						if reportNode == nil {
							reportNode = callee
						}

						ctx.ReportNodeWithSuggestions(
							reportNode,
							buildErrorFocusedTestMessage(),
							rule.RuleSuggestion{
								Message: buildErrorSuggestRemoveFocusMessage(),
								FixesArr: []rule.RuleFix{
									rule.RuleFixRemoveRange(core.NewTextRange(calleeRange.Pos(), calleeRange.Pos()+1)),
								},
							},
						)
					}
				} else {
					idx := slices.IndexFunc(jestFnCall.MemberEntries, func(entry jestUtils.ParsedJestFnMemberEntry) bool {
						return entry.Name == "only"
					})
					if idx >= 0 {
						entry := jestFnCall.MemberEntries[idx]
						startRange := entry.Node.Loc.Pos() - 1
						endRange := entry.Node.Loc.End()
						if entry.Node.Kind != ast.KindIdentifier {
							endRange = entry.Node.End() + 1
						}

						ctx.ReportNodeWithSuggestions(
							entry.Node,
							buildErrorFocusedTestMessage(),
							rule.RuleSuggestion{
								Message: buildErrorSuggestRemoveFocusMessage(),
								FixesArr: []rule.RuleFix{
									rule.RuleFixRemoveRange(core.NewTextRange(startRange, endRange)),
								},
							},
						)
					}
				}
			},
		}
	},
}

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