Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Exclude Files/Folders for SwiftLint Using CocoaPods?

The Problem

When building my xcode Swift project, I am getting violations from SwiftLint (i.e. Empty Count Violations) of files/folders that I exclude in my .swiftlint.yml file, but when specifying those files/folders in the excluded section, the violations still occur.

Code

.swiftlint.yml

included:

excluded:
  - Pods
  - myproject/API/api_implementation.swift
  - myproject/API

Build Phases Run Script

"${PODS_ROOT}/SwiftLint/swiftlint"

Project Structure

/projectroot
    .swiftlint.yml
    Pods/
    myproject/
        API/
            api_implementation.swift

Neither myproject/API/api_implementation.swift nor the entire directory myproject/API/ are excluded from the lint!

The Question

What is incorrect in terms of making this file and folder excluded from the lint? If my syntax is incorrect, what is the correct syntax? If my path is incorrect, where is the SwiftLint file run from? Interestingly, even though the .swiftlint.yml file is in the root of my project, the swiftlint file that is run is in Pods/SwiftLint/

Perhaps the way that Cocoapods requires additional integration for SwiftLint to work would cause this problem. I have tried, however, to empty the Build Phases Run Script, and have confirmed that the .swiftlint.yml file is indeed running on build.

Any help or thoughts would be appreciated!

like image 583
gpsugy Avatar asked Jul 20 '18 19:07

gpsugy


People also ask

What files does CocoaPods remove by default?

By default, CocoaPods removes all files that are not matched by any of the other file pattern. The module map file that should be used when this pod is integrated as a framework.

When to use multiple configuration files in swiftlint?

There are quite a lot of use cases where using multiple configuration files could be helpful: For instance, one could use a team-wide shared SwiftLint configuration while allowing overrides in each project via a child configuration file. You can specify a child_config and / or a parent_config reference within a configuration file.

What versions of Swift does CocoaPods support?

The versions of Swift that the specification supports. A version of '4' will be treated as '4.0' by CocoaPods and not '4.1' or '4.2'. Note The Swift compiler mostly accepts major versions and sometimes will honor minor versions. While CocoaPods allows specifying a minor or patch version it might not be honored fully by the Swift compiler.

Why linting is disabled when correcting a Swift file?

Standard linting is disabled while correcting because of the high likelihood of violations (or their offsets) being incorrect after modifying a file while applying corrections. The swiftlint analyze command can lint Swift files using the full type-checked AST.


2 Answers

The syntax and content of your .swiftlint.yml looks correct to me, but I wonder if the problem comes down to Groups vs Folders in Xcode?

SwiftLint only looks at the location of the source files on disk rather than using the hierarchy shown in the Project Navigator in Xcode. You need to make sure that the files you expect to be excluded are definitely in the API directory when you look in Finder, and not just the API group in Xcode.

like image 114
rodhan Avatar answered Oct 25 '22 20:10

rodhan


I had a similar problem. Somehow I ended up with additional symbols such as U+2067 which aren't seen in a text editor. I managed to remove them in vim. Here's a screenshot of git diff command after removing unnecessary symbols: enter image description here

Maybe it will help

like image 1
GeRyCh Avatar answered Oct 25 '22 19:10

GeRyCh