# SwiftLint
A tool to enforce Swift style and conventions, loosely based on the now archived [GitHub Swift Style Guide](https://github.com/github/swift-style-guide). SwiftLint enforces the style guide rules that are generally accepted by the Swift community. These rules are well described in popular style guides like [Ray Wenderlich's Swift Style Guide](https://github.com/raywenderlich/swift-style-guide).
SwiftLint hooks into [Clang](http://clang.llvm.org) and
[SourceKit](http://www.jpsim.com/uncovering-sourcekit) to use the
[AST](http://clang.llvm.org/docs/IntroductionToTheClangAST.html) representation
of your source files for more accurate results.
[![Build Status](https://dev.azure.com/jpsim/SwiftLint/_apis/build/status/realm.SwiftLint?branchName=main)](https://dev.azure.com/jpsim/SwiftLint/_build/latest?definitionId=4?branchName=main)
[![codecov.io](https://codecov.io/github/realm/SwiftLint/coverage.svg?branch=main)](https://codecov.io/github/realm/SwiftLint?branch=main)
![](assets/screenshot.png)
This project adheres to the [Contributor Covenant Code of Conduct](https://realm.io/conduct).
By participating, you are expected to uphold this code. Please report
unacceptable behavior to [info@realm.io](mailto:info@realm.io).
> Language Switch: [中文](https://github.com/realm/SwiftLint/blob/main/README_CN.md), [한국어](https://github.com/realm/SwiftLint/blob/main/README_KR.md).
## Installation
### Using [Homebrew](http://brew.sh/):
```
brew install swiftlint
```
### Using [CocoaPods](https://cocoapods.org):
Simply add the following line to your Podfile:
```ruby
pod 'SwiftLint'
```
This will download the SwiftLint binaries and dependencies in `Pods/` during your next
`pod install` execution and will allow you to invoke it via `${PODS_ROOT}/SwiftLint/swiftlint`
in your Script Build Phases.
This is the recommended way to install a specific version of SwiftLint since it supports
installing a pinned version rather than simply the latest (which is the case with Homebrew).
Note that this will add the SwiftLint binaries, its dependencies' binaries, and the Swift binary
library distribution to the `Pods/` directory, so checking in this directory to SCM such as
git is discouraged.
### Using [Mint](https://github.com/yonaskolb/mint):
```
$ mint install realm/SwiftLint
```
### Using a pre-built package:
You can also install SwiftLint by downloading `SwiftLint.pkg` from the
[latest GitHub release](https://github.com/realm/SwiftLint/releases/latest) and
running it.
### Installing from source:
You can also build and install from source by cloning this project and running
`make install` (Xcode 13.3 or later).
### Using Bazel
Put this in your `MODULE.bazel`:
```bzl
bazel_dep(name = "swiftlint", version = "0.50.4", repo_name = "SwiftLint")
```
Or put this in your `WORKSPACE`:
<details>
<summary>WORKSPACE</summary>
```bzl
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_apple",
sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911",
url = "https://github.com/bazelbuild/rules_apple/releases/download/1.1.3/rules_apple.1.1.3.tar.gz",
)
load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
)
apple_rules_dependencies()
load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)
swift_rules_dependencies()
load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)
swift_rules_extra_dependencies()
http_archive(
name = "SwiftLint",
sha256 = "7c454ff4abeeecdd9513f6293238a6d9f803b587eb93de147f9aa1be0d8337c4",
url = "https://github.com/realm/SwiftLint/releases/download/0.49.1/bazel.tar.gz",
)
load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")
swiftlint_repos()
load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")
swiftlint_deps()
```
</details>
Then you can run SwiftLint in the current directory with this command:
```console
bazel run -c opt @SwiftLint//:swiftlint
```
## Usage
### Presentation
To get a high-level overview of recommended ways to integrate SwiftLint into your project,
we encourage you to watch this presentation or read the transcript:
[![Presentation](assets/presentation.svg)](https://youtu.be/9Z1nTMTejqU)
### Xcode
Integrate SwiftLint into your Xcode project to get warnings and errors displayed
in the issue navigator.
To do this select the project in the file navigator, then select the primary app
target, and go to Build Phases. Click the + and select "New Run Script Phase".
Insert the following as the script:
![](assets/runscript.png)
If you installed SwiftLint via Homebrew on Apple Silicon, you might experience this warning:
> warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint
That is because Homebrew on Apple Silicon installs the binaries into the `/opt/homebrew/bin`
folder by default. To instruct Xcode where to find SwiftLint, you can either add
`/opt/homebrew/bin` to the `PATH` environment variable in your build phase
```bash
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
```
or you can create a symbolic link in `/usr/local/bin` pointing to the actual binary:
```bash
ln -s /opt/homebrew/bin/swiftlint /usr/local/bin/swiftlint
```
You might want to move your SwiftLint phase directly before the 'Compile Sources'
step to detect errors quickly before compiling. However, SwiftLint is designed
to run on valid Swift code that cleanly completes the compiler's parsing stage.
So running SwiftLint before 'Compile Sources' might yield some incorrect
results.
If you wish to fix violations as well, your script could run
`swiftlint --fix && swiftlint` instead of just `swiftlint`. This will mean
that all correctable violations are fixed while ensuring warnings show up in
your project for remaining violations.
If you've installed SwiftLint via CocoaPods the script should look like this:
```bash
"${PODS_ROOT}/SwiftLint/swiftlint"
```
### Plug-in Support
SwiftLint can be used as a build tool plug-in for both Xcode projects as well as
Swift packages.
> Due to limitations with Swift Package Manager Plug-ins this is only
recommended for projects that have a SwiftLint configuration in their root directory as
there is currently no way to pass any additional options to the SwiftLint executable.
#### Xcode
You can integrate SwiftLint as an Xcode Build Tool Plug-in if you're working
with a project in Xcode.
Add SwiftLint as a package dependency to your project without linking any of the
products.
Select the target you want to add linting to and open the `Build Phases` inspector.
Open `Run Build Tool Plug-ins` and select the `+` button.
Select `SwiftLintPlugin` from the list and add it to the project.
![](assets/select-swiftlint-plugin.png)
For unattended use (e.g. on CI), you can disable the package validation dialog by
* individually passing `-skipPackagePluginValidation` to `xcodebuild` or
* globally setting `defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES`
for that user.
_Note: This implicitly trusts all Xcode package plugins and bypasses Xcode's package validation
dialogs, which has security implications._
#### Swift Package
You can integrate SwiftLint as a Swift Package Manager Plug-in if you're working with
a Swift Package with a `Package.swift` manifest.
Add SwiftLint as a package dependency to your `Package.swift` file.
Add SwiftLint to a target using the `plugins` parameter.
```swift
.target(
...
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
),
```
### AppCode
To integrate SwiftLint with AppCode, install
[this plugin](https://plugins.jetbrains.com/plugin/9175) and configure
SwiftLint's installed path in the plugin's preferences.
The
没有合适的资源?快使用搜索试试~ 我知道了~
一个强制执行Swift风格和约定的工具。___下载.zip
共723个文件
swift:583个
yml:63个
md:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2023-04-19
00:48:42
上传
评论
收藏 1.11MB ZIP 举报
温馨提示
一个强制执行Swift风格和约定的工具。___下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
一个强制执行Swift风格和约定的工具。___下载.zip (723个子文件)
MODULE.bazel 1KB
.bazelignore 7B
.bazelrc 302B
.bazelversion 6B
BUILD 4KB
BUILD 3KB
SwiftSyntax.BUILD 2KB
CollectionConcurrencyKit.BUILD 278B
SwiftyTextTable.BUILD 245B
CryptoSwift.BUILD 238B
BUILD 107B
BUILD 35B
repos.bzl 2KB
deps.bzl 1KB
opt_wrapper.bzl 928B
extensions.bzl 885B
CannedCSVReporterOutput.csv 433B
Dangerfile 2KB
Dockerfile 1KB
.dockerignore 37B
Gemfile 72B
get-version 117B
.gitattributes 25B
.gitignore 975B
.gitkeep 0B
CannedHTMLReporterOutput.html 3KB
CannedCodeClimateReporterOutput.json 2KB
CannedSonarQubeReporterOutput.json 1KB
CannedJSONReporterOutput.json 915B
metadata.template.json 312B
source.template.json 134B
LICENSE 1KB
Gemfile.lock 4KB
Makefile 7KB
CHANGELOG.md 239KB
README.md 27KB
README_KR.md 17KB
README_CN.md 14KB
CONTRIBUTING.md 7KB
bug_report.md 1KB
Releasing.md 1KB
rule-request.md 782B
CannedMarkdownReporterOutput.md 504B
Rules.md 92B
oss-check 10KB
custom-rule.png 93KB
screenshot.png 71KB
runscript.png 58KB
macstadium.png 30KB
select-swiftlint-plugin.png 19KB
realm.png 19KB
SwiftLint.podspec 749B
push-docs 584B
Package.resolved 2KB
update-swift-syntax.sh 1KB
update-artifact-bundle.sh 490B
test-analyze.sh 343B
sourcery 176B
GeneratedTests.stencil 489B
PrimaryRuleList.stencil 454B
ReportersList.stencil 279B
presentation.svg 32KB
GeneratedTests.swift 37KB
TestHelpers.swift 25KB
ConfigurationTests.swift 23KB
CommandTests.swift 18KB
RuleConfigurationTests.swift 17KB
ConfigurationTests+MultipleConfigs.swift 16KB
Linter.swift 15KB
Configuration.swift 15KB
LinterCacheTests.swift 14KB
NestingRuleExamples.swift 14KB
ClosureEndIndentationRule.swift 14KB
Configuration+RulesWrapper.swift 14KB
IndentationWidthRuleTests.swift 14KB
ModifierOrderTests.swift 13KB
LintOrAnalyzeCommand.swift 13KB
NestingRuleTests.swift 13KB
UnusedDeclarationRule.swift 13KB
SyntacticSugarRule.swift 12KB
UnusedImportRule.swift 12KB
DiscouragedOptionalCollectionExamples.swift 12KB
SwiftLintFile+Regex.swift 12KB
Configuration+CommandLine.swift 11KB
Configuration+FileGraph.swift 11KB
LetVarWhitespaceRule.swift 11KB
Configuration+Remote.swift 11KB
TypeContentsOrderRuleTests.swift 11KB
MultilineParametersRuleExamples.swift 11KB
Collection+Windows.swift 11KB
ColonRuleExamples.swift 11KB
LegacyConstructorRule.swift 11KB
PrivateOverFilePrivateRule.swift 11KB
MissingDocsRuleTests.swift 10KB
IntegrationTests.swift 10KB
LowerACLThanParentRule.swift 10KB
MarkRule.swift 10KB
SwiftSyntax+SwiftLint.swift 10KB
Rule.swift 10KB
Configuration+Parsing.swift 10KB
共 723 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功