no_useless_call

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoUselessCallRule = rule.Rule{
	Name: "no-useless-call",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindCallExpression: func(node *ast.Node) {
				callee, methodName := isCallOrNonVariadicApply(node)
				if callee == nil {
					return
				}

				applied := ast.SkipParentheses(callee.AsPropertyAccessExpression().Expression)

				// expectedThis is the receiver implied by `applied`. ESLint
				// treats only MemberExpression receivers as having an
				// implied `this`; tsgo splits that into PropertyAccessExpression
				// and ElementAccessExpression.
				var expectedThis *ast.Node
				switch applied.Kind {
				case ast.KindPropertyAccessExpression:
					expectedThis = applied.AsPropertyAccessExpression().Expression
				case ast.KindElementAccessExpression:
					expectedThis = applied.AsElementAccessExpression().Expression
				}

				thisArg := node.AsCallExpression().Arguments.Nodes[0]

				var matches bool
				if expectedThis == nil {
					matches = utils.IsNullOrUndefined(thisArg)
				} else {
					matches = utils.HasSameTokens(ctx.SourceFile, expectedThis, thisArg)
				}
				if !matches {
					return
				}

				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "unnecessaryCall",
					Description: "Unnecessary '." + methodName + "()'.",
				})
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-useless-call

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