Rwaydha
Rwaydha

Reputation: 211

No lintable files found at paths SwiftLint

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?

Upvotes: 17

Views: 19743

Answers (12)

musakokcen
musakokcen

Reputation: 394

One of the reasons for this error is directory of the .swiftlint.yml file. If you locate it wrong, then it may not work as expected. If your swiftlint file is in the parent folder, then you should specify it with ../ prefix,

--config ${SRCROOT}/../.swiftlint.yml

The next point is the directory of included files. In .swiftlint.yml file, included files' directory might be wrong if you specify included and excluded files.

Upvotes: 0

Nikunj Gangani
Nikunj Gangani

Reputation: 354

This code is useful for those who use SwiftLint using cocoa pods.

Add the below line in the Run script.

1.

"${PODS_ROOT}/SwiftLint/swiftlint"

If you get the error again, use the below script.

2.

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

After a spend long time to find error like

Error: No lintable files found at paths: ''

The above 2nd script works for me.

Upvotes: 0

Yusuf
Yusuf

Reputation: 991

Replace autocorrect with --fix

export PATH="$PATH:/opt/homebrew/bin"

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

Upvotes: 3

Aaban Tariq Murtaza
Aaban Tariq Murtaza

Reputation: 1252

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

Upvotes: 0

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

Upvotes: -2

Bhavnish
Bhavnish

Reputation: 112

If you using pod file then follow this steps:

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

enter image description here

enter image description here

Upvotes: -2

Aaron
Aaron

Reputation: 419

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.

Upvotes: 3

GyroCocoa
GyroCocoa

Reputation: 1612

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.

Upvotes: 4

Medhi
Medhi

Reputation: 3245

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

Upvotes: 14

Jochen Holzer
Jochen Holzer

Reputation: 1736

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

Upvotes: 1

Ahmed Komsan
Ahmed Komsan

Reputation: 61

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

Upvotes: 2

Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40247

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

Upvotes: 3

Related Questions