Skip to content

Skip force_unwrapping for calls with static string literal args - #6490

Merged
SimplyDanny merged 7 commits into
realm:mainfrom
claudeaceae:fix/force-unwrapping-static-literals
Feb 19, 2026
Merged

SimplyDanny merged 7 commits into
realm:mainfrom
claudeaceae:fix/force-unwrapping-static-literals

Conversation

@claudeaceae

Copy link
Copy Markdown
Contributor

Summary

Suppresses force_unwrapping violations when the force-unwrapped expression is a function call where all arguments are static string literals (no interpolation).

Common patterns like these are now allowed:

let url = URL(string: "https://example.com")!
let data = Data(hexString: "AABBCCDD")!
let image = UIImage(named: "icon")!

While these still trigger violations:

let url = URL(string: variable)!           // variable argument
let url = URL(string: "\(dynamicValue)")!  // string interpolation

Rationale

When a developer writes a function call with a hardcoded string literal, they know the input is valid at compile time. Force unwrapping in this case is a deliberate, informed choice rather than a potential crash risk. This is one of the most common patterns flagged as a false positive by the current rule.

Changes

  • Added isCallWithOnlyStaticStringArguments check to the ForceUnwrapExprSyntax visitor
  • Added isStaticStringLiteral helper that verifies a string has no interpolation segments
  • Updated nonTriggeringExamples and triggeringExamples to cover the new behavior
  • Moved NSURL(string: "http://www.google.com")! from triggering to non-triggering

Closes #6487

… arguments

When force-unwrapping the result of a function call where all arguments
are static string literals (no interpolation), the violation is now
suppressed. This covers common safe patterns like:

  URL(string: "https://example.com")!
  Data(hexString: "AABBCCDD")!

Force unwraps with variable arguments or string interpolation still
trigger as before.

Closes realm#6487
@SwiftLintBot

SwiftLintBot commented Feb 11, 2026 •

Copy link
Copy Markdown
3 Warnings
⚠️ This PR introduced a violation in Firefox: /focus-ios/BlockzillaPackage/Sources/DesignSystem/UIImage+AppImages.swift:15:38: Warning: SwiftLint rule 'force_unwrapping' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Moya: /Examples/_shared/GiphyAPI.swift:11:: Warning: SwiftLint rule 'force_unwrapping' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Moya: /Examples/_shared/GitHubUserContentAPI.swift:11:: Warning: SwiftLint rule 'force_unwrapping' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
3313 Messages
📖 Building this branch resulted in a binary size of 27274.46 KiB vs 27252.48 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.82 s vs 0.79 s on main (3% slower).
📖 Linting Alamofire with this PR took 1.06 s vs 1.04 s on main (1% slower).
📖 Linting Brave with this PR took 7.2 s vs 7.19 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 25.48 s vs 25.5 s on main (0% faster).
📖 Linting Firefox with this PR took 11.72 s vs 11.74 s on main (0% faster).
📖 Linting Kickstarter with this PR took 8.01 s vs 8.01 s on main (0% slower).
📖 Linting Moya with this PR took 0.46 s vs 0.44 s on main (4% slower).
📖 Linting NetNewsWire with this PR took 2.41 s vs 2.44 s on main (1% faster).
📖 Linting Nimble with this PR took 0.69 s vs 0.68 s on main (1% slower).
📖 Linting PocketCasts with this PR took 7.56 s vs 7.59 s on main (0% faster).
📖 Linting Quick with this PR took 0.44 s vs 0.42 s on main (4% slower).
📖 Linting Realm with this PR took 3.3 s vs 3.29 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.88 s vs 1.85 s on main (1% slower).
📖 Linting Swift with this PR took 4.62 s vs 4.59 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.34 s vs 0.33 s on main (3% slower).
📖 Linting VLC with this PR took 1.19 s vs 1.15 s on main (3% slower).
📖 Linting Wire with this PR took 18.42 s vs 18.46 s on main (0% faster).
📖 Linting WordPress with this PR took 12.46 s vs 12.49 s on main (0% faster).
📖 This PR fixed a violation in Aerial: /Resources/MainUI/First time setup/RecapViewController.swift:26:78: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/First time setup/RecapViewController.swift:32:71: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/First time setup/TimeSetupViewController.swift:107:148: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/First time setup/VideoFormatViewController.swift:61:116: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/HelpViewController.swift:20:78: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/HelpViewController.swift:26:90: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/HelpViewController.swift:32:77: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/HelpViewController.swift:38:60: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/InfoViewController.swift:23:61: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/InfoViewController.swift:29:59: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/CreditsViewController.swift:23:81: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/CreditsViewController.swift:29:69: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/CreditsViewController.swift:35:70: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Infos panels/CreditsViewController.swift:41:60: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Settings panels/SourcesViewController.swift:68:85: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Settings panels/SourcesViewController.swift:118:85: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Settings panels/AdvancedViewController.swift:304:99: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Resources/MainUI/Settings panels/AdvancedViewController.swift:310:116: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/ManifestLoader.swift:381:89: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/ManifestLoader.swift:385:86: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/ManifestLoader.swift:389:88: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/ManifestLoader.swift:393:128: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:124:103: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/InfoWeatherView.swift:189:75: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/ParameterEncodingTests.swift:439:67: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/ParameterEncodingTests.swift:451:66: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/ParameterEncodingTests.swift:464:60: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/MultipartFormDataTests.swift:803:40: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/MultipartFormDataTests.swift:825:67: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/MultipartFormDataTests.swift:921:62: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Alamofire: /Tests/AuthenticationInterceptorTests.swift:305:70: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/BraveWidgets/TopNewsWidget.swift:271:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/BraveWidgets/TopNewsWidget.swift:275:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/BraveWidgets/LockScreenFavoriteWidget.swift:147:50: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/BraveWidgets/LockScreenFavoriteWidget.swift:162:54: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/l10n/tools/download-translations-from-transifex.swift:103:93: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/WebShell/ContentView.swift:183:83: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:18:69: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:19:64: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:20:69: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:21:83: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:22:68: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:125:65: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:126:63: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsSettingsMigrationTests.swift:127:65: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsTabHelperTests.swift:18:45: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsTabHelperTests.swift:138:67: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveShieldsTests/BraveShieldsTabHelperTests.swift:221:67: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DataSavedTests.swift:15:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DataSavedTests.swift:26:62: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DataSavedTests.swift:27:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DataSavedTests.swift:38:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:15:48: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:24:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:38:48: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:49:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:70:62: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:71:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:81:47: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:96:48: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:101:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:114:48: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:119:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:124:55: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:137:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:148:65: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/RecentlyClosedTests.swift:159:82: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:18:46: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:19:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:21:45: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:22:51: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:24:57: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:25:65: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:29:54: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:30:50: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:56:48: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:57:47: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:364:53: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:371:61: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/DataTests/DomainTests.swift:373:60: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:27:75: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:28:54: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:36:58: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:37:54: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:45:79: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/AdblockRustTests.swift:46:54: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/BraveNewsTests/CardGeneratorTests.swift:84:41: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:204:51: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:209:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:215:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:222:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:224:75: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:226:85: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:229:75: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:232:84: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:239:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:241:73: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:246:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:252:8: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:267:62: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:273:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:282:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:291:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:296:95: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:300:94: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:308:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:313:70: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:321:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/URLFormatTests.swift:329:10: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:24:68: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:25:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:33:68: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:34:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:42:74: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:43:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:51:74: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:52:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:124:66: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/WebFilters/GroupedAdBlockEngineTests.swift:139:58: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/NetworkManagerTests.swift:16:46: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/PageDataTests.swift:23:57: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/PageDataTests.swift:24:68: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/PageDataTests.swift:25:66: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/PageDataTests.swift:133:57: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/NavigationRouterTests.swift:91:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/NavigationRouterTests.swift:104:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/NavigationRouterTests.swift:118:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/NavigationRouterTests.swift:132:52: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/DownloadQueueTests.swift:135:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/DownloadQueueTests.swift:147:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/DownloadQueueTests.swift:159:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/DownloadQueueTests.swift:170:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/TestFavicons.swift:24:47: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/TestFavicons.swift:28:57: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/TestFavicons.swift:37:47: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/TabManagerTests.swift:167:56: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/UserScripts/ScriptFactoryTests.swift:16:50: Warning: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Tests/ClientTests/UserScripts/ScriptFactoryTests.swift:17:49: Warning: Force unwrapping should be avoided (force_unwrapping)
⚠️ Danger found 3313 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 157.

