Skip to content

Commit

Permalink
Format code similar to SwiftNIO (#38)
Browse files Browse the repository at this point in the history
Motivation:

Common formatting is good.

Modifications:

Enable formatting CI and format code with same
config as SwiftNIO

Result:

Common code format
  • Loading branch information
PeterAdams-A authored Nov 1, 2024
1 parent 50ff68f commit d93f78c
Show file tree
Hide file tree
Showing 16 changed files with 884 additions and 424 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 0 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
with:
license_header_check_project_name: "Swift Cassandra Client"
api_breakage_check_enabled: false
format_check_enabled: false

unit-tests:
name: Unit Tests
Expand Down
62 changes: 62 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
21 changes: 0 additions & 21 deletions .swiftformat

This file was deleted.

36 changes: 23 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// swift-tools-version:5.6
import class Foundation.FileManager

import PackageDescription

import class Foundation.FileManager

// Compute libuv sources to exclude
var libuvExclude = [
"./libuv/src/unix/aix-common.c",
Expand Down Expand Up @@ -58,7 +60,8 @@ var datastaxExclude = [
"./datastax-cpp-driver/src/wktgen.sh",
"./datastax-cpp-driver/src/gssapi",
"./datastax-cpp-driver/src/ssl/ssl_no_impl.cpp",
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp", // See ./custom/src/ssl/ssl_openssl_impl.cpp
// See ./custom/src/ssl/ssl_openssl_impl.cpp
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp",
"./datastax-cpp-driver/src/third_party/curl/CMakeLists.txt",
"./datastax-cpp-driver/src/third_party/curl/COPYING",
"./datastax-cpp-driver/src/third_party/hdr_histogram/CMakeLists.txt",
Expand All @@ -82,7 +85,9 @@ var datastaxExclude = [
]

do {
if !(try FileManager.default.contentsOfDirectory(atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles").isEmpty) {
if !(try FileManager.default.contentsOfDirectory(
atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles"
).isEmpty) {
datastaxExclude.append("./datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles/")
}
} catch {
Expand All @@ -92,7 +97,7 @@ do {
let package = Package(
name: "swift-cassandra-client",
products: [
.library(name: "CassandraClient", targets: ["CassandraClient"]),
.library(name: "CassandraClient", targets: ["CassandraClient"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.41.1")),
Expand Down Expand Up @@ -121,7 +126,7 @@ let package = Package(
],
cSettings: [
.headerSearchPath("./libuv/src"),
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
]
),

Expand All @@ -138,7 +143,9 @@ let package = Package(
],
publicHeadersPath: "./datastax-cpp-driver/include",
cxxSettings: [
.define("HAVE_TIMERFD", .when(platforms: [.linux])), // this is available on all modern Linux systems, and is needed for efficient MicroTimer implementation. Otherwise busy waits are used.
// This is available on all modern Linux systems, and is needed for efficient
// MicroTimer implementation. Otherwise busy waits are used.
.define("HAVE_TIMERFD", .when(platforms: [.linux])),
.headerSearchPath("./custom/include"),
.headerSearchPath("./extras"),
.headerSearchPath("./datastax-cpp-driver/src"),
Expand All @@ -147,13 +154,16 @@ let package = Package(
]
),

.target(name: "CassandraClient", dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]),
.target(
name: "CassandraClient",
dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]
),

.testTarget(name: "CassandraClientTests", dependencies: ["CassandraClient"]),
],
Expand Down
32 changes: 20 additions & 12 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// swift-tools-version:5.4
import class Foundation.FileManager

import PackageDescription

import class Foundation.FileManager

// Compute libuv sources to exclude
var libuvExclude = [
"./libuv/src/unix/aix-common.c",
Expand Down Expand Up @@ -58,7 +60,8 @@ var datastaxExclude = [
"./datastax-cpp-driver/src/wktgen.sh",
"./datastax-cpp-driver/src/gssapi",
"./datastax-cpp-driver/src/ssl/ssl_no_impl.cpp",
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp", // See ./custom/src/ssl/ssl_openssl_impl.cpp
// See ./custom/src/ssl/ssl_openssl_impl.cpp
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp",
"./datastax-cpp-driver/src/third_party/curl/CMakeLists.txt",
"./datastax-cpp-driver/src/third_party/curl/COPYING",
"./datastax-cpp-driver/src/third_party/hdr_histogram/CMakeLists.txt",
Expand All @@ -82,7 +85,9 @@ var datastaxExclude = [
]

do {
if !(try FileManager.default.contentsOfDirectory(atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles").isEmpty) {
if !(try FileManager.default.contentsOfDirectory(
atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles"
).isEmpty) {
datastaxExclude.append("./datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles/")
}
} catch {
Expand All @@ -92,7 +97,7 @@ do {
let package = Package(
name: "swift-cassandra-client",
products: [
.library(name: "CassandraClient", targets: ["CassandraClient"]),
.library(name: "CassandraClient", targets: ["CassandraClient"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio", .upToNextMinor(from: "2.41.1")),
Expand Down Expand Up @@ -121,7 +126,7 @@ let package = Package(
],
cSettings: [
.headerSearchPath("./libuv/src"),
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
]
),

Expand All @@ -146,13 +151,16 @@ let package = Package(
]
),

.target(name: "CassandraClient", dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]),
.target(
name: "CassandraClient",
dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]
),

.testTarget(name: "CassandraClientTests", dependencies: ["CassandraClient"]),
],
Expand Down
32 changes: 20 additions & 12 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// swift-tools-version:5.4
import class Foundation.FileManager

import PackageDescription

import class Foundation.FileManager

// Compute libuv sources to exclude
var libuvExclude = [
"./libuv/src/unix/aix-common.c",
Expand Down Expand Up @@ -58,7 +60,8 @@ var datastaxExclude = [
"./datastax-cpp-driver/src/wktgen.sh",
"./datastax-cpp-driver/src/gssapi",
"./datastax-cpp-driver/src/ssl/ssl_no_impl.cpp",
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp", // See ./custom/src/ssl/ssl_openssl_impl.cpp
// See ./custom/src/ssl/ssl_openssl_impl.cpp
"./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp",
"./datastax-cpp-driver/src/third_party/curl/CMakeLists.txt",
"./datastax-cpp-driver/src/third_party/curl/COPYING",
"./datastax-cpp-driver/src/third_party/hdr_histogram/CMakeLists.txt",
Expand All @@ -82,7 +85,9 @@ var datastaxExclude = [
]

do {
if !(try FileManager.default.contentsOfDirectory(atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles").isEmpty) {
if !(try FileManager.default.contentsOfDirectory(
atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles"
).isEmpty) {
datastaxExclude.append("./datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles/")
}
} catch {
Expand All @@ -92,7 +97,7 @@ do {
let package = Package(
name: "swift-cassandra-client",
products: [
.library(name: "CassandraClient", targets: ["CassandraClient"]),
.library(name: "CassandraClient", targets: ["CassandraClient"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio", .upToNextMinor(from: "2.41.1")),
Expand Down Expand Up @@ -121,7 +126,7 @@ let package = Package(
],
cSettings: [
.headerSearchPath("./libuv/src"),
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
.define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error
]
),

Expand All @@ -146,13 +151,16 @@ let package = Package(
]
),

.target(name: "CassandraClient", dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]),
.target(
name: "CassandraClient",
dependencies: [
"CDataStaxDriver",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]
),

.testTarget(name: "CassandraClientTests", dependencies: ["CassandraClient"]),
],
Expand Down
Loading

0 comments on commit d93f78c

Please sign in to comment.