Skip to content

Commit

Permalink
Add and run SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Apr 12, 2020
1 parent b80c685 commit 53353da
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 8 deletions.
106 changes: 106 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
excluded:
- Pods
- docs
- build
- scripts

disabled_rules:
# metrics
- nesting

# lint
- notification_center_detachment
- weak_delegate

# idiomatic
- force_cast
- type_name

# style
- identifier_name

opt_in_rules:
# performance
- empty_count
- first_where
- sorted_first_last
- contains_over_first_not_nil
- last_where
- reduce_into
- contains_over_filter_count
- contains_over_filter_is_empty
- empty_collection_literal
- type_contents_order

# idiomatic
- fatal_error_message
- xctfail_message
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- for_where
- function_default_parameter_at_end
- legacy_random
- no_extension_access_modifier
- redundant_type_annotation
- static_operator
- toggle_bool
- unavailable_function
- no_space_in_method_call

# style
- attributes
- number_separator
- operator_usage_whitespace
- sorted_imports
- vertical_parameter_alignment_on_call
- void_return
- closure_spacing
- empty_enum_arguments
- implicit_return
- modifier_order
- multiline_parameters
- trailing_closure
- unneeded_parentheses_in_closure_argument
- vertical_whitespace_between_cases

# lint
- overridden_super_call
- yoda_condition
- anyobject_protocol
- array_init
- empty_xctest_method
- identical_operands
- prohibited_super_call
- unused_import
- unused_capture_list
- duplicate_enum_cases
- legacy_multiple
- unused_declaration

line_length: 200
file_length: 600

type_body_length: 500

function_body_length: 250

cyclomatic_complexity: 15

type_contents_order:
order:
- associated_type
- type_alias
- case
- subtype
- type_property
- ib_outlet
- ib_inspectable
- instance_property
- initializer
- deinitializer
- subscript
- type_method
- view_life_cycle_method
- ib_action
- other_method
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Blog posts:
Overriding status bar display settings in the iOS simulator](https://www.jessesquires.com/blog/overriding-status-bar-settings-ios-simulator/)
* [A script to automate overriding iOS simulator status bar values](https://www.jessesquires.com/blog/automating-simctl-status-bar/)

[Xcode 11](https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes) shipped with `simctl status_bar`, a tool to override the status bar values in the simulator so you can take perfect screenshots.
[Xcode 11](https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes) shipped with `simctl status_bar`, a tool to override the status bar values in the simulator so you can take perfect screenshots.

However, it has some issues:
* The overrides do not persist across launches of the simulator
Expand All @@ -19,6 +19,12 @@ However, it has some issues:

This script fixes that. It overrides the status bars for all currently running simulators using "Apple's defaults" — full cellular bars, full wifi bars, full battery, and `9:41` for the time.

## Requirements

- Swift 5.2+
- Xcode 11.4+
- [SwiftLint](https://github.com/realm/SwiftLint)

## Contributing

Interested in making contributions to this project? Please review the guides below.
Expand Down
15 changes: 8 additions & 7 deletions nine41.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import Foundation

extension String {
var nsRange: NSRange {
return NSRange(location: 0, length: self.count)
NSRange(location: 0, length: self.count)
}
}

extension StringProtocol {
var byTrimmingWhiteSpace: String {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
self.trimmingCharacters(in: .whitespacesAndNewlines)
}
}

Expand All @@ -44,14 +44,15 @@ extension Process {
/// Executes `xcrun simctl list devices`
@discardableResult
func xcrun_list_devices() -> Data {
return self.xcrun("simctl", "list", "devices", "-j")
self.xcrun("simctl", "list", "devices", "-j")
}

/// Executes `xcrun simctl status_bar` on the specified device.
///
/// - Parameter device: The device for which status bar values should be overridden.
func xcrun_fix_status_bar(_ device: String) {
let magicDate = Date(timeIntervalSince1970: 1168364460) // 9:41 AM PT on Tuesday January 9, 2007
// 9:41 AM PT on Tuesday January 9, 2007
let magicDate = Date(timeIntervalSince1970: 1_168_364_460)
let time = ISO8601DateFormatter().string(from: magicDate)

self.xcrun(
Expand All @@ -71,9 +72,9 @@ extension Process {
print("Fixing status bars...")

let deviceData = Process().xcrun_list_devices()
let json = (try! JSONSerialization.jsonObject(with: deviceData, options: [])) as! Dictionary<String, Any>
let runtimes = json["devices"] as! Dictionary<String, Array<Any>>
let allDevices = runtimes.values.flatMap { $0 } as! Array<Dictionary<String, AnyHashable>>
let json = (try? JSONSerialization.jsonObject(with: deviceData, options: [])) as! [String: Any]
let runtimes = json["devices"] as! [String: [Any]]
let allDevices = runtimes.values.flatMap { $0 } as! [[String: AnyHashable]]

var fixed = false

Expand Down
36 changes: 36 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Created by Jesse Squires
# https://www.jessesquires.com
#
# Copyright © 2020-present Jesse Squires
#
# SwiftLint
# https://github.com/realm/SwiftLint/releases/latest
# ------------------------------

VERSION="0.39.2"
FOUND=$(swiftlint version)

if which swiftlint >/dev/null; then
swiftlint lint --config ./.swiftlint.yml
exit
else
echo "
Error: SwiftLint not installed!
Download from https://github.com/realm/SwiftLint,
or brew install swiftlint.
"
fi

if [ $(swiftlint version) != $VERSION ]; then
echo "
Warning: incorrect SwiftLint installed!
Expected: $VERSION
Found: $FOUND
Download from https://github.com/realm/SwiftLint,
or brew upgrade swiftlint.
"
fi

exit

0 comments on commit 53353da

Please sign in to comment.