Rule Request: Xcode templates
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
1. Why should this rule be added? Share links to existing discussion about what the community thinks about this.
It's very common in SwiftUI that XCode will create code templates. E.g. when you add the .font() view modifier to a view, XCode will automatically add the default font .title between the brackets and highlight it.
In the actual file, this code template is saved like so: .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/).
2. Provide several examples of what would and wouldn't trigger violations.
This would trigger the rule:
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
.font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
This would not:
.fontWeight(.bold)
.font(.title)
3. Should the rule be configurable, if so what parameters should be configurable?
No.
4. Should the rule be opt-in or enabled by default? Why?
It should be opt-in. Not everyone may consider it as bad style to have the XCode generated templates in their source files.
Custom Rule Implementation
xcode_template:
name: "XCode Template"
regex: "(\/\\*@START_MENU_TOKEN@\\*\/.*?\/\\*@END_MENU_TOKEN@\\*\/)"
message: "XCode generated code templates should be applied or removed."
severity: warning
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing SwiftLint's rule implementation conventions against the proposed xcode_template regex, examples, warning message, and opt-in requirement. Add coverage for the provided triggering and non-triggering snippets, and consider the rule complete when it detects the specified Xcode markers without flagging ordinary modifiers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100