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.
This Package contains a binaryTarget for the current released version 0.57.0 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
- Add this Package
SwiftLintPluginas a dependency of your Package.
dependencies: [
.package(url: "https://github.com/GayleDunham/SwiftLintPlugin.git", branch: "main"),
],- Optionally: Add the
SwiftLintBuildToolplugin 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") ]
),- Add the package
https://github.com/GayleDunham/SwiftLintPluginto the project. - Optionally: Add the
SwiftLintBuildToolplugin to the targets you want to be evaluated by the linter.
- In the Project Navigator select the first item (The Project)
- In the Project Settings Editor select the Project
- Then select the Package Dependencies tab
- Click the + under the "Add package here" text
- Paste https://github.com/GayleDunham/SwiftLintPlugin in the search box.
- Click Add Package
- Now Select the Target
- Then select the Build Phases tab
- Expand Run Build Tool Plug-in and Click the +
- Select SwiftLintBuildTool and Click Add
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 are run against one or more selected Targets
SwiftLintFix: Correct violations whenever possibleSwiftLintLinter: Print lint warnings and errorsSwiftLintRules: Display the list of rules and their identifiersSwiftLintVersion: Display the current version of SwiftLint
- 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.
- 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.
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 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-
SwiftLint Rule Directory Reference - https://realm.github.io/SwiftLint/rule-directory.html
-
The Official raywenderlich.com SwiftLint Policy - https://github.com/kodecocodes/swift-style-guide/blob/main/SWIFTLINT.markdown
-
com.raywenderlich.swiftlint.yml - The Official Kodeco Configuration file - https://github.com/kodecocodes/swift-style-guide/blob/main/com.raywenderlich.swiftlint.yml
-
The Official Kodeco Swift Style Guide - https://github.com/kodecocodes/swift-style-guide
-
SwiftLee Blog: SwiftLint valuable opt-in rules to improve your code - https://www.avanderlee.com/optimization/swiftlint-optin-rules/
-
Swift API Design Guidelines - https://www.swift.org/documentation/api-design-guidelines/
-
Google Swift Style Guide - https://google.github.io/swift/
-
LinkedIn Swift Style Guide - https://github.com/linkedin/swift-style-guide
-
Airbnb Swift Style Guide - https://github.com/airbnb/swift
-
WWDC 2022 Meet Swift Package plugins - https://developer.apple.com/videos/play/wwdc2022/110359/
-
WWDC 2022 Create Swift Package plugins - https://developer.apple.com/videos/play/wwdc2022/110401/
-
Xcode integration of Swift Package Plugins in Xcode 14 - https://blog.eidinger.info/xcode-integration-of-swift-package-plugins-in-xcode-14
-
Beginner's guide to Swift package manager command plugins - https://theswiftdev.com/beginners-guide-to-swift-package-manager-command-plugins/
-
How to Use Xcode Plugins in Your iOS App - https://betterprogramming.pub/how-to-use-xcode-plugins-in-your-ios-app-13574261f210





