Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var PreferTemplateRule = rule.Rule{ Name: "prefer-template", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { reported := map[int]bool{} checkForStringConcat := func(node *ast.Node) { if !utils.IsStringLiteralOrTemplate(node) { return } parent := ast.WalkUpParenthesizedExpressions(node.Parent) if !utils.IsPlusBinaryExpression(parent) { return } top := getTopConcatBinaryExpression(parent) if reported[top.Pos()] { return } reported[top.Pos()] = true if !hasNonStringLiteral(top) { return } msg := rule.RuleMessage{ Id: "unexpectedStringConcatenation", Description: "Unexpected string concatenation.", } if hasOctalOrNonOctalDecimalEscape(ctx.SourceFile, top) { ctx.ReportNode(top, msg) return } fixed := toTemplateLiteral(ctx.SourceFile, top, "", "") ctx.ReportNodeWithFixes(top, msg, rule.RuleFixReplace(ctx.SourceFile, top, fixed)) } return rule.RuleListeners{ ast.KindStringLiteral: checkForStringConcat, ast.KindNoSubstitutionTemplateLiteral: checkForStringConcat, ast.KindTemplateExpression: checkForStringConcat, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.