SwiftLintPlugin

1.0.1

A Swift Package Manager Plugin for SwiftLint, supporting both the command line and Xcode. The package provides both plugin commands and a build tool command that runs before the build
GayleDunham/SwiftLintPlugin

What's New

1.0.1

2023-09-17T01:22:14Z

A Swift Package Manager Plugin for SwiftLint, supporting both Swift Packages and Xcode Projects. This package provides both plugin commands and a build tool command that runs before the build. For Packages, the plugin commands can be executed from both the command line and within Xcode.

SwiftLintPlugin

A Swift Package Manager Plugin for SwiftLint, supporting both Swift Packages and Xcode Projects. This package provides both plugin commands and a build tool command that runs before the build. For Packages, the plugin commands can be executed from both the command line and within Xcode.

Installation

This Package contains a binaryTarget for the current released version 0.52.4 of swiftlint from https://github.com/realm/SwiftLint/ used by all the plugin commands and the build tool command. No installation of swiftlint or configuring of PATH is required.

Important

You do need either a swiftlint.yml or .swiftlint.yml file in the root folder of your package or project. The commands will fail if no configuration file can be found.

For more information on SwiftLint Rules see: https://realm.github.io/SwiftLint/rule-directory.html

Swift Package Configuration

  1. Add this Package SwiftLintPlugin as a dependency of your Package.
    dependencies: [
        .package(url: "https://github.com/GayleDunham/SwiftLintPlugin.git", branch: "main"),
    ],
  1. Optionally: Add the SwiftLintBuildTool plugin to your main target all files in the package will be evaluated by the linter.
    targets: [
        .target(
            name: "YOUR_TARGET",
            dependencies: [],
            plugins: [ .plugin(name: "SwiftLintBuildTool", package: "SwiftLintPlugin") ]
        ),

Xcode Project Configuration

TL;)DR

  1. Add the package https://github.com/GayleDunham/SwiftLintPlugin to the project.
  2. Optionally: Add the SwiftLintBuildTool plugin to the targets you want to be evaluated by the linter.

Add the package to your Project.

  1. In the Project Navigator select the first item (The Project)
  2. In the Project Settings Editor select the Project
  3. Then select the Package Dependencies tab
  4. Click the + under the "Add package here" text

Edit the Project Package Settings

  1. Paste https://github.com/GayleDunham/SwiftLintPlugin in the search box.
  2. Click Add Package

Paste the link and Add Package

Optionally: Add the Build Tool to your Target.

  1. Now Select the Target
  2. Then select the Build Phases tab
  3. Expand Run Build Tool Plug-in and Click the +

Edit the Target Build Setings

  1. Select SwiftLintBuildTool and Click Add

Select the Build Tool and Add

Features

Build Tool

The SwiftLintBuildTool is a pre-build command that runs swiftlint against a Target's sources directory. You must have a swiftlint.yml or .swiftlint.yml file in the root folder of the Package or Project

Commands

Commands are run against one or more selected Targets

  • SwiftLintFix: Correct violations whenever possible
  • SwiftLintLinter: Print lint warnings and errors
  • SwiftLintRules: Display the list of rules and their identifiers
  • SwiftLintVersion: Display the current version of SwiftLint

Running Plugin Commands from Xcode

  • To Run Commands from the Project Navigator: Right-click on the first item (The Project or Package) in the Project Navigator, then Click the Command to run.

Run Command from Project Navigator

  • To Run Commands from the Menu: Select the first item (The Project or Package) in the Project Navigator. Then in the Menu, Select File -> Packages and the Command to run.

Run Command from Project Navigator

Command Line Usage For Swift Packages

In the top-level directory of the Swift Package execute any of the following commands.

    % swift package swiftlint-fix
    % swift package swiftlint-lint
    % swift package swiftlint-rules
    % swift package swiftlint-version   

xcodebuild Usage and CI systems

Note

For CI Systems you should specify -skipPackagePluginValidation to skip the validation prompt that occurs in Xcode.

xcodebuild  \
    -scheme "YOUR_PROJECT" \
    -destination "platform=OS X,arch=x86_64" \
    -skipPackagePluginValidation \
    clean build

References:

SwiftLint

Swift Package Plugins

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Nov 09 2024 22:06:51 GMT-1000 (Hawaii-Aleutian Standard Time)