Rule request: computed_property_cyclomatic_complexity
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
Please describe the rule idea, format this issue's title as Rule Request: [Rule Name] and describe:
computed_property_cyclomatic_complexity
Complexity of computed properties' bodies should be limited.
Why should this rule be added? Share links to existing discussion about what the community thinks about this.
Since there is a similar rule concerning function bodies, it is appropriate that the same rule should be valid for computed properties.
Provide several examples of what would and wouldn't trigger violations.
NO:
var code: Int { switch self { case .initSDK, .startInitSDK: return 1300 case .mutualAuth, .startMutualAuth: return 1302 case .consumer, .startConsumer: return 1303 case .visits, .startVisits: return 1304 case .fetchAppointment, .startFetchAppointment: return 1305 case .reconnect, .startReconnect: return 1306 } }
YES:
var code: Int { switch self { case .initSDK, .startInitSDK: return 1300 case .mutualAuth, .startMutualAuth: return 1302 case .consumer, .startConsumer: return 1303 case .visits, .startVisits: return 1304 case .fetchAppointment, .startFetchAppointment: return 1305 case .reconnect, .startReconnect: return 1306
case .rejoin, .startRejoin:
return 1307
case .inboxMessages, .startInboxMessages:
return 1308
case .addHealthDoc, .startAddHealthDoc:
return 1309
case .visitContext, .startVisitContext:
return 1311
case .createVisit, .startCreateVisit:
return 1312
case .cancelVisit, .startCancelVisit:
return 1313
} }
Should the rule be configurable, if so what parameters should be configurable?
The rule should be configurable in a similar manner to cyclomatic_complexity
Should the rule be opt-in or enabled by default? Why? See README.md for guidelines on when to mark a rule as opt-in.
The rule should e enabled by default
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 comparing SwiftLint's existing cyclomatic_complexity rule and the README.md guidance for default versus opt-in rules. Define how the requested rule applies to computed-property bodies and which configuration parameters it shares with cyclomatic_complexity. Done means the rule detects over-complex computed properties and has documented configuration and default behavior.
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
- Mostly clear
- Newbie friendliness
- 35/100