Search code examples
iosswiftcocoapodsswiftlint

Swiftlint autocorrect command not working


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.


Solution

  • 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.