Skip to content

Commit 70de778

Browse files
committed
Use SwiftPM over CocoaPods to fetch SwiftLint
1 parent 1256f14 commit 70de778

File tree

10 files changed

+87
-21
lines changed

10 files changed

+87
-21
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ default.profraw
5757
# Everything without a .enc extension is ignored
5858
.configure-files/*
5959
!.configure-files/*.enc
60+
61+
# BuildTools
62+
BuildTools/.build

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ swiftlint_version: 0.58.2
22

33
# Project configuration
44
excluded:
5+
- BuildTools
56
- DerivedData
67
- Pods
78
- fastlane

BuildTools/Empty.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Here only to satisfy SwiftPM requirement.
2+
// See https://github.com/nicklockwood/SwiftFormat#1-create-a-buildtools-folder-and-packageswift

BuildTools/Package.resolved

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BuildTools/Package.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// swift-tools-version:6.0
2+
import Foundation
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "BuildTools",
7+
platforms: [.macOS(.v10_13)],
8+
dependencies: [
9+
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: loadSwiftLintVersion()),
10+
],
11+
targets: [.target(name: "BuildTools", path: "")]
12+
)
13+
14+
func loadSwiftLintVersion() -> Version {
15+
let swiftLintConfigURL = URL(fileURLWithPath: #filePath)
16+
.deletingLastPathComponent()
17+
.appendingPathComponent("..")
18+
.appendingPathComponent(".swiftlint.yml")
19+
20+
guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else {
21+
fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).")
22+
}
23+
24+
guard let versionLine = yamlString.components(separatedBy: .newlines)
25+
.first(where: { $0.contains("swiftlint_version") }) else {
26+
fatalError("SwiftLint version not found in YAML file.")
27+
}
28+
29+
// Assumes the format `swiftlint_version: <version>`
30+
guard let version = Version(versionLine.components(separatedBy: ":")
31+
.last?
32+
.trimmingCharacters(in: .whitespaces) ?? "") else {
33+
fatalError("Failed to extract SwiftLint version.")
34+
}
35+
36+
return version
37+
}

Podfile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ abstract_target 'Automattic' do
4141
end
4242
end
4343

44-
## Tools
45-
## ===================
46-
##
47-
48-
def swiftlint_version
49-
require 'yaml'
50-
51-
YAML.load_file('.swiftlint.yml')['swiftlint_version']
52-
end
53-
54-
abstract_target 'Tools' do
55-
pod 'SwiftLint', swiftlint_version
56-
end
57-
5844
# Post Install
5945
#
6046
post_install do |installer|

Podfile.lock

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,28 @@ PODS:
1111
- Simperium/SocketTrust (1.9.0)
1212
- Simperium/SPReachability (1.9.0)
1313
- Simperium/SSKeychain (1.9.0)
14-
- SwiftLint (0.58.2)
1514
- WordPress-Ratings-iOS (0.0.2)
1615
- ZIPFoundation (0.9.15)
1716

1817
DEPENDENCIES:
1918
- Gridicons (~> 0.18)
2019
- Simperium (= 1.9.0)
21-
- SwiftLint (= 0.58.2)
2220
- WordPress-Ratings-iOS (= 0.0.2)
2321
- ZIPFoundation (~> 0.9.9)
2422

2523
SPEC REPOS:
2624
trunk:
2725
- Gridicons
2826
- Simperium
29-
- SwiftLint
3027
- WordPress-Ratings-iOS
3128
- ZIPFoundation
3229

3330
SPEC CHECKSUMS:
3431
Gridicons: dc92efbe5fd60111d2e8ea051d84a60cca552abc
3532
Simperium: 45d828d68aad71f3449371346f270013943eff78
36-
SwiftLint: 365bcd9ffc83d0deb874e833556d82549919d6cd
3733
WordPress-Ratings-iOS: 9f83dbba6e728c5121b1fd21b5683cf2fd120646
3834
ZIPFoundation: 063163dc828bf699c5be160eb4f58f676322d94f
3935

40-
PODFILE CHECKSUM: 1a6145a673ddc931a81b1fbd59e20edfdbaca298
36+
PODFILE CHECKSUM: 14904fe5db303e2b35352af2f191345f1edf8f0a
4137

4238
COCOAPODS: 1.16.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Third party libraries and resources managed by CocoaPods will be installed by th
2020

2121
#### SwiftLint
2222

23-
We use [SwiftLint](https://github.com/realm/SwiftLint) to enforce a common style for Swift code. If you plan to write code, SwiftLint is going to be installed when you run `bundle exec pod install` and SwiftLint will run during the build.
23+
We use [SwiftLint](https://github.com/realm/SwiftLint) to enforce a common style for Swift code.
24+
If you plan to write code, SwiftLint is going to be installed automatically when you build the app.
2425
No commit should have lint warnings or errors.
2526

2627
### Open Xcode

Rakefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ LOCAL_PATH = 'vendor/bundle'
1717

1818
task default: %w[test]
1919

20+
desc 'Checks the source for style errors'
21+
task :lint do
22+
swiftlint
23+
end
24+
25+
namespace :lint do
26+
desc 'Automatically corrects style errors where possible'
27+
task :autocorrect do
28+
swiftlint(additional_args: ['--fix'])
29+
end
30+
end
31+
2032
desc 'Install required dependencies'
2133
task dependencies: %w[dependencies:check]
2234

@@ -251,3 +263,16 @@ def check_dependencies_hook
251263
exit 1
252264
end
253265
end
266+
267+
def swiftlint(additional_args: [])
268+
run_package_plugin(cmd: "swiftlint --working-directory .. --quiet #{additional_args.join(' ')}")
269+
end
270+
271+
def run_package_plugin(cmd:)
272+
run_in_build_tools(cmd: "swift package plugin --allow-writing-to-directory .. --allow-writing-to-package-directory #{cmd}")
273+
end
274+
275+
# We could use more idiomatic Ruby here, with `Dir.chdir`, but leaving as raw shell commands for when we'll drop Ruby and rake for tooling.
276+
def run_in_build_tools(cmd:)
277+
sh "pushd BuildTools && export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) && #{cmd} && popd"
278+
end

Simplenote.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,7 @@
33063306
);
33073307
runOnlyForDeploymentPostprocessing = 0;
33083308
shellPath = /bin/sh;
3309-
shellScript = "[ $CI ] && exit 0\n./Pods/SwiftLint/swiftlint\n";
3309+
shellScript = "[ $CI ] && exit 0\nrake lint\n";
33103310
};
33113311
B553F5A11D10474600F7E397 /* Delete Frameworks folder (temporary fix for CocoaPods) */ = {
33123312
isa = PBXShellScriptBuildPhase;

0 commit comments

Comments
 (0)