no_useless_concat

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoUselessConcatRule = rule.Rule{
	Name: "no-useless-concat",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		sourceFile := ctx.SourceFile
		lineMap := sourceFile.ECMALineMap()

		return rule.RuleListeners{
			ast.KindBinaryExpression: func(node *ast.Node) {
				if !utils.IsPlusBinaryExpression(node) {
					return
				}
				bin := node.AsBinaryExpression()

				left := getRightmostLeaf(bin.Left)
				right := getLeftmostLeaf(bin.Right)

				if !utils.IsStringLiteralOrTemplate(left) || !utils.IsStringLiteralOrTemplate(right) {
					return
				}

				leftEndLine := scanner.ComputeLineOfPosition(lineMap, left.End())
				rightStartLine := scanner.ComputeLineOfPosition(lineMap, utils.TrimNodeTextRange(sourceFile, right).Pos())
				if leftEndLine != rightStartLine {
					return
				}

				ctx.ReportRange(
					utils.TrimNodeTextRange(sourceFile, bin.OperatorToken),
					rule.RuleMessage{
						Id:          "unexpectedConcat",
						Description: "Unexpected string concatenation of literals.",
					},
				)
			},
		}
	},
}

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

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