Can unused_control_flow_label be configurable on which statement to check
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
We can prefix a loop statement, an if statement, a switch statement, or a do statement with a statement label. It would be nice that unused_control_flow_label can be configurable on which statement to check. The default configuration may be all the statements that can be labeled.
The reason for this is that there is a scenario that a label is not used for control flow:
class People {
let livingExpenses: Int
let salary: Int
init() {
livingExpensesInitialization:
do {
let foodExpenses = 1
let rent = 5
livingExpenses = foodExpenses + rent
}
salary = 3 // foodExpenses can not be accessed here
}
}
In the above snippet, the do block is used to create a scope and the label is used to describe what it does rather for a control flow. One reason that a label is better than simple comment is that other code which can not be labeled can not be accidentally placed between the label and do block while modifying code.
This is an unpopular usage of do block, but we can make the default configuration to check all statements that can be labeled and keep the flexibility to configure which statement to check.
Hopefully that makes sense!
-Thanks!
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
The issue names the unused_control_flow_label rule but no files or tests; start by locating that rule and its current configuration handling. Check how statement labels are classified, then verify that configuration can select statements while the default still checks all labelable statements, with tests covering both behaviors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100