From 9c04cbdc328eb8e3bee828ac47602dda4b95e419 Mon Sep 17 00:00:00 2001 From: Igor Kislyuk Date: Fri, 28 Jul 2017 05:02:10 +0300 Subject: [PATCH] Add. Code quality --- .gitmodules | 3 + LeadKitAdditions/.swiftlint.yml | 122 +++++++++++++++++- LeadKitAdditions/.tailor.yml | 4 - .../project.pbxproj | 30 ++--- .../ViewModel/BasePassCodeViewModel.swift | 2 + .../Sources/Services/MaskFieldTextProxy.swift | 3 + .../ValidationService/ValidationItem.swift | 2 + .../CellTextFieldViewModel.swift | 3 + code-quality | 1 + 9 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 .gitmodules delete mode 100644 LeadKitAdditions/.tailor.yml create mode 160000 code-quality diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..53b16c0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "code-quality"] + path = code-quality + url = https://github.com/TouchInstinct/code-quality-ios diff --git a/LeadKitAdditions/.swiftlint.yml b/LeadKitAdditions/.swiftlint.yml index 307a6ea..cd926c2 100644 --- a/LeadKitAdditions/.swiftlint.yml +++ b/LeadKitAdditions/.swiftlint.yml @@ -1,8 +1,9 @@ disabled_rules: - - variable_name + - identifier_name excluded: - Carthage - Pods + line_length: 128 type_body_length: - 500 # warning @@ -16,6 +17,121 @@ custom_rules: uiwebview_disabled: included: ".*.swift" name: "UIWebView Usage Disabled" - regex: "(UIWebView)" + regex: 'UIWebView' message: "Do not use UIWebView. Use WKWebView Instead. https://developer.apple.com/reference/uikit/uiwebview" - severity: error \ No newline at end of file + severity: error + + native_print: + name: "print -> DDLog" + regex: '(print|NSLog)\(' + message: "Please use CocoaLumberjack instead `print` and `NSlog`" + severity: error + + zero: + name: "Short .zero" + regex: '\(top: 0, left: 0, bottom: 0, right: 0\)' + message: "Please use short init `.zero`." + severity: error + + private_variable: + name: "Private variable" + regex: '(?|>=)\s*0' + message: "Prefer checking `isEmpty` over comparing `count` to zero." + severity: warning + + # Should be { braces_body } instead of {braces_body} + spaces_around_braces: + included: ".*.swift" + name: "Spaces around the braces" + regex: '(([A-Za-z0-9])[\{\}])|([\{\}]([A-Za-z0-9]))' + message: "No spaces around the braces" + severity: error + match_kinds: + - attribute.builtin + - attribute.id + - buildconfig.id + - buildconfig.keyword + - identifier + - keyword + - objectliteral + - parameter + - placeholder + - typeidentifier + + inout_keyword: + name: "Inout" + regex: 'inout' + message: "Don't use inout arguments" + severity: error + match_kinds: keyword + + continue_keyword: + name: "Continue" + regex: 'continue' + message: "Don't use continue instruction" + severity: error + match_kinds: keyword + + cyrillic_strings: + name: "Cyrillic strings" + regex: '[а-яА-Я]+' + message: "Localize or translate" + severity: error + match_kinds: + - identifier + - string + + simple_ban: + name: "Simple type name" + regex: '(class|struct)(.)+[sS]imple(.)+\{' + message: "Don't use 'simple' in type name, use 'default' or 'base' instead" + severity: warning diff --git a/LeadKitAdditions/.tailor.yml b/LeadKitAdditions/.tailor.yml deleted file mode 100644 index 1bee518..0000000 --- a/LeadKitAdditions/.tailor.yml +++ /dev/null @@ -1,4 +0,0 @@ -exclude: - - 'Pods' - - 'Carthage' - - 'RxAlamofire' diff --git a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj index 44d3e55..d511837 100644 --- a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj +++ b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj @@ -385,7 +385,6 @@ CAE698E11E968820000394B0 /* Resources */, 94F6E1BA5AD68C6E2F10062B /* [CP] Copy Pods Resources */, CAE6990A1E969A7A000394B0 /* Swiftlint */, - CAE6990B1E969A8D000394B0 /* Tailor */, ); buildRules = ( ); @@ -406,6 +405,7 @@ EFBD556D1EBB87100062AA63 /* Headers */, EFBD556E1EBB87100062AA63 /* Resources */, 808FF5474C0E1574D405EFAF /* [CP] Copy Pods Resources */, + ED69E7E91F2AD0E000C74895 /* Swiftlint */, ); buildRules = ( ); @@ -531,20 +531,6 @@ shellPath = /bin/sh; shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; }; - CAE6990B1E969A8D000394B0 /* Tailor */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = Tailor; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "if hash tailor 2>/dev/null; then\n tailor\nelse\n echo \"warning: Please install Tailor from https://tailor.sh\"\nfi"; - }; E8E82E34792B38EF225575D7 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -560,6 +546,20 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + ED69E7E91F2AD0E000C74895 /* Swiftlint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = Swiftlint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/LeadKitAdditions/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift b/LeadKitAdditions/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift index 3fbd333..b78d9a4 100644 --- a/LeadKitAdditions/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift +++ b/LeadKitAdditions/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift @@ -52,7 +52,9 @@ open class BasePassCodeViewModel: BaseViewModel { return passCodeControllerStateHolder.asDriver() } + // swiftlint:disable private_variable public let passCodeText = Variable(nil) + // swiftlint:enable private_variable fileprivate var attemptsNumber = 0 diff --git a/LeadKitAdditions/Sources/Services/MaskFieldTextProxy.swift b/LeadKitAdditions/Sources/Services/MaskFieldTextProxy.swift index e28c424..cfd4ead 100644 --- a/LeadKitAdditions/Sources/Services/MaskFieldTextProxy.swift +++ b/LeadKitAdditions/Sources/Services/MaskFieldTextProxy.swift @@ -6,7 +6,10 @@ class MaskFieldTextProxy: NSObject { private var disposeBag = DisposeBag() + // swiftlint:disable private_variable let text = Variable("") + // swiftlint:enable private_variable + fileprivate let isCompleteHolder = Variable(false) var isComplete: Bool { return isCompleteHolder.value diff --git a/LeadKitAdditions/Sources/Services/ValidationService/ValidationItem.swift b/LeadKitAdditions/Sources/Services/ValidationService/ValidationItem.swift index 902ac93..3204d53 100644 --- a/LeadKitAdditions/Sources/Services/ValidationService/ValidationItem.swift +++ b/LeadKitAdditions/Sources/Services/ValidationService/ValidationItem.swift @@ -43,7 +43,9 @@ class ValidationItem { return validationStateHolder.asObservable() } + // swiftlint:disable private_variable let text = Variable(nil) + // swiftlint:enable private_variable private(set) var rules: [Rule] = [] diff --git a/LeadKitAdditions/Sources/Views/CellTextField/CellTextFieldViewModel.swift b/LeadKitAdditions/Sources/Views/CellTextField/CellTextFieldViewModel.swift index c154ede..1c9ffcd 100644 --- a/LeadKitAdditions/Sources/Views/CellTextField/CellTextFieldViewModel.swift +++ b/LeadKitAdditions/Sources/Views/CellTextField/CellTextFieldViewModel.swift @@ -3,7 +3,10 @@ import RxSwift class CellTextFieldViewModel: CellFieldJumpingProtocol { + // swiftlint:disable private_variable let text: Variable + // swiftlint:enable private_variable + let placeholder: String let textFieldSettingsBlock: ItemSettingsBlock? diff --git a/code-quality b/code-quality new file mode 160000 index 0000000..817e845 --- /dev/null +++ b/code-quality @@ -0,0 +1 @@ +Subproject commit 817e845592f02fb0d22bf52ff9bb8db3210ddd89