Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 964b007

Browse files
authored
Setup SwiftLint to run locally (#697)
2 parents f6be0c8 + 2badf37 commit 964b007

File tree

13 files changed

+80
-19
lines changed

13 files changed

+80
-19
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ Pods/
3434
fastlane/README.md
3535
fastlane/report.xml
3636
fastlane/test_output
37+
38+
# SwiftLint Remote Config Cache
39+
.swiftlint/RemoteConfigCache

.swiftlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parent_config: https://raw.githubusercontent.com/Automattic/swiftlint-config/0f8ab6388bd8d15a04391825ab125f80cfb90704/.swiftlint.yml
2+
remote_timeout: 10.0

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Why is there a `Makefile` when we already have a `Fastfile` in this project?
2+
#
3+
# Because when running Ruby code (i.e. `bundle exec fastlane <lane>`) from
4+
# within an Xcode build phase, Xcode will use a shell different from the user's
5+
# and with system Ruby where Bundler and Fastlane may or may not be available.
6+
# `make` on the other hand, is always available, therefore `make lint` can be
7+
# reliably called from both the user's terminal, Xcode, and CI.
8+
SWIFTLINT=./Pods/SwiftLint/swiftlint
9+
10+
lint:
11+
$(SWIFTLINT) lint --quiet
12+
13+
format:
14+
$(SWIFTLINT) lint --autocorrect --quiet

Podfile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,30 @@ target 'WordPressAuthenticatorTests' do
4949
pod 'OCMock', '~> 3.4'
5050
pod 'Expecta', '1.0.6'
5151
pod 'Specta', '1.0.7'
52+
end
53+
54+
# Used to donwload CLI tools.
55+
abstract_target 'Tools' do
56+
pod 'SwiftLint', '~> 0.49'
57+
end
58+
59+
post_install do |installer|
60+
installer.pods_project.targets.each do |target|
61+
target.build_configurations.each do |configuration|
62+
# Let Pods targets inherit deployment target from the app
63+
# This solution is suggested here: https://github.com/CocoaPods/CocoaPods/issues/4859
64+
pod_ios_deployment_target = Gem::Version.new(configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
65+
configuration.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' if pod_ios_deployment_target <= ios_deployment_target
5266

53-
post_install do |installer|
54-
# Let Pods targets inherit deployment target from the app
55-
# This solution is suggested here: https://github.com/CocoaPods/CocoaPods/issues/4859
56-
# =====================================
57-
#
58-
installer.pods_project.targets.each do |target|
59-
target.build_configurations.each do |configuration|
60-
pod_ios_deployment_target = Gem::Version.new(configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
61-
configuration.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' if pod_ios_deployment_target <= ios_deployment_target
62-
end
67+
# This addresses Xcode 12, 13, and 14 showing an "Update to recommended
68+
# settings" warning on the Pods project.
69+
#
70+
# See:
71+
#
72+
# - https://github.com/CocoaPods/CocoaPods/issues/10189
73+
# - https://github.com/CocoaPods/CocoaPods/issues/11553
74+
configuration.build_settings.delete 'ARCHS'
75+
configuration.build_settings['DEAD_CODE_STRIPPING'] = 'YES'
6376
end
6477
end
6578
end

Podfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ PODS:
2626
- OCMock (3.8.1)
2727
- Specta (1.0.7)
2828
- SVProgressHUD (2.2.5)
29+
- SwiftLint (0.49.1)
2930
- UIDeviceIdentifier (1.6.0)
3031
- WordPressKit (4.24.0):
3132
- Alamofire (~> 4.8.0)
@@ -49,6 +50,7 @@ DEPENDENCIES:
4950
- OCMock (~> 3.4)
5051
- Specta (= 1.0.7)
5152
- SVProgressHUD (= 2.2.5)
53+
- SwiftLint (~> 0.49)
5254
- WordPressKit (~> 4.18-beta)
5355
- WordPressShared (~> 1.12-beta)
5456
- WordPressUI (~> 1.7-beta)
@@ -69,6 +71,7 @@ SPEC REPOS:
6971
- OCMock
7072
- Specta
7173
- SVProgressHUD
74+
- SwiftLint
7275
- UIDeviceIdentifier
7376
- WordPressKit
7477
- WordPressShared
@@ -90,12 +93,13 @@ SPEC CHECKSUMS:
9093
OCMock: 29f6e52085b4e7d9b075cbf03ed7c3112f82f934
9194
Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66
9295
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
96+
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
9397
UIDeviceIdentifier: f4bf3b343581a1beacdbf5fb1a8825bd5f05a4a4
9498
WordPressKit: ee58e3d313ddce1f768e87d76364d261ad86fca9
9599
WordPressShared: 38cb62e9cb998d4dc3c1611f17934c6875a6b3e8
96100
WordPressUI: 1cf47a3b78154faf69caa18569ee7ece1e510fa0
97101
wpxmlrpc: bf55a43a7e710bd2a4fb8c02dfe83b1246f14f13
98102

99-
PODFILE CHECKSUM: a1020c109a62537b5751fddc9375bacd6c45db78
103+
PODFILE CHECKSUM: 4aeaf3c769fe14a1696e9e1c42b609b7e9f8858c
100104

101105
COCOAPODS: 1.11.3

WordPressAuthenticator.xcodeproj/project.pbxproj

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -1013,6 +1013,7 @@
10131013
B5ED78F0207E976500A8FD8C /* Frameworks */,
10141014
B5ED78F2207E976500A8FD8C /* Resources */,
10151015
B5A5274B20B479D30065BE81 /* CopyFiles */,
1016+
3FCF8AA329111BD200E64F8D /* Lint */,
10161017
);
10171018
buildRules = (
10181019
);
@@ -1131,6 +1132,25 @@
11311132
/* End PBXResourcesBuildPhase section */
11321133

11331134
/* Begin PBXShellScriptBuildPhase section */
1135+
3FCF8AA329111BD200E64F8D /* Lint */ = {
1136+
isa = PBXShellScriptBuildPhase;
1137+
alwaysOutOfDate = 1;
1138+
buildActionMask = 2147483647;
1139+
files = (
1140+
);
1141+
inputFileListPaths = (
1142+
);
1143+
inputPaths = (
1144+
);
1145+
name = Lint;
1146+
outputFileListPaths = (
1147+
);
1148+
outputPaths = (
1149+
);
1150+
runOnlyForDeploymentPostprocessing = 0;
1151+
shellPath = /bin/sh;
1152+
shellScript = "make lint\n";
1153+
};
11341154
6CD6648B820552D8638F8EDA /* [CP] Check Pods Manifest.lock */ = {
11351155
isa = PBXShellScriptBuildPhase;
11361156
buildActionMask = 2147483647;

WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class AuthenticatorAnalyticsTracker {
8383
///
8484
case loginWithSiteAddress = "login_site_address"
8585

86-
/// This flow starts when the user wants to troubleshoot their site by inputting its address
86+
/// This flow starts when the user wants to troubleshoot their site by inputting its address
8787
///
8888
case siteDiscovery = "site_discovery"
8989

WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,14 @@ import WordPressKit
557557

558558
public extension WordPressAuthenticator {
559559

560-
func getAppleIDCredentialState(for userID: String, completion: @escaping (ASAuthorizationAppleIDProvider.CredentialState, Error?) -> Void) {
560+
func getAppleIDCredentialState(for userID: String, completion: @escaping (ASAuthorizationAppleIDProvider.CredentialState, Error?) -> Void) {
561561
AppleAuthenticator.sharedInstance.getAppleIDCredentialState(for: userID) { (state, error) in
562562
// If credentialState == .notFound, error will have a value.
563563
completion(state, error)
564564
}
565565
}
566566

567-
func startObservingAppleIDCredentialRevoked(completion: @escaping () -> Void) {
567+
func startObservingAppleIDCredentialRevoked(completion: @escaping () -> Void) {
568568
appleIDCredentialObserver = NotificationCenter.default.addObserver(forName: AppleAuthenticator.credentialRevokedNotification, object: nil, queue: nil) { (_) in
569569
completion()
570570
}

WordPressAuthenticator/Logging/CocoaLumberjack.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import CocoaLumberjack
33

44
// June 14 2017 - @astralbodies
5-
// Taken from CocoaLumberjack repository - reproduced to prevent issue with
5+
// Taken from CocoaLumberjack repository - reproduced to prevent issue with
66
// CocoaPods and some weird bug with frameworks
77

88
// Software License Agreement (BSD License)

WordPressAuthenticator/Navigation/NavigationCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
/// NavigationCommand abstracts logic necessary provide clients of this library
44
/// with a way to navigate to a particular location in the UL navigation flow.
5-
///
5+
///
66
/// Concrete implementations of this protocol will decide what that means
77
///
88
public protocol NavigationCommand {

0 commit comments

Comments
 (0)