8

I have installed swiftlint using cocoapods and it is working properly

But when I am trying to use swiftlint autocorrect command in the terminal, it is giving below error

-bash: swiftlint: command not found

Should I need to do any other setup to make the command work in Terminal?

Note: Cant use the SwiftLint package due to some restriction on Mac.

pradeep
  • 413
  • 2
  • 7
  • 20

2 Answers2

8

Pods are installed in a folder local to your project, not in any global folder that would already be defined in the terminals $PATH variable, so the terminal is unable to find the script.

There are a few options, but it mostly comes down to being more specific about where the executable is, presuming (for example) your project folder is located at /Users/John/Documents/MyiOsProject/

The pods are likely installed in Pods/SwiftLint/bin

so you should be able to run /Users/John/Documents/MyiOsProject/Pods/SwiftLint/bin/swiftlint autocorrect

This can obviously get tedious very quickly, so just alias it. (Another option would be a Symlink)

open up the file ~/.bashrc for editing and add

alias swiftlint='/Users/John/Documents/MyiOsProject/Pods/SwiftLint/bin/swiftlint'

then you should be able to just type swiftlint autocorrect.

Note: I dont know your exact paths, so you may need to make some minor changes.

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • 2
    Thanks, in my case it worked in this way (without bin folder): /Users/yaircarreno/Documents/MyiOsProject/Pods/SwiftLint/swiftlint lint – yaircarreno May 31 '20 at 15:24
1

Installing swiftlint as a cocoapod does not modify the $PATH variable to include the path to the swiftlint command. Here is a guide to do it.

The path to the swiftlint command is probably $HOME/Pods/SwiftLint or sth like that.

Fabian
  • 5,040
  • 2
  • 23
  • 35