SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Unable to use SwiftLint with Swift Package Manager

Open aBhanuTeja opened this issue 3 years ago • 6 comments

Environment

  • SwiftLint version: 0.47.0
  • Installation method: Swift Package
  • Xcode version: 13.2.1
  • Deployment Target: iOS 14.1

Bug description

I am trying to Migrate my existing project to "Swift Package Manager" from "Cocoapods"

The project with Cocoapods is working fine. But, When I try to build my current project with "Swift Package Manager", I am getting following error for SwiftLint. I don't have any issues with other swift packages.

Screen Shot 2022-04-12 at 11 06 54 PM

I tried by deleting Derived data. Then I am getting this issue Then, I quit and launch the Xcode, I am getting the above error(as shown in the image)

Before(While using Cocoapods), I am using following as Run Script in Build Phases

if which ${PODS_ROOT}/SwiftLint/swiftlint >/dev/null; then
  ${PODS_ROOT}/SwiftLint/swiftlint --strict
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

Now(While using Swift Package), I am using following as Run Script in Build Phases

if swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

aBhanuTeja avatar Apr 12 '22 18:04 aBhanuTeja

What's your Package.swift? Based on the Xcode error messages, it's telling you Xcode is trying to build SwiftLint to run on an iOS target, which it of course won't work, considering SourceKit is only available on macOS and Linux.

jpsim avatar Apr 12 '22 18:04 jpsim

I don't have any Package.swift file. Will it create automatically? How can we get it? I added Packages under "Package Dependencies" tab.

aBhanuTeja avatar Apr 12 '22 19:04 aBhanuTeja

That won't work, that'll try to build a target with the SwiftLint macOS binary for an iOS target, which won't work for the reasons I explained above.

jpsim avatar Apr 12 '22 19:04 jpsim

I'm also getting errors:

image

afern247 avatar May 12 '22 22:05 afern247

You're using SwiftLint as a build dependency but I believe you're only looking to lint the code. In that case, you shouldn't add SwiftLint as a pod or SPM dependency. Instead, install SwiftLint through Brew and make sure your build phases contain a step for running SwiftLint

Ferdzz avatar May 17 '22 16:05 Ferdzz

Thank you for the nonpatronizing response and solution, @Ferdzz.

roz0n avatar May 21 '22 00:05 roz0n

I think enough advice has been provided. Closing the issue for now.

SimplyDanny avatar Sep 18 '22 13:09 SimplyDanny