diff --git a/.github/workflows/actor-credentials.yml b/.github/workflows/actor-credentials.yml index b51059e0f1..bb7c32344c 100644 --- a/.github/workflows/actor-credentials.yml +++ b/.github/workflows/actor-credentials.yml @@ -20,6 +20,7 @@ on: jobs: configure: + if: false runs-on: ubuntu-slim outputs: name: ${{ steps.configure_git_author.outputs.name }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bf77fc296..db99ac0e5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ permissions: jobs: bazel_linux: + if: false name: Bazel, Linux, Swift 6.2 # pre-installed runs-on: ubuntu-24.04 steps: @@ -22,6 +23,7 @@ jobs: CI_BAZELRC_FILE_CONTENT: ${{ secrets.CI_BAZELRC_FILE_CONTENT }} plugins_linux: + if: false name: SPM plugins, Linux, Swift ${{ matrix.version }} runs-on: ubuntu-24.04 strategy: diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 8b53c2643d..6085a7f744 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -9,6 +9,7 @@ on: jobs: # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. copilot-setup-steps: + if: false name: Perform runs-on: ubuntu-24.04 # Swift containers don't work with Copilot diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c929d179c7..14cb0e41ab 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -17,6 +17,7 @@ on: jobs: set-context: + if: false name: Set Context runs-on: ubuntu-slim permissions: {} @@ -50,6 +51,7 @@ jobs: INPUTS_TAG: ${{ inputs.tag }} build-amd64: + if: false name: Build AMD64 Image runs-on: ubuntu-24.04 permissions: @@ -72,6 +74,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} build-arm64: + if: false name: Build ARM64 Image runs-on: ubuntu-24.04-arm permissions: @@ -94,6 +97,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} merge: + if: false name: Create Multi-Platform Image runs-on: ubuntu-24.04 permissions: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0516df0787..742cb56205 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -7,6 +7,7 @@ on: jobs: create-docs: + if: false name: Create runs-on: ubuntu-24.04 permissions: @@ -71,7 +72,7 @@ jobs: name: Deploy runs-on: ubuntu-slim needs: create-docs - if: github.event_name == 'push' + if: false # github.event_name == 'push' permissions: pages: write id-token: write diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f3a6adeb74..7e431d25fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,6 +9,7 @@ permissions: jobs: lint-swift: + if: false name: Swift runs-on: ubuntu-24.04 # "Noble Numbat" steps: @@ -22,6 +23,7 @@ jobs: - name: Lint run: ./bazel-bin/swiftlint lint --reporter github-actions-logging --strict 2> /dev/null lint-markdown: + if: false name: Markdown runs-on: ubuntu-slim steps: @@ -36,6 +38,7 @@ jobs: CONTRIBUTING.md README.md lint-actions: + if: false name: Actions runs-on: ubuntu-24.04 steps: diff --git a/.github/workflows/plugins-sync.yml b/.github/workflows/plugins-sync.yml index 535ef0f127..ad21254397 100644 --- a/.github/workflows/plugins-sync.yml +++ b/.github/workflows/plugins-sync.yml @@ -13,6 +13,7 @@ permissions: jobs: sync: + if: false name: Sync Plugins Folder runs-on: ubuntu-slim steps: diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml index 0fc3bbdf10..88f60bff22 100644 --- a/.github/workflows/post-release.yml +++ b/.github/workflows/post-release.yml @@ -6,6 +6,7 @@ on: jobs: setup-credentials: + if: false name: Setup Actor Credentials uses: ./.github/workflows/actor-credentials.yml with: @@ -15,6 +16,7 @@ jobs: secrets: inherit merge-into-main: + if: false name: Merge into main needs: setup-credentials runs-on: ubuntu-slim @@ -40,6 +42,7 @@ jobs: TAG_NAME: ${{ github.event.release.tag_name }} publish-pod: + if: false name: Publish Pod needs: - merge-into-main @@ -59,6 +62,7 @@ jobs: COCOAPODS_TRUNK_TOKEN: ${{ secrets[format('COCOAPODS_TRUNK_TOKEN_{0}', needs.setup-credentials.outputs.author_uppercase)] }} dispatch-plugins: + if: false name: Dispatch Plugins Repository needs: merge-into-main runs-on: ubuntu-slim @@ -87,6 +91,7 @@ jobs: } bump-homebrew: + if: false name: Bump Homebrew Formula needs: - merge-into-main @@ -110,6 +115,7 @@ jobs: formulae: swiftlint build-docker: + if: false name: Build Docker Images needs: merge-into-main uses: ./.github/workflows/docker.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb6f7a369d..7789bf0ead 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,7 @@ env: jobs: setup-credentials: + if: false name: Setup Actor Credentials uses: ./.github/workflows/actor-credentials.yml with: @@ -28,6 +29,7 @@ jobs: secrets: inherit prepare-release: + if: false name: Prepare Release runs-on: ubuntu-slim needs: setup-credentials @@ -64,6 +66,7 @@ jobs: git push origin HEAD verify-podspec: + if: false name: Verify Podspec runs-on: macOS-14 permissions: @@ -88,6 +91,7 @@ jobs: make pod_lint build-linux: + if: false name: Build Linux ${{ matrix.arch }} Binary needs: prepare-release runs-on: ${{ matrix.runner }} @@ -119,6 +123,7 @@ jobs: path: .build/release/swiftlint build-static-linux: + if: false name: Build Static Linux ${{ matrix.arch }} Binary needs: prepare-release runs-on: ${{ matrix.runner }} @@ -182,6 +187,7 @@ jobs: LICENSE.mimalloc build-macos: + if: false name: Build macOS Binaries needs: prepare-release runs-on: macOS-26 @@ -206,6 +212,7 @@ jobs: if-no-files-found: error create-release: + if: false name: Create Release needs: - setup-credentials diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml index 875db8002f..caed7c62d7 100644 --- a/.github/workflows/stale-issues.yml +++ b/.github/workflows/stale-issues.yml @@ -10,6 +10,7 @@ permissions: jobs: close-stale-issues: + if: false runs-on: ubuntu-24.04 steps: - name: Checkout repository diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca741a2edf..e09c4bf57d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ env: jobs: spm_linux: + if: false name: SPM, Linux, Swift 6.2 runs-on: ubuntu-24.04 container: swift:6.2-noble @@ -34,6 +35,7 @@ jobs: rule: spm_test spm_macos: + if: false name: SPM, macOS ${{ matrix.macOS }}, Xcode ${{ matrix.xcode }} runs-on: macos-${{ matrix.macOS }} strategy: @@ -60,6 +62,7 @@ jobs: run: make spm_test spm_windows: + if: false name: SPM, Windows ${{ matrix.windows-display-name }} runs-on: windows-${{ matrix.windows-version }} env: diff --git a/.swiftlint.yml b/.swiftlint.yml index d2ad46c444..6fcbad4a23 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -76,8 +76,8 @@ file_name: - SwiftSyntax+SwiftLint.swift - TestHelpers.swift excluded_paths: - - Tests/GeneratedTests/GeneratedTests_\d\d\.swift - - Tests/FileSystemAccessTests/.+\.swift + - Tests[\\/]GeneratedTests[\\/]GeneratedTests_\d\d\.swift + - Tests[\\/]FileSystemAccessTests[\\/].+\.swift final_test_case: *unit_test_configuration function_body_length: 60 identifier_name: diff --git a/Source/SwiftLintCore/Models/Baseline.swift b/Source/SwiftLintCore/Models/Baseline.swift index 05bbd29add..79603d4bab 100644 --- a/Source/SwiftLintCore/Models/Baseline.swift +++ b/Source/SwiftLintCore/Models/Baseline.swift @@ -191,7 +191,9 @@ private extension StyleViolation { var withAbsolutePath: StyleViolation { let absolutePath: String? = if let relativePath = location.file { - FileManager.default.currentDirectoryPath + "/" + relativePath + URL(fileURLWithPath: FileManager.default.currentDirectoryPath) + .appendingPathComponent(relativePath) + .filepath } else { nil } diff --git a/Source/SwiftLintCore/Models/Location.swift b/Source/SwiftLintCore/Models/Location.swift index 4bb174207c..1c600ac987 100644 --- a/Source/SwiftLintCore/Models/Location.swift +++ b/Source/SwiftLintCore/Models/Location.swift @@ -23,7 +23,16 @@ public struct Location: CustomStringConvertible, Comparable, Codable, Sendable { /// The file path for this location relative to the current working directory. public var relativeFile: String? { - file?.replacingOccurrences(of: FileManager.default.currentDirectoryPath + "/", with: "") + guard let file else { return nil } + let fileComponents = URL(fileURLWithPath: file).pathComponents + let baseComponents = URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true) + .pathComponents + + guard fileComponents.starts(with: baseComponents) else { + return file + } + + return fileComponents.dropFirst(baseComponents.count).joined(separator: "/") } /// Creates a `Location` by specifying its properties directly. diff --git a/Source/SwiftLintFramework/Configuration+CommandLine.swift b/Source/SwiftLintFramework/Configuration+CommandLine.swift index ed91876931..b36a65aa55 100644 --- a/Source/SwiftLintFramework/Configuration+CommandLine.swift +++ b/Source/SwiftLintFramework/Configuration+CommandLine.swift @@ -138,7 +138,7 @@ extension Configuration { pathComponents.removeFirst() } - return pathComponents.joined(separator: "/") + return pathComponents.reduce(URL(fileURLWithPath: "/")) { $0.appendingPathComponent($1) }.filepath } private func linters(for filesPerConfiguration: [Configuration: [SwiftLintFile]], diff --git a/Source/SwiftLintFramework/Configuration/Configuration+Cache.swift b/Source/SwiftLintFramework/Configuration/Configuration+Cache.swift index 47bf254fe7..a8294914c7 100644 --- a/Source/SwiftLintFramework/Configuration/Configuration+Cache.swift +++ b/Source/SwiftLintFramework/Configuration/Configuration+Cache.swift @@ -81,13 +81,12 @@ extension Configuration { #endif } - let versionedDirectory = [ - "SwiftLint", - Version.current.value, - ExecutableInfo.buildID, - ].compactMap(\.self).joined(separator: "/") - - let folder = baseURL.appendingPathComponent(versionedDirectory) + var folder = baseURL + .appendingPathComponent("SwiftLint") + .appendingPathComponent(Version.current.value) + if let buildID = ExecutableInfo.buildID { + folder = folder.appendingPathComponent(buildID) + } do { try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true, attributes: nil) diff --git a/Source/swiftlint/Commands/Docs.swift b/Source/swiftlint/Commands/Docs.swift index 8b3d368e3a..c9c4fa90f4 100644 --- a/Source/swiftlint/Commands/Docs.swift +++ b/Source/swiftlint/Commands/Docs.swift @@ -33,6 +33,10 @@ private func open(_ url: URL) { let command = "xdg-open" process.arguments = [command, url.absoluteString] try? process.run() +#elseif os(Windows) + process.executableURL = URL(fileURLWithPath: "cmd", isDirectory: false) + process.arguments = ["/C", "start", url.absoluteString] + try? process.run() #else process.launchPath = "/usr/bin/env" let command = "open" diff --git a/Tests/BuiltInRulesTests/FileNameRuleTests.swift b/Tests/BuiltInRulesTests/FileNameRuleTests.swift index d81ede7ffa..af517a1e46 100644 --- a/Tests/BuiltInRulesTests/FileNameRuleTests.swift +++ b/Tests/BuiltInRulesTests/FileNameRuleTests.swift @@ -2,7 +2,8 @@ import TestHelpers import XCTest -private let fixturesDirectory = "\(TestResources.path())/FileNameRuleFixtures" +private let fixturesDirectory = + URL(fileURLWithPath: TestResources.path()).appendingPathComponent("FileNameRuleFixtures").filepath final class FileNameRuleTests: SwiftLintTestCase { private func validate(fileName: String, @@ -165,7 +166,7 @@ final class FileNameRuleTests: SwiftLintTestCase { try validate( fileName: "main.swift", excluded: [], - excludedPaths: [".*/FileNameRuleFixtures/.*"] + excludedPaths: [#".*[\\/]FileNameRuleFixtures[\\/].*"#] ).isEmpty ) } @@ -175,7 +176,7 @@ final class FileNameRuleTests: SwiftLintTestCase { try validate( fileName: "main.swift", excluded: [], - excludedPaths: [".*/OtherFolder/.*", "MAIN\\.swift"] + excludedPaths: [#".*[\\/]OtherFolder[\\/].*"#, "MAIN\\.swift"] ).isNotEmpty ) } @@ -197,7 +198,7 @@ final class FileNameRuleTests: SwiftLintTestCase { try validate( fileName: "main.swift", excluded: [], - excludedPaths: ["/FileNameRuleFixtures/.*", "("] + excludedPaths: [#"[\\/]FileNameRuleFixtures[\\/].*"#, "("] ) ) @@ -205,7 +206,7 @@ final class FileNameRuleTests: SwiftLintTestCase { try validate( fileName: "main.swift", excluded: [], - excludedPaths: ["/FileNameRuleFixtures/.*", "(", ".*.swift"] + excludedPaths: [#"[\\/]FileNameRuleFixtures[\\/].*"#, "(", ".*.swift"] ) ) } diff --git a/Tests/FileSystemAccessTests/ReporterTests.swift b/Tests/FileSystemAccessTests/ReporterTests.swift index a9083b9efd..b0eb70170c 100644 --- a/Tests/FileSystemAccessTests/ReporterTests.swift +++ b/Tests/FileSystemAccessTests/ReporterTests.swift @@ -23,7 +23,10 @@ final class ReporterTests: SwiftLintTestCase { ruleDescription: SyntacticSugarRule.description, severity: .error, location: Location( - file: FileManager.default.currentDirectoryPath + "/path/file.swift", + file: URL(fileURLWithPath: FileManager.default.currentDirectoryPath) + .appendingPathComponent("path") + .appendingPathComponent("file.swift") + .path, line: 1, character: 2 ), @@ -43,7 +46,8 @@ final class ReporterTests: SwiftLintTestCase { } private func stringFromFile(_ filename: String) -> String { - SwiftLintFile(path: "\(TestResources.path())/\(filename)")!.contents + let path = URL(fileURLWithPath: TestResources.path()).appendingPathComponent(filename) + return SwiftLintFile(path: path.filepath)!.contents } func testXcodeReporter() throws { @@ -196,9 +200,12 @@ final class ReporterTests: SwiftLintTestCase { line: UInt = #line) throws { let dateFormatter = DateFormatter() dateFormatter.dateStyle = .short + + let cwd = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).path + let reference = stringFromFile(referenceFile).replacingOccurrences( of: "${CURRENT_WORKING_DIRECTORY}", - with: FileManager.default.currentDirectoryPath + with: cwd ).replacingOccurrences( of: "${SWIFTLINT_VERSION}", with: SwiftLintFramework.Version.current.value @@ -210,9 +217,9 @@ final class ReporterTests: SwiftLintTestCase { let convertedReference = try stringConverter(reference) let convertedReporterOutput = try stringConverter(reporterOutput) if convertedReference != convertedReporterOutput { - let referenceURL = URL(fileURLWithPath: "\(TestResources.path())/\(referenceFile)") + let referenceURL = URL(fileURLWithPath: TestResources.path()).appendingPathComponent(referenceFile) try reporterOutput.replacingOccurrences( - of: FileManager.default.currentDirectoryPath, + of: cwd, with: "${CURRENT_WORKING_DIRECTORY}" ).replacingOccurrences( of: SwiftLintFramework.Version.current.value, diff --git a/Tests/TestHelpers/TestResources.swift b/Tests/TestHelpers/TestResources.swift index 58a7f13bb0..cd796a2693 100644 --- a/Tests/TestHelpers/TestResources.swift +++ b/Tests/TestHelpers/TestResources.swift @@ -9,7 +9,6 @@ public enum TestResources { } return folder .appendingPathComponent("Resources") - .path - .absolutePathStandardized() + .filepath } }