9

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.

0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, in my case it worked in this way (without bin folder): /Users/yaircarreno/Documents/MyiOsProject/Pods/SwiftLint/swiftlint lint
2

Seems this command is renamed to:

swiftlint --fix

This command launches autocorrection successfully!

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.