Giter VIP home page Giter VIP logo

Comments (6)

chandlerwall avatar chandlerwall commented on May 27, 2024

I checked out SwiftLint's source to debug the issue a bit and found the cause: SwiftLintCore.SwiftVersion does not compare string versions reliably, preventing version-specific workarounds from being applied.

public struct SwiftVersion: RawRepresentable, Codable, Comparable {
public typealias RawValue = String
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
public static func < (lhs: SwiftVersion, rhs: SwiftVersion) -> Bool {
return lhs.rawValue < rhs.rawValue
}
}

For Swift 5.10, version-specific workarounds are not applied correctly. Specifically, LintableFilesVisitor.parallel is assigned true instead of false when SwiftVersion.current < .fiveDotSix returns an incorrect value.

if let compilerInvocations {
self.mode = .analyze(allCompilerInvocations: compilerInvocations)
// SourceKit had some changes in 5.6 that makes it ~100x more expensive
// to process files concurrently. By processing files serially, it's
// only 2x slower than before.
self.parallel = SwiftVersion.current < .fiveDotSix
} else {
self.mode = .lint
self.parallel = true
}

I replaced SwiftVersion with the following:

/// A value describing the version of the Swift compiler.
public struct SwiftVersion: RawRepresentable, Codable, Comparable, Sendable {
    public typealias RawValue = String

    public let rawValue: String

    public init(rawValue: String) {
        self.rawValue = rawValue
    }

  public static func < (lhs: SwiftVersion, rhs: SwiftVersion) -> Bool {
      func versionComponents(from version: String) -> [Int] {
          return version.components(separatedBy: ".").compactMap { Int($0) }
      }

      let lhsComponents = versionComponents(from: lhs.rawValue)
      let rhsComponents = versionComponents(from: rhs.rawValue)

      for (lhsComponent, rhsComponent) in zip(lhsComponents, rhsComponents) {
          if lhsComponent < rhsComponent {
              return true
          } else if lhsComponent > rhsComponent {
              return false
          }
      }

      return lhsComponents.count < rhsComponents.count
  }
}

Note: I used Claude to implement static func < (lhs:rhs:). I wanted to save time while troubleshooting. The implementation may or may not handle edge cases correctly. I only verified the implementation for my environment.

With the changes in place, I'm able to run swiftlint analyze on a larger set of files. The run below was limited to 30 files. I also verified the result on a run with 350+ files.

Analyzing Swift files in current working directory
Collecting 'Modules/Sources/StyleGuide/_exported.swift' (1/30)
Collecting 'SomethingsWrong.swift' (2/30)
Collecting 'ToolbarMenuButton.swift' (3/30)
Collecting 'ShowInMusicMenuButton.swift' (4/30)
Collecting 'View+hidden.swift' (5/30)
Collecting 'View+foregroundStyle.swift' (6/30)
Collecting 'View+dimensionOverlay.swift' (7/30)
Collecting 'View+enabled.swift' (8/30)
Collecting 'View+firstTextCenterline.swift' (9/30)
Collecting 'HeaderTitle.swift' (10/30)
Collecting 'ExplicitTitle.swift' (11/30)
Collecting 'LabelStyle.swift' (12/30)
Collecting 'StyleGuide.swift' (13/30)
Collecting 'ActiveTrackIcon.swift' (14/30)
Collecting 'FontPreview.swift' (15/30)
Collecting 'CountsView.swift' (16/30)
Collecting 'NoSearchResults.swift' (17/30)
Collecting 'LibraryIcon.swift' (18/30)
Collecting 'PresentationState.swift' (19/30)
Collecting 'AlertPresentation.swift' (20/30)
Collecting 'ConfirmationDialogPresentation.swift' (21/30)
Collecting 'Symbol.swift' (22/30)
Collecting 'SearchControllerProxy.swift' (23/30)
Collecting 'EnvironmentAction.swift' (24/30)
Collecting 'Resolvable.swift' (25/30)
Collecting 'SearchableUIHostingController.swift' (26/30)
Collecting 'SearchScope.swift' (27/30)
Collecting 'RelativeTimeframe.swift' (28/30)
Collecting 'SimilarityResult.swift' (29/30)
Collecting 'Counts.swift' (30/30)
Analyzing 'Modules/Sources/StyleGuide/_exported.swift' (1/30)
Analyzing 'SomethingsWrong.swift' (2/30)
Analyzing 'ToolbarMenuButton.swift' (3/30)
Analyzing 'ShowInMusicMenuButton.swift' (4/30)
Analyzing 'View+hidden.swift' (5/30)
Analyzing 'View+foregroundStyle.swift' (6/30)
Analyzing 'View+dimensionOverlay.swift' (7/30)
Analyzing 'View+enabled.swift' (8/30)
Analyzing 'View+firstTextCenterline.swift' (9/30)
Analyzing 'HeaderTitle.swift' (10/30)
Analyzing 'ExplicitTitle.swift' (11/30)
Analyzing 'LabelStyle.swift' (12/30)
Analyzing 'StyleGuide.swift' (13/30)
Analyzing 'ActiveTrackIcon.swift' (14/30)
Analyzing 'FontPreview.swift' (15/30)
Analyzing 'CountsView.swift' (16/30)
Analyzing 'NoSearchResults.swift' (17/30)
Analyzing 'LibraryIcon.swift' (18/30)
Analyzing 'PresentationState.swift' (19/30)
Analyzing 'AlertPresentation.swift' (20/30)
Analyzing 'ConfirmationDialogPresentation.swift' (21/30)
Analyzing 'Symbol.swift' (22/30)
Analyzing 'SearchControllerProxy.swift' (23/30)
Analyzing 'EnvironmentAction.swift' (24/30)
Analyzing 'Resolvable.swift' (25/30)
Analyzing 'SearchableUIHostingController.swift' (26/30)
Analyzing 'SearchScope.swift' (27/30)
Analyzing 'RelativeTimeframe.swift' (28/30)
Analyzing 'SimilarityResult.swift' (29/30)
Analyzing 'Counts.swift' (30/30)
Done analyzing! Found 0 violations, 0 serious in 30 files.

from swiftlint.

SimplyDanny avatar SimplyDanny commented on May 27, 2024

Can the stop of analysis be associated with a specific file maybe?

from swiftlint.

chandlerwall avatar chandlerwall commented on May 27, 2024

Can the stop of analysis be associated with a specific file maybe?

I started my troubleshooting by adjusting included and excluded to find a problematic file. I started with a small number of files and gradually included more files until the issue occurred. I thought I found the problematic file. I added more files and noticed the issue again. I tested different combinations and realized I could move "problematic" files from excluded to included without triggering the issue. As long as I keep the file count very low, the command finished. As soon as I added an extra file, the command chokes.

from swiftlint.

SimplyDanny avatar SimplyDanny commented on May 27, 2024

Forget my previous question. You were obviously a little faster with the detailed report of your investigation. I didn't notice it while crafting my message.

Your reasoning makes a lot of sense. Looks like SwiftVersion wasn't developed with version components >9 in mind or the implementors didn't expect such high numbers.

Would you like to open a PR to fix the comparison algorithm?

from swiftlint.

chandlerwall avatar chandlerwall commented on May 27, 2024

Yes, I will prepare a PR with a fix for the comparison algorithm. Appreciate the quick responses!

from swiftlint.

NachoSoto avatar NachoSoto commented on May 27, 2024

I'm seeing the exact same thing. For me it stops after 14 files, no matter what file that is.

from swiftlint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.