Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ default.profraw
# Everything without a .enc extension is ignored
.configure-files/*
!.configure-files/*.enc

# BuildTools
BuildTools/.build
8 changes: 5 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
swiftlint_version: 0.54.0
swiftlint_version: 0.58.2

# Project configuration
excluded:
- BuildTools
- DerivedData
- Pods
- fastlane
- vendor
Expand Down Expand Up @@ -49,8 +51,8 @@ only_rules:

# Rules configuration

control_statement:
severity: error
control_statement:
severity: error

custom_rules:

Expand Down
2 changes: 2 additions & 0 deletions BuildTools/Empty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Here only to satisfy SwiftPM requirement.
// See https://github.com/nicklockwood/SwiftFormat#1-create-a-buildtools-folder-and-packageswift
15 changes: 15 additions & 0 deletions BuildTools/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions BuildTools/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version:6.0
import Foundation
import PackageDescription

let package = Package(
name: "BuildTools",
platforms: [.macOS(.v10_13)],
dependencies: [
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: loadSwiftLintVersion()),
],
targets: [.target(name: "BuildTools", path: "")]
)

func loadSwiftLintVersion() -> Version {
let swiftLintConfigURL = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.appendingPathComponent("..")
.appendingPathComponent(".swiftlint.yml")

guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else {
fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).")
}

guard let versionLine = yamlString.components(separatedBy: .newlines)
.first(where: { $0.contains("swiftlint_version") }) else {
fatalError("SwiftLint version not found in YAML file.")
}

// Assumes the format `swiftlint_version: <version>`
guard let version = Version(versionLine.components(separatedBy: ":")
.last?
.trimmingCharacters(in: .whitespaces) ?? "") else {
fatalError("Failed to extract SwiftLint version.")
}

return version
}
14 changes: 0 additions & 14 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,6 @@ abstract_target 'Automattic' do
end
end

## Tools
## ===================
##

def swiftlint_version
require 'yaml'

YAML.load_file('.swiftlint.yml')['swiftlint_version']
end

abstract_target 'Tools' do
pod 'SwiftLint', swiftlint_version
end

# Post Install
#
post_install do |installer|
Expand Down
6 changes: 1 addition & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,28 @@ PODS:
- Simperium/SocketTrust (1.9.0)
- Simperium/SPReachability (1.9.0)
- Simperium/SSKeychain (1.9.0)
- SwiftLint (0.54.0)
- WordPress-Ratings-iOS (0.0.2)
- ZIPFoundation (0.9.15)

DEPENDENCIES:
- Gridicons (~> 0.18)
- Simperium (= 1.9.0)
- SwiftLint (= 0.54.0)
- WordPress-Ratings-iOS (= 0.0.2)
- ZIPFoundation (~> 0.9.9)

SPEC REPOS:
trunk:
- Gridicons
- Simperium
- SwiftLint
- WordPress-Ratings-iOS
- ZIPFoundation

SPEC CHECKSUMS:
Gridicons: dc92efbe5fd60111d2e8ea051d84a60cca552abc
Simperium: 45d828d68aad71f3449371346f270013943eff78
SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211
WordPress-Ratings-iOS: 9f83dbba6e728c5121b1fd21b5683cf2fd120646
ZIPFoundation: 063163dc828bf699c5be160eb4f58f676322d94f

PODFILE CHECKSUM: 1a6145a673ddc931a81b1fbd59e20edfdbaca298
PODFILE CHECKSUM: 14904fe5db303e2b35352af2f191345f1edf8f0a

COCOAPODS: 1.16.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Third party libraries and resources managed by CocoaPods will be installed by th

#### SwiftLint

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.
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 automatically when you build the app.
No commit should have lint warnings or errors.

### Open Xcode
Expand Down
25 changes: 25 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ LOCAL_PATH = 'vendor/bundle'

task default: %w[test]

desc 'Checks the source for style errors'
task :lint do
swiftlint
end

namespace :lint do
desc 'Automatically corrects style errors where possible'
task :autocorrect do
swiftlint(additional_args: ['--fix'])
end
end

desc 'Install required dependencies'
task dependencies: %w[dependencies:check]

Expand Down Expand Up @@ -251,3 +263,16 @@ def check_dependencies_hook
exit 1
end
end

def swiftlint(additional_args: [])
run_package_plugin(cmd: "swiftlint --working-directory .. --quiet #{additional_args.join(' ')}")
end

def run_package_plugin(cmd:)
run_in_build_tools(cmd: "swift package plugin --allow-writing-to-directory .. --allow-writing-to-package-directory #{cmd}")
end

# 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.
def run_in_build_tools(cmd:)
sh "pushd BuildTools && export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) && #{cmd} && popd"
end
2 changes: 1 addition & 1 deletion Simplenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "[ $CI ] && exit 0\n./Pods/SwiftLint/swiftlint\n";
shellScript = "[ $CI ] && exit 0\nrake lint\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wary of if running rake from an Xcode build phase would work as expected, given that:

  • When Xcode runs shell scripts it runs them in a separate shell that might not have the same env / settings as your Terminal.app's shell (e.g. $PATH and where rake is installed)
  • That shell script runs in /bin/sh, while macOS users are using zsh, so all their customization and setup of their shell is in .zshrc and not .bashrc. So again, any custom $PATH or rbenv and bundle-related config etc might be set up properly in .zshrc but not in .bashrc for the /bin/sh shell to pick up, which could lead to this rake lint command to fail
  • Notice how you run rake lint, not bundle exec rake lint. Which means one might accidentally run this command with a different version of rake than the one in the Gemfile.lock bundle of this repo. Probably not a big deal (the most important thing is for swiftlint to be using the right version, and rake doesn't have that many updates anyway, and if it does, nothing likely breaking anything) but still inconsistent.

It still worked when I tested building the project with Xcode on my Mac:
image

But I think that might be a happy coincidence in how my Mac is set up, and that might not be the case for every developer? I wonder if switching to shellPath = /bin/zsh; and using bundle exec rake lint wouldn't be better (maybe with a need to source ~/.zshrc explicitly first, in case Xcode running this shell in non-interactive mode would prevent that from loading… not sure, always confused with the rc files and when they're loaded wrt to interactive vs non-interactive shells etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember looking into this with Jeremy a while back and coming to the conclusion that calling rake from Xcode works because of a number of happy coincidences in how Apple set up Ruby in macOS.

In the long run, consistently with our goal of removing Ruby from day-to-day DX, I think we'd be better off using make which we know would be consistent without depending on Ruby setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this discussion internally to paaHJt-8yZ-p2

};
B553F5A11D10474600F7E397 /* Delete Frameworks folder (temporary fix for CocoaPods) */ = {
isa = PBXShellScriptBuildPhase;
Expand Down