Skip to content

Commit 85f1d44

Browse files
committed
Automatically download swiftlint / xcbeautifier, lint fixes
1 parent a2897d5 commit 85f1d44

File tree

10 files changed

+80
-38
lines changed

10 files changed

+80
-38
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ DerivedData
2222
# Carthage
2323
/Carthage/
2424

25+
# Makefile
26+
bin/
27+
2528
# Swift Package Manager
2629
.build
2730
Packages/

.swiftlint.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ disabled_rules: # rule identifiers to exclude from running
44
- large_tuple
55
- closure_parameter_position
66
- inclusive_language # sqlite_master etc.
7+
- blanket_disable_command
78
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
89
- Sources
910
- Tests
@@ -26,8 +27,8 @@ identifier_name:
2627
- SQLITE_TRANSIENT
2728

2829
type_body_length:
29-
warning: 260
30-
error: 260
30+
warning: 350
31+
error: 350
3132

3233
function_body_length:
3334
warning: 60

Makefile

+58-23
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,76 @@
1-
BUILD_TOOL = xcodebuild
1+
XCODEBUILD = xcodebuild
22
BUILD_SCHEME = SQLite Mac
3-
IOS_SIMULATOR = iPhone 12
4-
IOS_VERSION = 15.0
3+
IOS_SIMULATOR = iPhone 14
4+
IOS_VERSION = 16.4
5+
6+
# tool settings
7+
SWIFTLINT_VERSION=0.52.2
8+
SWIFTLINT=bin/swiftlint-$(SWIFTLINT_VERSION)
9+
SWIFTLINT_URL=https://github.com/realm/SwiftLint/releases/download/$(SWIFTLINT_VERSION)/portable_swiftlint.zip
10+
XCBEAUTIFY_VERSION=0.20.0
11+
XCBEAUTIFY=bin/xcbeautify-$(XCBEAUTIFY_VERSION)
12+
ifeq ($(shell uname), Linux)
13+
XCBEAUTIFY_PLATFORM=x86_64-unknown-linux-gnu.tar.xz
14+
else
15+
XCBEAUTIFY_PLATFORM=universal-apple-macosx.zip
16+
endif
17+
XCBEAUTIFY_URL=https://github.com/tuist/xcbeautify/releases/download/$(XCBEAUTIFY_VERSION)/xcbeautify-$(XCBEAUTIFY_VERSION)-$(XCBEAUTIFY_PLATFORM)
18+
CURL_OPTS=--fail --silent -L --retry 3
19+
520
ifeq ($(BUILD_SCHEME),SQLite iOS)
621
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -destination "platform=iOS Simulator,name=$(IOS_SIMULATOR),OS=$(IOS_VERSION)"
722
else
823
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)"
924
endif
1025

11-
XCPRETTY := $(shell command -v xcpretty)
12-
TEST_ACTIONS := clean build build-for-testing test-without-building
26+
test: $(XCBEAUTIFY)
27+
set -o pipefail; \
28+
$(XCODEBUILD) $(BUILD_ARGUMENTS) test | $(XCBEAUTIFY)
1329

14-
default: test
30+
build: $(XCBEAUTIFY)
31+
set -o pipefail; \
32+
$(XCODEBUILD) $(BUILD_ARGUMENTS) | $(XCBEAUTIFY)
1533

16-
build:
17-
$(BUILD_TOOL) $(BUILD_ARGUMENTS)
34+
lint: $(SWIFTLINT)
35+
$< --strict
1836

19-
lint:
20-
swiftlint --strict
21-
lint-fix:
22-
swiftlint lint fix
23-
24-
test:
25-
ifdef XCPRETTY
26-
@set -o pipefail && $(BUILD_TOOL) $(BUILD_ARGUMENTS) $(TEST_ACTIONS) | $(XCPRETTY) -c
27-
else
28-
$(BUILD_TOOL) $(BUILD_ARGUMENTS) $(TEST_ACTIONS)
29-
endif
37+
lint-fix: $(SWIFTLINT)
38+
$< lint fix
3039

