diff options
| author | Steffen <steffen.ernst@mullvad.net> | 2025-08-25 12:37:41 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-09-30 11:11:29 +0200 |
| commit | d245030d373720aa627d5577e9251504ea2e9305 (patch) | |
| tree | 7a3b847ad9b32d691937ffe3f7896d935a34a4c9 | |
| parent | ceca0206a3af013470ab77d34468e76aa129fd78 (diff) | |
| download | mullvadvpn-d245030d373720aa627d5577e9251504ea2e9305.tar.xz mullvadvpn-d245030d373720aa627d5577e9251504ea2e9305.zip | |
Switch swiftformat to swift-format
| -rw-r--r-- | .github/workflows/ios-screenshots-tests.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/ios-validate-build-schemas.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/ios.yml | 31 | ||||
| -rw-r--r-- | ci/ios/create-vm/scripts/run-xcode-first-launch.sh | 3 | ||||
| -rw-r--r-- | ios/.swift-format | 77 | ||||
| -rw-r--r-- | ios/.swiftformat | 84 | ||||
| -rw-r--r-- | ios/.swiftlint.yml | 52 | ||||
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 6 | ||||
| -rw-r--r-- | ios/PacketTunnelCore/Daita/Maybenot.swift | 3 | ||||
| -rwxr-xr-x | ios/format.sh | 2 | ||||
| -rwxr-xr-x | ios/lint.sh | 2 |
11 files changed, 92 insertions, 172 deletions
diff --git a/.github/workflows/ios-screenshots-tests.yml b/.github/workflows/ios-screenshots-tests.yml index a091ac658e..c7fe27422f 100644 --- a/.github/workflows/ios-screenshots-tests.yml +++ b/.github/workflows/ios-screenshots-tests.yml @@ -8,7 +8,7 @@ on: - main paths: - .github/workflows/ios.yml - - ios/.swiftformat + - ios/.swift-format - ios/**/*.swift - ios/**/*.xctestplan workflow_dispatch: diff --git a/.github/workflows/ios-validate-build-schemas.yml b/.github/workflows/ios-validate-build-schemas.yml index 46d87c0077..07499a5849 100644 --- a/.github/workflows/ios-validate-build-schemas.yml +++ b/.github/workflows/ios-validate-build-schemas.yml @@ -9,7 +9,7 @@ on: paths: - .github/workflows/ios.yml - .github/workflows/ios-validate-build-schemas.yml - - ios/.swiftformat + - ios/.swift-format - ios/**/*.swift - ios/**/*.xctestplan - Cargo.toml diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 48184d848d..2a8409139c 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -5,7 +5,7 @@ on: paths: - .github/workflows/ios.yml - ios/build-rust-library.sh - - ios/.swiftformat + - ios/.swift-format - ios/wireguard-apple - ios/**/*.swift - ios/**/*.xctestplan @@ -14,36 +14,15 @@ on: permissions: {} jobs: - check-formatting: - name: Check formatting + swift-format: + name: Run swift format lint runs-on: macos-15 steps: - - name: Install SwiftFormat - run: | - brew update - brew upgrade swiftformat - - name: Checkout repository uses: actions/checkout@v4 - - name: Check formatting - run: | - swiftformat --version - swiftformat --lint . - working-directory: ios - - swiftlint: - name: Run swiftlint - runs-on: macos-15 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Run swiftlint - run: | - brew install swiftlint - swiftlint --version - swiftlint --reporter github-actions-logging + - name: Run swift format lint + run: ./lint.sh -s working-directory: ios ui-test-build: diff --git a/ci/ios/create-vm/scripts/run-xcode-first-launch.sh b/ci/ios/create-vm/scripts/run-xcode-first-launch.sh index 9159c90f21..c0d33de4b7 100644 --- a/ci/ios/create-vm/scripts/run-xcode-first-launch.sh +++ b/ci/ios/create-vm/scripts/run-xcode-first-launch.sh @@ -12,6 +12,3 @@ then echo >&1 "Downloading iOS Simulator runtime, this might take a while" xcodebuild -downloadPlatform iOS fi - -# Xcode is needed in order to run swiftformat or swiftlint -brew install swiftformat swiftlint
\ No newline at end of file diff --git a/ios/.swift-format b/ios/.swift-format new file mode 100644 index 0000000000..cd6f86ded3 --- /dev/null +++ b/ios/.swift-format @@ -0,0 +1,77 @@ +{ + "fileScopedDeclarationPrivacy": { + "accessLevel": "private" + }, + "indentConditionalCompilationBlocks": true, + "indentSwitchCaseLabels": false, + "indentation": { + "spaces": 4 + }, + "lineBreakAroundMultilineExpressionChainComponents": false, + "lineBreakBeforeControlFlowKeywords": false, + "lineBreakBeforeEachArgument": false, + "lineBreakBeforeEachGenericRequirement": false, + "lineBreakBetweenDeclarationAttributes": false, + "lineLength": 120, + "maximumBlankLines": 1, + "multiElementCollectionTrailingCommas": true, + "noAssignmentInExpressions": { + "allowedFunctions": [ + "XCTAssertNoThrow" + ] + }, + "prioritizeKeepingFunctionOutputTogether": false, + "reflowMultilineStringLiterals": { + "never": {} + }, + "respectsExistingLineBreaks": true, + "rules": { + "AllPublicDeclarationsHaveDocumentation": false, + "AlwaysUseLiteralForEmptyCollectionInit": false, + "AlwaysUseLowerCamelCase": false, + "AmbiguousTrailingClosureOverload": true, + "AvoidRetroactiveConformances": false, + "BeginDocumentationCommentWithOneLineSummary": false, + "DoNotUseSemicolons": true, + "DontRepeatTypeInStaticProperties": false, + "FileScopedDeclarationPrivacy": true, + "FullyIndirectEnum": true, + "GroupNumericLiterals": true, + "IdentifiersMustBeASCII": true, + "NeverForceUnwrap": false, + "NeverUseForceTry": false, + "NeverUseImplicitlyUnwrappedOptionals": false, + "NoAccessLevelOnExtensionDeclaration": false, + "NoAssignmentInExpressions": true, + "NoBlockComments": false, + "NoCasesWithOnlyFallthrough": true, + "NoEmptyLinesOpeningClosingBraces": false, + "NoEmptyTrailingClosureParentheses": true, + "NoLabelsInCasePatterns": true, + "NoLeadingUnderscores": false, + "NoParensAroundConditions": true, + "NoPlaygroundLiterals": true, + "NoVoidReturnOnFunctionSignature": true, + "OmitExplicitReturns": false, + "OneCasePerLine": true, + "OneVariableDeclarationPerLine": true, + "OnlyOneTrailingClosureArgument": true, + "OrderedImports": true, + "ReplaceForEachWithForLoop": false, + "ReturnVoidInsteadOfEmptyTuple": true, + "TypeNamesShouldBeCapitalized": true, + "UseEarlyExits": false, + "UseExplicitNilCheckInConditions": true, + "UseLetInEveryBoundCaseVariable": false, + "UseShorthandTypeNames": true, + "UseSingleLinePropertyGetter": true, + "UseSynthesizedInitializer": true, + "UseTripleSlashForDocumentationComments": false, + "UseWhereClausesInForLoops": false, + "ValidateDocumentationComments": false + }, + "spacesAroundRangeFormationOperators": false, + "spacesBeforeEndOfLineComments": 2, + "tabWidth": 8, + "version": 1 +}
\ No newline at end of file diff --git a/ios/.swiftformat b/ios/.swiftformat deleted file mode 100644 index d6c663b36e..0000000000 --- a/ios/.swiftformat +++ /dev/null @@ -1,84 +0,0 @@ -# file options ---exclude Build, .spm, MullvadVPNScreenshots/SnapshotHelper.swift, PacketTunnelCore/Daita/Maybenot.swift, wireguard-apple - -# general options ---swiftversion 5.8 - -# format options ---indent 4 -# Google suggests 100, but Mullvad historically uses 120 ---maxwidth 120 -# The cardinal rules of Google Swift style for line-wrapping are: - # If the entire declaration, statement, or expression fits on one line, then do that. - # All elements must fit on the same line, or each element must be on its own line. ---wraparguments before-first ---wrapcollections before-first ---wrapternary before-operators ---redundanttype inferred ---ifdef no-indent -# Use K&R brace style, which is what Apple also uses ---allman false -# Use consistent ordering for member modifiers. ---modifierorder ---disable \ -initCoderUnavailable, \ -unusedArguments, \ -redundantRawValues, \ -preferKeyPath, \ -extensionAccessControl, \ -hoistTry, \ -# Do not reorganize declarations -organizeDeclarations, \ -# Do not reorder switch case statements -sortedSwitchCases, \ -# Do not add // MARK: ClassName before every type -markTypes, \ -# disable enum imports since it seems borken -enumNamespaces - - ---rules \ -blankLinesAroundMark, \ -blankLinesAtEndOfScope, \ -blankLinesAtStartOfScope, \ -blankLinesBetweenScopes, \ -braces, \ -consecutiveBlankLines, \ -consecutiveSpaces, \ -duplicateImports, \ -elseOnSameLine, \ -emptyBraces, \ -enumNamespaces, \ -extensionAccessControl, \ -hoistPatternLet, \ -indent, \ -leadingDelimiters, \ -linebreakAtEndOfFile, \ -redundantInit, \ -redundantParens, \ -redundantPattern, \ -redundantRawValues, \ -redundantType, \ -redundantVoidReturnType, \ -semicolons, \ -sortImports, \ -spaceAroundBraces, \ -spaceAroundBrackets, \ -spaceAroundComments, \ -spaceAroundGenerics, \ -spaceAroundOperators, \ -spaceAroundParens, \ -spaceInsideBraces, \ -spaceInsideBrackets, \ -spaceInsideComments, \ -spaceInsideGenerics, \ -spaceInsideParens, \ -todos, \ -trailingClosures, \ -trailingCommas, \ -trailingSpace, \ -typeSugar, \ -void, \ -wrap, \ -wrapArguments, \ -wrapAttributes diff --git a/ios/.swiftlint.yml b/ios/.swiftlint.yml deleted file mode 100644 index 408738d853..0000000000 --- a/ios/.swiftlint.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -disabled_rules: - - colon - - comma - - control_statement - - identifier_name - - type_body_length - - opening_brace # Differs from Google swift guidelines enforced by swiftformat - - trailing_comma - - switch_case_alignment # Enables expressions such as [return switch location {}] - - orphaned_doc_comment -opt_in_rules: - - empty_count - -analyzer_rules: # rules run by `swiftlint analyze` - - explicit_self - -included: # case-sensitive paths to include during linting. `--path` is ignored if present - - . -excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included` - - AdditionalAssets - - Assets - - Build - - Configurations - - MullvadVPNScreenshots - - wireguard-apple - -allow_zero_lintable_files: false - -force_cast: warning -force_try: - severity: warning -line_length: - ignores_comments: true - ignores_interpolated_strings: true - warning: 120 - error: 300 -cyclomatic_complexity: - ignores_case_statements: true - -type_name: - min_length: 4 - max_length: - warning: 50 - error: 60 - excluded: iPhone # excluded via string - allowed_symbols: ["_"] # these are allowed in type names -reporter: "xcode" -nesting: - type_level: - warning: 2 - error: 4 diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 410989b975..5966f448c1 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -5833,7 +5833,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "./lint.sh\n"; }; 580E3F222A9861990061809D /* Run SwiftLint */ = { isa = PBXShellScriptBuildPhase; @@ -5852,7 +5852,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint PacketTunnel/**/*.swift\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "./lint.sh\n"; }; A93969802CE603110032A7A0 /* Import maybenot_machines */ = { isa = PBXShellScriptBuildPhase; @@ -5870,7 +5870,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "MAYBENOT_MACHINES=`cat ${SRCROOT}/../dist-assets/maybenot_machines`\ncat > ${SRCROOT}/PacketTunnelCore/Daita/Maybenot.swift << EOF\n// swiftlint:disable line_length\n// This is an autogenerated file, do not edit\npublic struct Maybenot {\n public let machines=\"\"\"\n$MAYBENOT_MACHINES\n\"\"\"\n public let maximumEvents: UInt32 = 2048\n public let maximumActions: UInt32 = 1024\n public let maximumPadding: Double = 1.0\n public let maximumBlocking: Double = 1.0\n}\n// swiftlint:enable line_length\nEOF\n"; + shellScript = "MAYBENOT_MACHINES=`cat ${SRCROOT}/../dist-assets/maybenot_machines`\ncat > ${SRCROOT}/PacketTunnelCore/Daita/Maybenot.swift << EOF\n// swift-format-ignore-file\n// This is an autogenerated file, do not edit\npublic struct Maybenot {\n public let machines=\"\"\"\n$MAYBENOT_MACHINES\n\"\"\"\n public let maximumEvents: UInt32 = 2048\n public let maximumActions: UInt32 = 1024\n public let maximumPadding: Double = 1.0\n public let maximumBlocking: Double = 1.0\n}\nEOF\n"; }; A992DA2A2C2470B300DE7CE5 /* Build MullvadRustRuntime */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/PacketTunnelCore/Daita/Maybenot.swift b/ios/PacketTunnelCore/Daita/Maybenot.swift index 0bc682af75..3420853fe6 100644 --- a/ios/PacketTunnelCore/Daita/Maybenot.swift +++ b/ios/PacketTunnelCore/Daita/Maybenot.swift @@ -1,4 +1,4 @@ -// swiftlint:disable line_length +// swift-format-ignore-file // This is an autogenerated file, do not edit public struct Maybenot { public let machines=""" @@ -12,4 +12,3 @@ public struct Maybenot { public let maximumPadding: Double = 1.0 public let maximumBlocking: Double = 1.0 } -// swiftlint:enable line_length diff --git a/ios/format.sh b/ios/format.sh new file mode 100755 index 0000000000..005d8e66df --- /dev/null +++ b/ios/format.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +swift format format -r -p -i Mullvad* Routing* Shared TunnelObfuscationTests PacketTunnel* Operations*
\ No newline at end of file diff --git a/ios/lint.sh b/ios/lint.sh new file mode 100755 index 0000000000..9190670308 --- /dev/null +++ b/ios/lint.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +swift format lint -r -p $@ Mullvad* Routing* Shared TunnelObfuscationTests PacketTunnel* Operations*
\ No newline at end of file |
