1+ #Contribution Guidelines
2+
13##Tutorial
24
35If you'd like to write a SwiftLint rule but aren't sure how to start,
@@ -6,42 +8,44 @@ please watch and follow along with
68
79##Pull Requests
810
9- All changes, no matter how trivial, must be done via pull request. Commits
10- should never be made directly on the` main ` branch. Prefer rebasing over
11- merging` main ` into your PR branch to update it and resolve conflicts.
11+ All changes, no matter how trivial, must be done via pull requests. Commits
12+ should never be made directly on the` main ` branch. If possible, avoid mixing
13+ different aspects in one pull request. Prefer squashing if there are commits
14+ that are not reasonable alone. To update your PR branch and resolve conflicts,
15+ prefer rebasing over merging` main ` .
1216
1317_ If you have commit access to SwiftLint and believe your change to be trivial
14- and not worth waiting for review, you may open a pull request and merge
18+ and not worth waiting for review, you may open a pull request and merge it
1519immediately, but this should be the exception, not the norm._
1620
17- ### BuildingAnd Running Locally
21+ ##Buildingand Running Locally
1822
19- #### Using Xcode
23+ ###Using Xcode
2024
21251 . ` git clone https://github.com/realm/SwiftLint.git `
22261 . ` cd SwiftLint `
23271 . ` xed . `
24- 1 . Select the "swiftlint" scheme
25- 1 . ` cmd-opt-r ` open the scheme options
28+ 1 . Select the "swiftlint" scheme.
29+ 1 . ` cmd-opt-r ` to open the scheme options.
26301 . Set the "Arguments Passed On Launch" you want in the "Arguments" tab. See
2731available arguments[ in the README] ( https://github.com/realm/SwiftLint#command-line ) .
28321 . Set the "Working Directory" in the "Options" tab to the path where you would like
29- to execute SwiftLint. A folder that containsswift source files.
30- 1 . Hit "Run"
33+ to execute SwiftLint — a folder that containsSwift source files.
34+ 1 . Hit "Run".
3135
3236| Arguments| Options|
3337| -| -|
3438| ![ image] ( https://user-images.githubusercontent.com/5748627/115156411-d38c8780-a08c-11eb-9de4-939606c81574.png ) | ![ image] ( https://user-images.githubusercontent.com/5748627/115156276-287bce00-a08c-11eb-9e1d-35684a665228.png ) |
3539
3640Then you can use the full power of Xcode/LLDB/Instruments to develop and debug your changes to SwiftLint.
3741
38- #### Using thecommand line
42+ ###Using theCommand Line
3943
40441 . ` git clone https://github.com/realm/SwiftLint.git `
41451 . ` cd SwiftLint `
42461 . ` swift build [-c release] `
43471 . Use the produced` swiftlint ` binary from the command line, either by running` swift run [-c release] [swiftlint] [arguments] ` or by invoking the binary directly at` .build/[release|debug]/swiftlint `
44- 1 . [ Optional ] Attach LLDB:` lldb -- .build/[release|debug]/swiftlint [arguments] `
48+ 1 . For debugging, attach LLDB:` lldb -- .build/[release|debug]/swiftlint [arguments] `
4549
4650###Code Generation
4751
@@ -54,64 +58,73 @@ machine. This will update source files to reflect these changes.
5458
5559SwiftLint supports building via Xcode and Swift Package Manager on macOS, and
5660with Swift Package Manager on Linux. When contributing code changes, please
57- ensure that allthree supported build methods continue to work and pass tests.
61+ ensure that allfour supported build methods continue to work and pass tests:
5862
5963``` shell
60- $ xcodebuild -scheme swiftlinttest -destination' platform=macOS'
61- $ swifttest
62- $ make docker_test
64+ xcodebuild -scheme swiftlinttest -destination' platform=macOS'
65+ swifttest
66+ make bazel_test
67+ make docker_test
6368```
6469
6570##Rules
6671
6772New rules should be added in the` Source/SwiftLintBuiltInRules/Rules ` directory.
6873
69- Rules should conform to either the` Rule ` or` ASTRule ` protocols.
74+ Prefer implementing new rules with the help of SwiftSyntax. Look for the
75+ ` @SwiftSyntaxRule ` attribute for examples and use the same on your own rule.
76+ New rules should conform to either` Rule ` or` OptInRule ` depending on whether
77+ they shall be enabled by default or opt-in, respectively.
7078
7179All new rules or changes to existing rules should be accompanied by unit tests.
7280
7381Whenever possible, prefer adding tests via the` triggeringExamples ` and
7482` nonTriggeringExamples ` properties of a rule's` description ` rather than adding
7583those test cases in the unit tests directly. This makes it easier to understand
7684what rules do by reading their source, and simplifies adding more test cases
77- over time. This way adding a unit test for your new Rule is just a matter of
78- adding a test case in` RulesTests.swift ` which simply calls
79- ` verifyRule(YourNewRule.description) ` .
85+ over time. With` make sourcery ` , you ensure that all test cases are automatically
86+ checked in unit tests. Moreover, the examples added to a rule will appear in the
87+ rule's rendered documentation accessible from the
88+ [ Rule Directory] ( https://realm.github.io/SwiftLint/rule-directory.html ) .
8089
81- For debugging purposes examples can be marked as` focused ` . If there are any
82- focused examples found, then only those will be run when running tests for that rule.
83- ```
90+ For debugging purposes, examples can be marked as` focused ` . If there are any
91+ focused examples found, then only those will be run when running all tests for that
92+ rule.
93+
94+ ``` swift
8495nonTriggeringExamples: [
8596Example (" let x: [Int]" ),
86- Example("let x: [Int: String]").focused() //only this one will be run in tests
97+ Example (" let x: [Int: String]" ).focused ()// Only this one will be run in tests.
8798],
8899triggeringExamples: [
89100Example (" let x: ↓Array<String>" ),
90101Example (" let x: ↓Dictionary<Int, String>" )
91102]
92103```
93104
94- ###` ConfigurationProviderRule `
105+ ###Configuration
106+
107+ Every rule is configurable via` .swiftlint.yml ` , even if only by settings its default
108+ severity. This is done by setting the` configuration ` property of a rule as:
95109
96- If your rule supports user-configurable options via` .swiftlint.yml ` , you can
97- accomplish this by conforming to` ConfigurationProviderRule ` . You must provide a
98- configuration object via the` configuration ` property:
110+ ``` swift
111+ var configuration= SeverityConfiguration< Self > (.warning )
112+ ```
113+
114+ If a rule requires more options, a specific configuration can be implemented
115+ and associated with the rule via its` configuration ` property. Check for rules providing
116+ their own configurations as extensive examples or check out
99117
100- * The object provided must conform to ` RuleConfiguration ` .
101- * There are several provided ` RuleConfiguration ` s thatcover the common patterns like
102- configuring violation severity, violation severity levels, and evaluating
103- names.
104- * If none of the provided ` RuleConfiguration ` s are applicable, you can create one
105- specifically foryour rule.
118+ * [ ` ForceCastRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ForceCastRule.swift )
119+ for a rule thatallows severity configuration,
120+ * [ ` FileLengthRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Metrics/FileLengthRule.swift )
121+ for a rule that has multiple severity levels or
122+ * [ ` IdentifierNameRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Style/IdentifierNameRule.swift )
123+ fora rule that allows name evaluation configuration .
106124
107- See[ ` ForceCastRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ForceCastRule.swift )
108- for a rule that allows severity configuration,
109- [ ` FileLengthRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Metrics/FileLengthRule.swift )
110- for a rule that has multiple severity levels,
111- [ ` IdentifierNameRule ` ] ( https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Style/IdentifierNameRule.swift )
112- for a rule that allows name evaluation configuration:
125+ Configuring them in` .swiftlint.yml ` looks like:
113126
114- ``` yaml
127+ ``` yaml
115128force_cast :warning
116129
117130file_length :
@@ -126,22 +139,7 @@ identifier_name:
126139excluded :id
127140` ` `
128141
129- If your rule is configurable, but does not fit the pattern of
130- ` ConfigurationProviderRule`, you can conform directly to `Rule`:
131-
132- * `init(configuration: AnyObject) throws` will be passed the result of parsing the
133- value from `.swiftlint.yml` associated with your rule's `identifier` as a key
134- (if present).
135- * `configuration` may be of any type supported by YAML (e.g. `Int`, `String`, `Array`,
136- ` Dictionary` , etc.).
137- * This initializer must throw if it does not understand the configuration, or
138- it cannot be fully initialized with the configuration and default values.
139- * By convention, a failing initializer throws
140- `Issue.unknownConfiguration(ruleID :Parent.identifier)`.
141- * If this initializer fails, your rule will be initialized with its default
142- values by calling `init()`.
143-
144- # # Tracking changes
142+ ## Tracking Changes
145143
146144All changes should be made via pull requests on GitHub.
147145
@@ -151,13 +149,14 @@ summary of your changes to the `CHANGELOG.md` file.
151149We follow the same syntax as CocoaPods' CHANGELOG.md :
152150
1531511. One Markdown unnumbered list item describing the change.
154- 2. 2 trailing spaces on the last line describing the change (so that Markdown renders each change [on its own line](https://daringfireball.net/projects/markdown/syntax#p)).
155- 3. A list of Markdown hyperlinks to the contributors to the change. One entry
152+ 1. 2 trailing spaces on the last line describing the change (so that Markdown renders each change
153+ [on its own line](https://daringfireball.net/projects/markdown/syntax#p)).
154+ 1. A list of Markdown hyperlinks to the contributors to the change. One entry
156155per line. Usually just one.
157- 4 . A list of Markdown hyperlinks to the issues the change addresses. One entry
156+ 1 . A list of Markdown hyperlinks to the issues the change addresses. One entry
158157per line. Usually just one. If there was no issue tracking this change,
159158you may instead link to the change's pull request.
160- 5 . All CHANGELOG.md content is hard-wrapped at 80 characters.
159+ 1 . All CHANGELOG.md content is hard-wrapped at 80 characters.
161160
162161# # CI
163162
@@ -175,10 +174,10 @@ To bring up a new Buildkite worker from MacStadium:
175174
1761751. Change account password
1771761. Update macOS to the latest version
178- 1. Install Homebrew :https://brew.sh
177+ 1. Install Homebrew :< https://brew.sh>
1791781. Install Buildkite agent and other tools via Homebrew :
180179` brew install aria2 bazelisk htop buildkite/buildkite/buildkite-agent robotsandpencils/made/xcodes`
1811801. Install latest Xcode version :` xcodes update && xcodes install 14.0.0`
1821811. Add `DANGER_GITHUB_API_TOKEN` and `HOME` to `/opt/homebrew/etc/buildkite-agent/hooks/environment`
1831821. Configure and launch buildkite agent :` brew info buildkite-agent` /
184- https://buildkite.com/organizations/swiftlint/agents#setup-macos
183+ < https://buildkite.com/organizations/swiftlint/agents#setup-macos>