opening_braces allows some multiline if statements, others get flagged
Open
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
- I've Updated SwiftLint to the latest version.
- I've searched for existing GitHub issues.
Bug Description
Related issues: #5521, #5602
Some multiline if statements with a starting brace don't trigger an error, but more complicated lines do. For instance no warning:
// Instance variables
var foo = 5
var goo = 7
if
self.foo == 9,
self.goo == 10
{
print("SUCCESS")
} else {
fatalError()
}
More usual code triggers an opening_brace error:
if
let rootVC = AppDelegate.myDelegate.window?.rootViewController as? XYZ,
let abcVC = rootVC.myArray.first as? ABC
{
...
} else {
fatalError()
}
Environment
- SwiftLint version 0.57.1
- Xcode version 16.2
- Installation method used Swift Package
- Configuration file:
# Case-sensitive paths to include during linting. Directory paths supplied on the
# command line will be ignored.
included:
- abc
- def
excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included`
- 1111
# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
- trailing_whitespace
- line_length
- force_cast
- cyclomatic_complexity
- function_body_length
- identifier_name
- file_length
- function_parameter_count
- large_tuple
- type_name
- type_body_length
- todo
- no_fallthrough_only
- static_over_final_class
- inclusive_language
- legacy_random
- nesting
- nsobject_prefer_isequal
- force_try
- closure_parameter_position
opt_in_rules: # some rules are turned off by default, so you need to opt-in
- empty_count # find all the available rules by running: `swiftlint rules`
analyzer_rules: # rules run by `swiftlint analyze`
- explicit_self
# If true, SwiftLint will not fail if no lintable files are found.
allow_zero_lintable_files: false
# If true, SwiftLint will treat all warnings as errors.
strict: false
# If true, SwiftLint will treat all errors as warnings.
lenient: false
# If true, SwiftLint will check for updates after linting or analyzing.
check_for_updates: true
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging, summary)
colon:
severity: error
comma:
severity: error
control_statement:
severity: error
trailing_comma:
severity: error
mandatory_comma: true
Are you using nested configurations? If so, paste their
relative paths and respective contents. N/A
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 reproducing the two multiline if examples with SwiftLint 0.57.1 and compare how the opening_braces rule handles them. The issue names no source files or tests, so locate the rule's implementation and existing tests before defining the expected consistent diagnostic behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100