feat: Add inline suppression comments for complexity thresholds#35
Merged
Conversation
Add // swift-complexity:disable so a reviewed function can be exempted from threshold checks without raising the threshold globally or giving up on enforcement, closing the gap left by the earlier per-type threshold work: a single legitimately complex function otherwise forces either fixing it or weakening the check for the whole type. Design: - The comment must be the closest leading comment directly above the suppressed declaration (function, initializer, deinitializer, or computed property/accessor). There is deliberately no "next line" form and no "enable" counterpart, since suppression always scopes to exactly the one declaration whose leading trivia holds the comment - unlike range-based disable/enable, this can't be left un-re-enabled by mistake. - A bare disable suppresses every metric; naming specific metrics (cyclomatic/cognitive) suppresses only those, leaving the rest checked as usual. - Parsing fails closed: an unrecognized metric name suppresses nothing, rather than falling back to "suppress everything". A typo should not silently widen what gets hidden from a tool whose entire purpose is to not let violations slip through. - Suppressed values are still computed and shown in every output format; only the threshold judgment is skipped. This required updating all three places that independently decide "does this function violate its threshold" - ThresholdConfiguration.isExceeded, the Xcode diagnostic (which reports both metrics in one combined message and keeps doing so), and SARIF's per-metric result generation - so a metric suppression can't be bypassed through one of the three. - LCOM4 class cohesion has no suppression yet: it's a type-level metric, not a per-function one, so it needs its own design and is left for a follow-up. Also add --report-suppressions, which prints every suppressed function and its current metric values to stderr, so suppression comments stay visible instead of silently accumulating. Claude-Session: https://claude.ai/code/session_01GaTHVDhSAx76RbLmVziLQu
📊 PR Analysis
📝 Large PR: Consider breaking this into smaller, focused PRs. Automated analysis by swift-complexity CI |
🔍 Complexity Analysis Results✅ All functions are below the complexity threshold of 15. This analysis was performed by swift-complexity itself. |
1 task
Empty commit only, to re-trigger the WIP marketplace app's webhook, which did not report a status for this PR's prior commits. Claude-Session: https://claude.ai/code/session_01GaTHVDhSAx76RbLmVziLQu
📊 PR Analysis
📝 Large PR: Consider breaking this into smaller, focused PRs. Automated analysis by swift-complexity CI |
🔍 Complexity Analysis Results✅ All functions are below the complexity threshold of 15. This analysis was performed by swift-complexity itself. |
fummicc1
added a commit
that referenced
this pull request
Jul 18, 2026
Release includes SARIF output format (#33) and inline suppression comments (#35). Claude-Session: https://claude.ai/code/session_01GaTHVDhSAx76RbLmVziLQu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
// swift-complexity:disableso a single, reviewed function can be exempted from threshold checks without raising the threshold globally or abandoning enforcement. This closes a real gap left by the per-type threshold work (#32): today, one legitimately complex function forces a choice between fixing it or weakening the check for the whole type.Second step of the "Now" roadmap, after SARIF output (#33).
Syntax
cyclomatic/cognitive, space- or comma-separated) suppresses only those.///doc comments are never mistaken for a directive.Design notes
ThresholdConfiguration.isExceeded(feeds the exit code and the upstream filter shared by text/json/xml/xcode/sarif), the Xcode diagnostic (which reports both metrics in one combined message and keeps doing so — only the gating changes), and SARIF's per-metric result generation (which computes its own>=check independent ofisExceeded).--report-suppressionsflag prints every suppressed function and its current metric values to stderr, so suppressions stay visible instead of silently accumulating.Verification
swift test: 102 tests pass, including new coverage forSuppressionParser(bare disable, specific metrics, comma-separated, typo'd metric, unrelated comment, doc comment, false-prefix match likedisableFoo),ThresholdConfiguration.isExceededwith suppression, Xcode diagnostics with partial/full suppression, and SARIF with partial suppressionTests/SwiftComplexityCoreTests/Fixtures/suppressed_functions.swift) confirmed with the built CLI acrosstext,xcode, andsarifformats at multiple thresholds, and--report-suppressionsoutputswift-formatclean via lefthook pre-commit; no new markdownlint errors introduced (verified by diffing lint output againstmain)https://claude.ai/code/session_01GaTHVDhSAx76RbLmVziLQu