3140
clean:
32-
$(BUILD_TOOL) $(BUILD_ARGUMENTS) clean
41+
$(XCODEBUILD) $(BUILD_ARGUMENTS) clean
3342

3443
repl:
35-
@$(BUILD_TOOL) $(BUILD_ARGUMENTS) -derivedDataPath $(TMPDIR)/SQLite.swift > /dev/null && \
36-
swift -F '$(TMPDIR)/SQLite.swift/Build/Products/Debug'
44+
@$(XCODEBUILD) $(BUILD_ARGUMENTS) -derivedDataPath $(TMPDIR)/SQLite.swift > /dev/null && \
45+
swift repl -F '$(TMPDIR)/SQLite.swift/Build/Products/Debug'
3746

3847
sloc:
39-
@zsh -c "grep -vE '^ *//|^$$' Sources/**/*.{swift,h,m} | wc -l"
48+
@zsh -c "grep -vE '^ *//|^$$' Sources/**/*.{swift,h} | wc -l"
49+
50+
$(SWIFTLINT):
51+
set -e ; \
52+
curl $(CURL_OPTS) $(SWIFTLINT_URL) -o swiftlint.zip; \
53+
unzip -o swiftlint.zip swiftlint; \
54+
mkdir -p bin; \
55+
mv swiftlint $@ && rm -f swiftlint.zip
56+
57+
$(XCBEAUTIFY):
58+
set -e; \
59+
FILE=$(XCBEAUTIFY_PLATFORM); \
60+
curl $(CURL_OPTS) $(XCBEAUTIFY_URL) -o $$FILE; \
61+
case "$${FILE#*.}" in \
62+
"zip") \
63+
unzip -o $$FILE xcbeautify; \
64+
;; \
65+
"tar.xz") \
66+
tar -xvf $$FILE xcbeautify; \
67+
;; \
68+
*) \
69+
echo "unknown extension $${FILE#*.}!"; \
70+
exit 1; \
71+
;; \
72+
esac; \
73+
mkdir -p bin; \
74+
mv xcbeautify $@ && rm -f $$FILE;
4075

4176
.PHONY: test clean repl sloc

Sources/SQLite/Core/Backup.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public final class Backup {
140140
/// - Parameter pagesToCopy: The maximal number of pages to copy in one step
141141
///
142142
/// - Throws: `Result.Error` if step fails.
143-
//
143+
///
144144
/// See: <https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupstep>
145145
public func step(pagesToCopy pages: Pages = .all) throws {
146146
let status = sqlite3_backup_step(handle, pages.number)

Sources/SQLite/Helpers.swift

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public func *(_: Expression<Binding>?, _: Expression<Binding>?) -> Expression<Vo
3838
Expression(literal: "*")
3939
}
4040

41+
// swiftlint:disable:next type_name
4142
public protocol _OptionalType {
4243

4344
associatedtype WrappedType

Sources/SQLite/Schema/SchemaReader.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SchemaReader {
1313
// column name, data type, whether or not the column can be NULL, and the default value for the column. The
1414
// "pk" column in the result set is zero for columns that are not part of the primary key, and is the
1515
// index of the column in the primary key for columns that are part of the primary key.
16-
public func columnDefinitions(table: String) throws -> [ColumnDefinition] {
16+
public func columnDefinitions(table: String) throws -> [ColumnDefinition] {
1717
func parsePrimaryKey(column: String) throws -> ColumnDefinition.PrimaryKey? {
1818
try createTableSQL(name: table).flatMap { .init(sql: $0) }
1919
}

Sources/SQLite/Typed/Query.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ extension Connection {
11051105
return value(try scalar(expression.template, expression.bindings))
11061106
}
11071107

1108-
public func scalar<V: Value>(_ query: Select<V?>) throws -> V.ValueType? {
1108+
public func scalar<V: Value>(_ query: Select<V?>) throws -> V.ValueType? {
11091109
let expression = query.expression
11101110
guard let value = try scalar(expression.template, expression.bindings) as? V.Datatype else { return nil }
11111111
return V.fromDatatypeValue(value)

Tests/.swiftlint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ disabled_rules:
66
- identifier_name
77

88
type_body_length:
9-
warning: 800
10-
error: 800
9+
warning: 1000
10+
error: 1000
1111

1212
function_body_length:
1313
warning: 200

Tests/SQLiteTests/Schema/SchemaTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class SchemaTests: XCTestCase {
7272
}
7373

7474
// thoroughness test for ambiguity
75+
// swiftlint:disable:next function_body_length
7576
func test_column_compilesColumnDefinitionExpression() {
7677
XCTAssertEqual(
7778
"CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL)",
@@ -390,6 +391,7 @@ class SchemaTests: XCTestCase {
390391
)
391392
}
392393

394+
// swiftlint:disable:next function_body_length
393395
func test_column_withStringExpression_compilesCollatedColumnDefinitionExpression() {
394396
XCTAssertEqual(
395397
"CREATE TABLE \"table\" (\"string\" TEXT NOT NULL COLLATE RTRIM)",

Tests/SQLiteTests/Typed/CustomFunctionsTests.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import SQLite
55
#if !os(Linux)
66

77
class CustomFunctionNoArgsTests: SQLiteTestCase {
8-
typealias FunctionNoOptional = () -> Expression<String>
9-
typealias FunctionResultOptional = () -> Expression<String?>
8+
typealias FunctionNoOptional = () -> Expression<String>
9+
typealias FunctionResultOptional = () -> Expression<String?>
1010

1111
func testFunctionNoOptional() throws {
1212
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) {
@@ -26,9 +26,9 @@ class CustomFunctionNoArgsTests: SQLiteTestCase {
2626
}
2727

2828
class CustomFunctionWithOneArgTests: SQLiteTestCase {
29-
typealias FunctionNoOptional = (Expression<String>) -> Expression<String>
29+
typealias FunctionNoOptional = (Expression<String>) -> Expression<String>
3030
typealias FunctionLeftOptional = (Expression<String?>) -> Expression<String>
31-
typealias FunctionResultOptional = (Expression<String>) -> Expression<String?>
31+
typealias FunctionResultOptional = (Expression<String>) -> Expression<String?>
3232
typealias FunctionLeftResultOptional = (Expression<String?>) -> Expression<String?>
3333

3434
func testFunctionNoOptional() throws {
@@ -65,12 +65,12 @@ class CustomFunctionWithOneArgTests: SQLiteTestCase {
6565
}
6666

6767
class CustomFunctionWithTwoArgsTests: SQLiteTestCase {
68-
typealias FunctionNoOptional = (Expression<String>, Expression<String>) -> Expression<String>
69-
typealias FunctionLeftOptional = (Expression<String?>, Expression<String>) -> Expression<String>
68+
typealias FunctionNoOptional = (Expression<String>, Expression<String>) -> Expression<String>
69+
typealias FunctionLeftOptional = (Expression<String?>, Expression<String>) -> Expression<String>
7070
typealias FunctionRightOptional = (Expression<String>, Expression<String?>) -> Expression<String>
71-
typealias FunctionResultOptional = (Expression<String>, Expression<String>) -> Expression<String?>
71+
typealias FunctionResultOptional = (Expression<String>, Expression<String>) -> Expression<String?>
7272
typealias FunctionLeftRightOptional = (Expression<String?>, Expression<String?>) -> Expression<String>
73-
typealias FunctionLeftResultOptional = (Expression<String?>, Expression<String>) -> Expression<String?>
73+
typealias FunctionLeftResultOptional = (Expression<String?>, Expression<String>) -> Expression<String?>
7474
typealias FunctionRightResultOptional = (Expression<String>, Expression<String?>) -> Expression<String?>
7575
typealias FunctionLeftRightResultOptional = (Expression<String?>, Expression<String?>) -> Expression<String?>
7676

0 commit comments

Comments
 (0)