Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SwiftLint and .swiftformat #428

Merged
merged 11 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
110 changes: 107 additions & 3 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,108 @@
# https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md
# SwiftFormat config compliant with Google Swift Guideline
# https://google.github.io/swift/#control-flow-statements

# file options
--exclude Pods
# Specify version used in a project

--swiftversion 5.9

# Rules explicitly required by the guideline

--rules \
blankLinesAroundMark, \
blankLinesAtEndOfScope, \
blankLinesAtStartOfScope, \
blankLinesBetweenScopes, \
braces, \
consecutiveBlankLines, \
consecutiveSpaces, \
duplicateImports, \
elseOnSameLine, \
emptyBraces, \
enumNamespaces, \
extensionAccessControl, \
hoistPatternLet, \
indent, \
leadingDelimiters, \
linebreakAtEndOfFile, \
markTypes, \
organizeDeclarations, \
redundantInit, \
redundantParens, \
redundantPattern, \
redundantRawValues, \
redundantType, \
redundantVoidReturnType, \
semicolons, \
sortImports, \
sortSwitchCases, \
spaceAroundBraces, \
spaceAroundBrackets, \
spaceAroundComments, \
spaceAroundGenerics, \
spaceAroundOperators, \
spaceAroundParens, \
spaceInsideBraces, \
spaceInsideBrackets, \
spaceInsideComments, \
spaceInsideGenerics, \
spaceInsideParens, \
todos, \
trailingClosures, \
trailingCommas, \
trailingSpace, \
typeSugar, \
void, \
wrap, \
wrapArguments, \
wrapAttributes, \
#
#
# Additional rules not mentioned in the guideline, but helping to keep the codebase clean
# Quoting the guideline:
# Common themes among the rules in this section are:
# avoid redundancy, avoid ambiguity, and prefer implicitness over explicitness
# unless being explicit improves readability and/or reduces ambiguity.
#
#
andOperator, \
isEmpty, \
redundantBackticks, \
redundantBreak, \
redundantExtensionACL, \
redundantGet, \
redundantLetError, \
redundantNilInit, \
redundantObjc, \
redundantReturn, \
redundantSelf, \
strongifiedSelf


# Options for basic rules

--extensionacl on-declarations
--funcattributes prev-line
--indent 4
--maxwidth 120
--typeattributes prev-line
--varattributes same-line
--voidtype tuple
--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
--wrapreturntype if-multiline
--wrapconditions after-first

# Option for additional rules

--self init-only

# Excluded folders

--exclude Pods,**/UNTESTED_TODO,vendor,fastlane

# https://github.com/NoemiRozpara/Google-SwiftFormat-Config

# Following is by Lava

--ifdef no-indent
71 changes: 71 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Copyright (c) 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

disabled_rules:
- multiple_closures_with_trailing_closure
- nesting
- void_return
- shorthand_operator
- cyclomatic_complexity
- force_cast
- force_try
- large_tuple

opt_in_rules:
- convenience_type
# - no_magic_numbers
# - force_unwrapping

line_length:
warning: 120
ignores_comments: true
function_body_length:
warning: 120
error: 400
type_body_length:
warning: 500
error: 1200
file_length:
warning: 900
error: 1600
type_name:
min_length: 3
max_length:
warning: 50
error: 50
identifier_name:
min_length: 3
excluded: # excluded via string array
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
- id
- URL
- url
- x
- y
- i
- j
- Defaults # Make use of `SwiftyUserDefaults`
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
trailing_comma:
severity: warning
mandatory_comma: true

excluded:
- "Build/*"
- "Pods"
- "**/UNTESTED_TODO"
- "vendor"
- "fastlane"
- ".build"
26 changes: 23 additions & 3 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,8 @@
buildConfigurationList = C99EEB2C2385796900FEE666 /* Build configuration list for PBXNativeTarget "Easydict" */;
buildPhases = (
21D768ECC6D11E109E6EB73A /* [CP] Check Pods Manifest.lock */,
03B04B582B2D4B8E00E30823 /* Run Script */,
03B04B582B2D4B8E00E30823 /* Format */,
EAA54DF92B8C74F6001C2CC6 /* Lint */,
C99EEB142385796700FEE666 /* Sources */,
C99EEB152385796700FEE666 /* Frameworks */,
C99EEB162385796700FEE666 /* Resources */,
Expand Down Expand Up @@ -2662,7 +2663,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
03B04B582B2D4B8E00E30823 /* Run Script */ = {
03B04B582B2D4B8E00E30823 /* Format */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 12;
Expand All @@ -2672,7 +2673,7 @@
);
inputPaths = (
);
name = "Run Script";
name = Format;
outputFileListPaths = (
);
outputPaths = (
Expand Down Expand Up @@ -2759,6 +2760,25 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-EasydictTests/Pods-EasydictTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
EAA54DF92B8C74F6001C2CC6 /* Lint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = Lint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
12 changes: 10 additions & 2 deletions Easydict/Feature/Configuration/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
import Defaults
import Foundation

@objc enum AppearenceType: Int, CaseIterable, Defaults.Serializable {
// MARK: - AppearenceType

@objc
enum AppearenceType: Int, CaseIterable, Defaults.Serializable {
case followSystem = 0
case light
case dark

// MARK: Internal

var title: String {
switch self {
case .followSystem:
Expand Down Expand Up @@ -42,7 +47,10 @@ import Foundation
}
}

@objcMembers class AppearenceHelper: NSObject {
// MARK: - AppearenceHelper

@objcMembers
class AppearenceHelper: NSObject {
static let shared = AppearenceHelper()

func titles() -> [String] {
Expand Down
3 changes: 2 additions & 1 deletion Easydict/Feature/Configuration/Configuration+UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ extension Configuration {
let userDefaults = UserDefaults.standard

var userConfigDict = [String: Any]()
if let bundleIdentifier = Bundle.main.bundleIdentifier, let appUserDefaultsData = userDefaults.persistentDomain(forName: bundleIdentifier) {
if let bundleIdentifier = Bundle.main.bundleIdentifier,
let appUserDefaultsData = userDefaults.persistentDomain(forName: bundleIdentifier) {
for (key, value) in appUserDefaultsData {
if !key.hasPrefix("MASPreferences"), !(value is Data) {
userConfigDict[key] = value
Expand Down
Loading