Skip to content

Make force_unwrapping more nuanced #6487

Closed

Description

@mlaster

New Issue Checklist

New Rule Request

Modification to an existing rule.

Please describe the rule idea, format this issue's title as Rule Request: [Rule Name] and describe:

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.
    force_unwrapping flags in cases where it is probably legitimate.

  2. Provide several examples of what would and wouldn't trigger violations.

Should not trigger:
let a = Data(hexString: "AABBCCDD")! // argument is a static String
let a = URL(string: "https://www.example.com")! // argument is static String

Should trigger:
let a = Data(hexString: someVar)! // argument is a variable
let a = URL(string: someVar)! // argument is variable

  1. Should the rule be configurable, if so what parameters should be configurable?
    Probably not outside of basing enable/disable.

  2. 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.
    Whatever current force_unwrapping is.

Activity

  1. added
    enhancement
    good first issue
    on Feb 10, 2026
  2. added a commit that references this issue on Feb 11, 2026
    f219ad5
  3. claudeaceae commented on Feb 12, 2026

    @claudeaceae
    Contributor

    This is addressed by #6490, which adds a static_string_argument_functions configuration option to force_unwrapping. It ships with defaults covering exactly these cases (URL(string:), Data(hexString:), etc.) and allows users to add their own.

    The approach was guided by the maintainer to be explicit about which function calls to ignore rather than doing broad static-string detection. Happy to hear your thoughts on the PR if you have additional functions you'd want in the defaults.

  4. mlaster commented on Feb 13, 2026

    @mlaster
    Author
  5. claudeaceae commented on Feb 13, 2026

    @claudeaceae
    Contributor

    Glad it lines up with what you were looking for! Yeah, once the maintainer suggested the explicit allowlist approach, it made sense to cover the broader set of static-string initializers rather than just Data/URL. If you think of any other functions that should be in the defaults, feel free to drop them on the PR.

  6. claudeaceae commented on Feb 13, 2026

    @claudeaceae
    Contributor

    This is addressed by #6490 — it adds an allowlist for force-unwrapping when all arguments are static string literals, which covers the exact patterns you describe (URL(string:), Data(hexString:), etc.).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions