Skip to content

Run SwiftLint with custom configuration on multiple files #3038

Closed

Description

@josemiguelmelo

New Issue Checklist

Describe the bug

At Codacy, we are using SwiftLint to analyse Swift code.

We are trying to use a custom configuration file by passing it to --config param.
If the source code directory contains a .swiftlint.yml file and we run SwiftLint with a custom configuration on 2 or more specific files (by passing them as param to the command), it ignores the custom the configuration and uses .swiftlint.yml file present inside the source code directory.

If I run the same command but specifying only 1 file or a directory with multiple files inside, it uses the custom configuration file we are providing.

Example

As an example, we have a /src folder with the following files:

  • dynamic_inline.swift - with dynamic_inline violation:
    class C {
    @inline(__always) dynamic func f() {}
    }

    class C {
    @inline(__always) public dynamic func f() {}
    }

    class C {
    @inline(__always) dynamic internal func f() {}
    }

    class C {
    @inline(__always)
    dynamic func f() {}
    }

    class C {
    @inline(__always)
    dynamic
    func f() {}
    }
  • closing_brace.swift - with closing_brace violation:
    [].map({ } )

    [].map({ }	)
  • .test.yml file:
whitelist_rules:
  - dynamic_inline
  • .swiftlint.yml file:
whitelist_rules:
  - closing_brace

With this source folder, we are making these tests:

  1. Custom configuration file (.test.yml) and analysing 1 file - returns the expected result
$ swiftlint lint --config /src/.test.yml /src/dynamic_inline.swift

Loading configuration from '/src/.test.yml'
Linting Swift files at paths /src/dynamic_inline.swift
Linting 'dynamic_inline.swift' (1/1)
/src/dynamic_inline.swift:3:31: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:7:38: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:11:40: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:16:13: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:22:5: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
Done linting! Found 5 violations, 5 serious in 1 file.
  1. Custom configuration file (.test.yml) and analysing entire src folder - returns the expected result
$ swiftlint lint --config /src/.test.yml /src/

Loading configuration from '/src/.test.yml'
Linting Swift files at paths /src/dynamic_inline.swift
Linting 'dynamic_inline.swift' (1/1)
/src/dynamic_inline.swift:3:31: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:7:38: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:11:40: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:16:13: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
/src/dynamic_inline.swift:22:5: error: Dynamic Inline Violation: Avoid using 'dynamic' and '@inline(__always)' together. (dynamic_inline)
Done linting! Found 5 violations, 5 serious in 1 file.
  1. Custom configuration file (.test.yml) and analysing 2 or more files - returns result different from the expected
$ swiftlint lint --config /src/.test.yml /src/dynamic_inline.swift /src/closing_brace.swift

Loading configuration from '/src/.test.yml'
Linting Swift files at paths /src/dynamic_inline.swift, /src/closing_brace.swift
Linting 'closing_brace.swift' (1/2)
Linting 'dynamic_inline.swift' (2/2)
/src/closing_brace.swift:1:14: warning: Closing Brace Spacing Violation: Closing brace with closing parenthesis should not have any whitespaces in the middle. (closing_brace)
/src/closing_brace.swift:3:14: warning: Closing Brace Spacing Violation: Closing brace with closing parenthesis should not have any whitespaces in the middle. (closing_brace)
Done linting! Found 2 violations, 0 serious in 2 files.

Environment

  • SwiftLint version: 0.38.2

Activity

  1. laxmorek commented on Aug 31, 2020

    @laxmorek

    Problem still occurs in 0.40.1.

  2. stale commented on Nov 8, 2020

    @stale

    This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

  3. added
    wontfix
    on Nov 8, 2020
  4. sethfri commented on Nov 9, 2020

    @sethfri
    Contributor

    @josemiguelmelo @laxmorek Do you mind checking to see if you still see this behavior in 0.41.0? I did some work in this area where we should now always be treating --config as an explicit override, but I don't think I tested your use case explicitly. Thanks!

  5. removed
    wontfix
    on Nov 9, 2020
  6. stale commented on Jan 8, 2021

    @stale

    This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

  7. added
    wontfix
    on Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions