realm / realm/SwiftLint

Create custom rule for .multilineTextAlignment for Text

Open
#5,771 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SwiftLint's custom_rules configuration and the supplied multiline_text_alignment_rule regex, then compare it with each SwiftUI Text example in the issue. Done means establishing whether the requested validation can be expressed reliably as a custom rule and documenting or implementing a defined approach for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.