Skip to content

force_unwrapping: provide opt-out for default ignored_literal_argument_functions exemptions #6675

Closed

Description

@ablaszczynska

New Issue Checklist

Bug Description

Not strictly a bug, closer to a missing capability for teams with strict force-unwrap policies.

The ignored_literal_argument_functions option on force_unwrapping (added in #6490, 0.63.3) is intentionally additive: the postprocessor on the config element unions five built-in defaults (URL(string:), NSURL(string:), UIImage(named:), NSImage(named:), Data(hexString:)) into the user-supplied set after parsing.

The limitation is that there's no way for a user to opt out of those five defaults. Some codebases treat any force-unwrap as a code smell, even of compile-time literals, because the literal might still be invalid:

let url = URL(string: "")!        // crashes
let img = UIImage(named: "renamedAsset")! // crashes when asset is moved/renamed

For those teams, the new exemption silently loosens force_unwrapping with no config path to restore strict policing. Pinning to 0.63.2 is currently the only workaround, which leaves users stuck on an older release.

Reproducer

// test.swift
import Foundation
import UIKit
let aaa = URL(string: "https://example.com")!
let bbb = UIImage(named: "icon")!
$ swiftlint lint --no-cache test.swift
Done linting! Found 0 violations, 0 serious in 1 file.

Expected: both lines trigger force_unwrapping. Actual: zero violations regardless of what the user puts in ignored_literal_argument_functions ([], ["DummyOnly"], etc.), the defaults are always merged in.

Environment

  • SwiftLint version: 0.63.3
  • Xcode version: 26.3
  • Installation method: Homebrew
  • Configuration file:
opt_in_rules:
  - force_unwrapping
force_unwrapping:
  ignored_literal_argument_functions: []   # has no effect; defaults still apply

Not using nested configurations.

Activity

  1. changed the title [-]force_unwrapping: `ignored_literal_argument_functions` cannot remove default exemptions[/-] [+]force_unwrapping: provide opt-out for default `ignored_literal_argument_functions` default exemptions[/+] on May 28, 2026
  2. changed the title [-]force_unwrapping: provide opt-out for default `ignored_literal_argument_functions` default exemptions[/-] [+]force_unwrapping: provide opt-out for default `ignored_literal_argument_functions` exemptions[/+] on May 28, 2026
  3. added
    bug
    on May 28, 2026
  4. self-assigned this
    on May 28, 2026
  5. SimplyDanny commented on May 28, 2026

    @SimplyDanny
    Collaborator

    You are right. That's problematic. I've prepared #6677 to make the defaults replaceable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions