realm / realm/SwiftLint

Can unused_control_flow_label be configurable on which statement to check

Open
#5,349 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

New Issue Checklist

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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.