Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer_key_path in 0.58.0 warns if {$0} instead of (\.self) for SwiftPM using Swift 5 #5965

Open
2 tasks done
rgoldberg opened this issue Jan 15, 2025 · 1 comment
Open
2 tasks done
Labels
help Questions or user problems that require more explanation rather than code changes. integration Issues related to integration of SwiftLint into toolchains.

Comments

@rgoldberg
Copy link

New Issue Checklist

Bug Description

prefer_key_path in 0.58.0 warns if {$0} is used instead of ()\.self for a Swift file in a SwiftPM project whose Package.swift contains // swift-tools-version:5.7.1 & swiftLanguageVersions: [.v5].

I assume that SwiftVersion.current used in SwiftVersion.current >= .six doesn't properly determine the correct version of Swift that is being used.

Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.

$ swiftlint --strict --quiet Sources

Environment

  • SwiftLint version (run swiftlint version to be sure) 0.58.0
  • Xcode version (run xcodebuild -version to be sure) 16.0 (16A242d)
  • Installation method used (Homebrew, CocoaPods, building from source, etc) Homebrew
  • Configuration file:
---
opt_in_rules:
  - all
disabled_rules:
  # eventually enable
  - file_header
  - one_declaration_per_file
  - trailing_comma
  # never enable
  - contrasted_opening_brace
  - explicit_acl
  - explicit_enum_raw_value
  - explicit_top_level_acl
  - explicit_type_interface
  - no_extension_access_modifier
  - no_grouping_extension
  - no_magic_numbers
  - prefixed_toplevel_constant
  - sorted_enum_cases
  - vertical_whitespace_between_cases
file_name:
  excluded: [Finder.swift, Utilities.swift]
file_types_order:
  order:
    [
      [main_type],
      [supporting_type],
      [extension],
      [preview_provider],
      [library_content_provider],
    ]
number_separator:
  minimum_length: 6
type_contents_order:
  order:
    [
      [case],
      [type_alias, associated_type],
      [subtype],
      [type_property],
      [instance_property],
      [ib_inspectable],
      [ib_outlet],
      [initializer],
      [deinitializer],
      [type_method],
      [view_life_cycle_method],
      [ib_action],
      [other_method],
      [subscript],
    ]
@rgoldberg rgoldberg changed the title prefer_key_path in 0.58.0 warns if {$0} instead of ()\.self for SwiftPM swiftLanguageVersions: [.v5] prefer_key_path in 0.58.0 warns if {$0} instead of ()\.self for SwiftPM using Swift 5 Jan 15, 2025
@rgoldberg rgoldberg changed the title prefer_key_path in 0.58.0 warns if {$0} instead of ()\.self for SwiftPM using Swift 5 prefer_key_path in 0.58.0 warns if {$0} instead of (\.self) for SwiftPM using Swift 5 Jan 15, 2025
@SimplyDanny
Copy link
Collaborator

This is a valid report and something people need to be aware of.

SwiftLint doesn't care for any versions specified in the Package.swift at all - neither the tools version nor specific language versions for certain modules.

What it does is to ask SourceKit for the version which depends on the Xcode version being selected or first SourceKit binary in the PATH. If everything is configured well, this would also be what swift --version reports. So if you set a different version for some modules, this can cause problems, like in your case.

That said, you have the option to set SWIFTLINT_SWIFT_VERSION as an environment variable to overwrite whatever SourceKit reports. This is again a global version and thus applies to all modules.

@SimplyDanny SimplyDanny added help Questions or user problems that require more explanation rather than code changes. integration Issues related to integration of SwiftLint into toolchains. labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions or user problems that require more explanation rather than code changes. integration Issues related to integration of SwiftLint into toolchains.
Projects
None yet
Development

No branches or pull requests

2 participants