Giter VIP home page Giter VIP logo

swiftlintplugin's Introduction

SwiftLintPlugin

Twitter: @lukeeep_

A Swift Package Plugin for SwiftLint that will run SwiftLint on build time and show errors & warnings in Xcode.

Note There now is an official version in the SwiftLint repo! Though this package will still be maintained and updated since it brings the benefit of being a smaller repository and therefore faster to download as a dependency

Add to Package

First add a dependency from this package:

dependencies: [
    // ...
    .package(url: "https://github.com/lukepistrol/SwiftLintPlugin", from: "0.2.2"),
]

Then add it to your targets as a plugin:

targets: [
    .target(
        name: "YOUR_TARGET",
        dependencies: [],
        plugins: [
            .plugin(name: "SwiftLint", package: "SwiftLintPlugin")
        ]
    ),
]

Add to Project

Starting with Xcode 14, plugins can also work on Xcode Project's targets. To do so, simply add this package to your SPM dependencies in Xcode. After that open your target's settings > Build Phases and add SwiftLint to Run Build Tool Plug-ins like shown below:

Screen Shot 2022-09-02 at 09 33 23

You may need to enable & trust the plugin before you can actually run it during builds.

Fix Warnings

As of version 0.1.0 this package also includes a command plugin which can be called on any target.

  1. Select a project or package in the project navigator.
  2. Richt-click and select SwiftLintFix.
    • alternatively you can select File > Packages > SwiftLintFix.
  3. Choose the target(s) to run the swiftlint --fix command on.

Screenshot 2022-10-31 at 12 59 53

Run on CI

Important to notice is that when building a package/project on any CI provider (e.g. GitHub Actions) it is mandatory to pass the -skipPackagePluginValidation flag to the xcodebuild command. This will skip the validation prompt which in Xcode looks like this:

Screenshot 2022-12-13 at 17 48 44

Example

xcodebuild  \
    -scheme "$SCHEME" \
    -destination "$PLATFORM" \
    -skipPackagePluginValidation \ # this is mandatory
    clean build

If you need to disable linting (for release/app store builds), you can setDISABLE_SWIFTLINT environment variable


Buy Me A Coffee

swiftlintplugin's People

Contributors

kenji21 avatar lukepistrol avatar simba909 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swiftlintplugin's Issues

SwiftLintPlugin does not support provisioning profiles

I've added SwiftLintPlugin as a build phase but I have a problem building the app in the CI where I explicitly provide a provisioning profile (ie. not using automagic signing)

I have the following error

error: SwiftLintPlugin does not support provisioning profiles. SwiftLintPlugin does not support provisioning profiles, but provisioning profile 3cf518f8-8e85-44f7-ac02-12f1ac55de03 has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'SwiftLintPlugin' from project 'SwiftLint')

How can I pre-build the plugin so that xcodebuild doesn't try to sign it with that particular provisioning profile?

Error when archiving in Xcode Cloud

Hi,

I added the TMDb package to a project in Xcode with the SPM. That package has SwiftLint and SwiftLintPlugin as dependencies.
If I archive the code locally from Xcode everything works fine, but when I try to do the same from Xcode Cloud it fails.

Screenshot 2023-10-07 at 10 35 25 AM

At first, I thought it was because I had linting issues, so I fixed them all. If I run SwiftLint locally I don't get any warning.
Checking the logs, I realized that wasn't the problem. The problem is:

Error: You don’t have permission to save the file “f5a82a99c7fcf819a5868248f7fe3ad5ac901d06aa1bfa62415f26aba3e78b03.plist” in the folder “A4FD347F-F59D-3FB2-835A-CAC16AC563DB”.

Then I thought, well, maybe I don't need to run the linter when archiving, and found that setting this env var (DISABLE_SWIFTLINT) should disable the linter. I added it to the workflow but the error is still there.

I'm using Xcode 15.0

Generate a SwiftLint json report

Can it also generate a SwiftLint json report in the package directory?
We have some CI processes that we need SwiftLint reports for.....

Very high CPU usage after adding the plugin to my Swift Package

Whenever I add the Swift Package Plugin to my Swift Package Xcode CPU maxes out and I basically can't edit any code anymore because it lags constantly. I have found other people having the same issue with other Plugins as well.

For instance here with SwiftGenPlugin
SwiftGen/SwiftGenPlugin#2

In this issue someone refers to issues with this SwiftLintPlugin as well. They say it might have something to do with a remote artifactbundle. I don't know what that means and how to resolve the issue. Unfortunately this means for me that the plugin currently is unusable.

I have tested it and the plugin itself works fine. I am seeing al my linting issues in Xcode properly whenever I build.

I have tested this on the official Xcode 14.0 release:
Version 14.0 (14A309)

SPM Showing Recent Messages Command PhaseScriptExecution failed with a nonzero exit code

I have simple SPM and can't get Swiftlint to work. I guess it can't find .swiftlint.yml
I added config file in folder but still getting same error

Linting Swift files at paths /Users/Downloads/SPMSwiftLint-Test/Sources/MyApp
Error: No lintable files found at paths: '/Users/Downloads/SPMSwiftLint-Test/Sources/MyApp'
Command PhaseScriptExecution failed with a nonzero exit code

Linting Swift files at paths /Users/SPMSwiftLint-Test/Sources/MyApp

Error: No lintable files found at paths: '/Users/SPMSwiftLint-Test/Sources/MyApp'

Command PhaseScriptExecution failed with a nonzero exit code
Screenshot 2024-05-02 at 21 34 47

any clue what I'm missing?

Package.swift

// swift-tools-version:5.9

import PackageDescription

let package = Package(
    name: "MyApp",
    platforms: [
        .iOS(.v16),
        .macOS(.v13)
    ],
    products: [
        .executable(name: "MyApp", targets: ["MyApp"]),
    ],
    dependencies: [
        .package(url: "https://github.com/lukepistrol/SwiftLintPlugin.git", from: "0.54.0")
    ],
    targets: [
        .executableTarget(
            name: "MyApp",
            plugins: [
                .plugin(name: "SwiftLint", package: "SwiftLintPlugin")
            ]
        )
    ]
)

Error when using Xcode Cloud

This is a reopen of #15

I've just run into the same issue, and moving over to the official plug in resolved the issue, but just adding the spm takes ages now as the swiftlint repo is a giant...

Looks like your version appears to be not including a specific plugin fix which involves disabling caching while running in CI mode - see this comment by a disgruntled developer 😅

realm/SwiftLint#5448 (comment)

Unable to resolve f3586ed424d7bf5d94628332fbd0edebf1f5147f

Subject: Unable to resolve Git reference in SwiftLintPlugin

Hi Team,

I am encountering an issue with the SwiftLintPlugin in our project. Specifically, I am seeing the following error:

fatal: reference is not a tree: f3586ed (on 0.2.3)

This error occurs when I try to run xcodebuild via Fastlane and it prevents me from resolving the package dependencies.

I have tried troubleshooting this issue on my end, but I have not been able to find a solution. I suspect that this issue is related to the Git reference that SwiftLintPlugin is using, as the error message mentions a specific reference.

Could you please investigate this issue and provide a solution? Please let me know if you need any additional information or if there are any further steps I can take to troubleshoot this issue.

Thank you for your time and assistance.

anysnap-01-apr-2023-at-5-44-16-pm

Best regards,
Karthik

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.