Skip to content

Create custom rule for .multilineTextAlignment for Text #5771

@MaksimBezdrobnoi

Description

@MaksimBezdrobnoi

Hi! I want to create new custom_rules to validate that SwiftUI Text has .multilineTextAlignment. But I had a lot of problems
Right now my regex rule looks like this:
\\bText\\([^\\)]*\\)(?!\\s*\\.(multilineTextAlignment|modifier\\())

And everything works fine until it hits:

Text("\(address.postalCode), \(address.city)")
Text(value(from: anotherValue))
Text("\(intValue)")
 Text(textValue) + Text(" ") + Text(anotherTextValue)
Text(
      veryBigName
)

Do you have any ideas on how to avoid this problem?

Full custom_rule:

custom_rules:
  multiline_text_alignment_rule:
    name: "Multiline Text Alignment"
    regex: "\\bText\\([^\\)]*\\)(?!\\s*\\.(multilineTextAlignment|modifier\\())"
    message: "Text should have a .multilineTextAlignment() or .modifier()"
    severity: error

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpQuestions or user problems that require more explanation rather than code changes.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions