Swiftformat: No eligible files found error when all checked files are ignored

Created on 29 Jul 2019  路  5Comments  路  Source: nicklockwood/SwiftFormat

Description

Hi, we discovered an issue that sounds quite similar to #368. As soon as we pass only files that are excluded in the .swiftformat config, SwiftFormat will fail with the error message _"error: No eligible files found at ..."_

Steps to reproduce

  1. Add any folder to the exclusion list in the .swiftformat config file, e.g. Pods
  2. Run swiftformat using the config file, and pass files that are included in the excluded directory
# Example
$ swiftformat --config .swiftformat --verbose /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/Validatable.swift /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/ColorResource.swift

Expected results

I'd expect a successful run of SwiftFormat with the message 0/2 files formatted.

Actual results

SwiftFormat throws an error:

Running SwiftFormat...
Skipping /Users/ffittschen/Code/project/Pods
-- ignored
Skipping /Users/ffittschen/Code/project/Pods
-- ignored
error: No eligible files found at /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/ColorResource.swift, /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/Validatable.swift.

As soon as there is one file that is not within any of the excluded folders, the execution is as expected:

$ swiftformat --config .swiftformat --verbose /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/Validatable.swift /Users/ffittschen/Code/project/Pods/R.swift.Library/Library/Core/ColorResource.swift /Users/ffittschen/Code/project/Project/AppDelegate.swift

Running SwiftFormat...
Skipping /Users/ffittschen/Code/project/Pods
-- ignored
Formatting /Users/ffittschen/Code/project/Project/AppDelegate.swift
 -- no changes
Skipping /Users/ffittschen/Code/project/Pods
-- ignored

SwiftFormat completed in 0.02s.
0/1 files formatted.
bug known issue

Most helpful comment

Ahh, I see. Yes, we are using the danger-ruby-swiftformat plugin for danger to run SwiftFormat as check for each PR. The plugin only passes modified files to SwiftFormat, which resulted in the above mentioned error in one of our recent PRs containing only updates of dependencies.

As a workaround we duplicated the excludes that are already in our .swiftformat config and added them as config of the plugin to the Dangerfile:

swiftformat.exclude = %w(Pods/** Carthage/** **/*generated.swift)

All 5 comments

The idea here is to avoid a situation where SwiftFormat fails silently when you've accidentally misconfigured it so that all files are being ignored.

Can you explain a bit more about the use case for passing only excluded files? Is it because you are using a hook that only submits modified files for formatting?

Ahh, I see. Yes, we are using the danger-ruby-swiftformat plugin for danger to run SwiftFormat as check for each PR. The plugin only passes modified files to SwiftFormat, which resulted in the above mentioned error in one of our recent PRs containing only updates of dependencies.

As a workaround we duplicated the excludes that are already in our .swiftformat config and added them as config of the plugin to the Dangerfile:

swiftformat.exclude = %w(Pods/** Carthage/** **/*generated.swift)

@ffittschen thanks for the workaround!

We have the same issue and the workaround is not enough for us. We are using swiftformat as part of our xcode build phase and this failure causes Xcode to stop building - when only assets have changed which causes a rebuild of R.swift.generated only (which is excluded similarly).

This should be fixed in 0.44.11. The "No eligible files found" error has been downgraded to a warning.

Was this page helpful?
0 / 5 - 0 ratings