Generated by 🚫 Danger

@claudeaceae

Copy link
Copy Markdown
Contributor Author

Added a CHANGELOG entry under Enhancements. Thanks for the CI run — glad to see 0 errors and the real-world violation fixes across projects like Aerial.

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The approach is reasonable, but we should be explicit about the function calls to ignore.

- Use key path syntax instead of closure to fix prefer_key_path violation
- Use onlyElement?.is() per reviewer suggestion for cleaner check

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace the general heuristic (any function with static string args) with
an explicit, configurable set of function names. Defaults include
URL(string:), NSURL(string:), UIImage(named:), NSImage(named:), and
Data(hexString:). Users can extend the list via the
static_string_argument_functions configuration option.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@claudeaceae

Copy link
Copy Markdown
Contributor Author

Updated to use an explicit, configurable allowlist per your feedback. The new static_string_argument_functions option defaults to:

  • URL(string:)
  • NSURL(string:)
  • UIImage(named:)
  • NSImage(named:)
  • Data(hexString:)

Users can extend the set in their .swiftlint.yml:

force_unwrapping:
  static_string_argument_functions:
    - MyType(identifier:)

The postprocessor pattern (from NoMagicNumbersConfiguration) ensures defaults are always included — user entries are merged in rather than replacing them.

Also normalizes Type.init(label:) to Type(label:) so both call forms are matched against the same allowlist entry.

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! You need to run swift run swiftlint-dev rules register to make sure the test validating configurations passes.

Rename the configuration key and Swift property from
static_string_argument_functions to ignored_literal_argument_functions
per reviewer feedback. The more generic name leaves room for future
extension to other literal types (integer, boolean, etc.).

Also updates default_rule_configurations.yml to reflect the new option
name and its default values.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add a non-triggering example that proves an arbitrary function
configured in ignored_literal_argument_functions is correctly
excluded from violations.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@claudeaceae

Copy link
Copy Markdown
Contributor Author

Added — the new non-triggering example uses someFunction("constant")\! with ["ignored_literal_argument_functions": ["someFunction(_:)"]] in the configuration. This mirrors the existing triggering example (let result = someFunction("constant")↓\! under default config), so together they prove the configurability end-to-end.

@SimplyDanny
SimplyDanny enabled auto-merge (squash) February 19, 2026 19:25
@SimplyDanny
SimplyDanny merged commit 09f2fca into realm:main Feb 19, 2026
18 checks passed
nadeemnali pushed a commit to nadeemnali/SwiftLint that referenced this pull request Feb 26, 2026
nadeemnali pushed a commit to nadeemnali/SwiftLint that referenced this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make force_unwrapping more nuanced

3 participants