13

I tried to install SwiftLint using CocoaPods and I add in Build phases the following script :

"${PODS_ROOT}/SwiftLint/swiftlint" 

SwiftLint is installed correctly and I get many errors and warnings in the project.

Then, I create the swiftLint.yml file in which I modify some rules but they are not token into consideration and the same number of errors and warnings persist in Xcode project.

When I run this command to confirm the application of the rules :

    ./swiftlint lint --config .swiftlint.yml       

I get the error :

 No lintable files found at paths : ''

How can I solve this issue please?

Rwaydha
  • 171
  • 1
  • 2
  • 8

10 Answers10

12

It happens also if you rename the directory of your app, make sure you report the change in the .swiftlint.yml too at first lines :

 included: # paths to include during linting
    - My_App_Directory
Medhi
  • 2,656
  • 23
  • 16
  • 1
    That was my problem. The default .swiftlint.yml file includes only the "Sources" folder. They should warn people about that on the Readme. – GabrielaBezerra Aug 10 '21 at 11:54
3

For those of you who used 0.42.0 before and updated to 0.43.0 (or higher?). They made a change and now interpret included and excluded as relative paths.

Configuration files now consistently have their included/excluded relative file paths applied relative to their location in the file system. Previously the root configuration file applied these relative to the current working directory, but nested configurations applied these to their location in the file system.

From the release notes of 0.43.0: Clothes Line Interface.

Aaron
  • 413
  • 5
  • 13
  • So what should I add inside the `.yml` file for the `included` and `excluded`. I simply excluded one of my `.swift` files because I didn't want that to be linted, and didn't added any `included` because I wanted to lint a particular commit file only. – Samarth Kejriwal Oct 25 '21 at 08:53
  • 2
    Use it as usual but keep in mind that they have changed how these paths/filenames are applied. I've added the appropriate part as quote to my answer. E.g. if your `.yml` lays in _myRoot/aFolderName/mySwiftLint.yml_ and you want to exclude a file in _myRoot/aDifferntFolder/myFile.swift_ then you have to add `../aDifferentFolder/myFile.swift` to your `exclude`. – Aaron Oct 25 '21 at 19:58
2
  • if you are using swiftLint with CocoaPods : try "${PODS_ROOT}/SwiftLint/swiftlint" --config .swiflint.yml in your SwiftLint Run Script in your project build phases.

  • make sure your .swiflint.yml config file is in the root of your project directory ( beside .xcodeproj file ).

  • make sure the paths included on your .swiflint.yml (in included: and excluded: sections ) is valid paths

  • make sure your .swiflint.yml file is valid yaml

  • don't escape the directory paths in your config file dont do : - some\ Directorybut do - some Directory without escape character.

  • 1
    I tried it like `--config .swiflint.yml` and it didn't work, but the below answer did: `--config "${PROJECT_DIR}/.swiftlint.yml"` (Xcode 12.1) – danywarner Dec 31 '20 at 12:07
2

If you installed it using Cocoapods this can help you. I will just merely improve the above answers, to put clarity on how to resolve the issue of SwiftLint not finding the path.

Things to lookout for.

  • Make sure your swiftlint.yml file is valid.
  • Make sure the swiftlint.yml is in the same level as your .xcodeproj
  • Don't specify --path and also add an entry under included: inside your yml file, choose one, either specify the --path or add an entry don't use both otherwise SwiftLint will ignore the --path param, and if the entry specified inside included: is wrong you will get the "no lintable file found" error

In your script.

  • The gihub page of SwiftLint recommends just using "${PODS_ROOT}/SwiftLint/swiftlint" but that didn't work for me, I had to specify the --path see below for the full script.

"${PODS_ROOT}/SwiftLint/swiftlint" --path "${SRCROOT}/Classes" --config "directory-of-your-config"

The --path param should be your own --path "${SRCROOT}/Classes"

enter image description here

Finally inside the yml file.

Make sure your included and excluded file specification is correct, see how I did mine below.

included:
  - Your-Project-Name
  
excluded:
  - Pods

One Important thing to note is if you add directories under included: the --path param will be ignored, and you might possibly get the "no lintable files found" error if the directory is wrong.

GyroCocoa
  • 1,542
  • 16
  • 19
1

First of all, you do not need to add explicitly the--config file if the yml file is in the running directory (from where you are running the command) and name is .swiftlint.yml.

Secondly, you need to specify the path for your source with --path. Below command will work fine in your case,

swiftlint lint --path SourcePath
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
1

For swiftlint from version 0.41 the following code worked for me in the build phase (workspace with several projects. Depending on the project configuration, it may be that "../" has to be removed from the path information):

cd ${PROJECT_DIR}/../
"${PODS_ROOT}/SwiftLint/swiftlint" --config "${PROJECT_DIR}/../.swiftlint.yml"

Here is a screenshot of the build phase entry:

Build Phase Entry for swiftlint via cocoapods

Jochen Holzer
  • 1,598
  • 19
  • 25
0

Replace autocorrect with --fix

export PATH="$PATH:/opt/homebrew/bin" //This line is only for Apple Silicon chips

if which swiftlint > /dev/null; then
  swiftlint --fix && swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Yusuf
  • 851
  • 6
  • 14
-1

For M1, don't go for swift lint installation VIA PODS instead use Brew. For installation run below command in Terminal

brew install swiftlint

and add below scripts into RunScript into build phase of your target.

export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Aaban Tariq Murtaza
  • 1,155
  • 14
  • 16
-2
If you using pod file then follow this steps:

Run Script: "${PODS_ROOT}/SwiftLint/swiftlint"

enter image description here

enter image description here

Bhavnish
  • 42
  • 1
  • 6
-2

This worked for me

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