Add. Code quality

This commit is contained in:
Igor Kislyuk 2017-07-28 05:02:10 +03:00
parent 192c7b0fe5
commit 9c04cbdc32
9 changed files with 148 additions and 22 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "code-quality"]
path = code-quality
url = https://github.com/TouchInstinct/code-quality-ios

View File

@ -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
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: '(?<!private\s)let\s\w*(:|(\s=))\sVariable'
message: "Please use (file)private with variable."
severity: error
let_variable:
name: "Let Variable"
regex: 'var\s\w*(:|(\s=))\sVariable'
message: "Please make variable using `let`."
severity: error
marks_style:
name: "Marks"
regex: '// MARK: -?[a-zA-Z0-9]'
message: "Marks should follow the following structure: // MARK: - Comment."
severity: warning
no_header_comments:
name: "Header Comments"
regex: '//\s*Created by.*\s*//\s*Copyright'
match_kinds:
- comment
message: "Template header comments should be removed."
private_outlet:
name: "Outlet"
regex: '@IBOutlet(\sweak)?(\s(file)?private(\(set\))?)?\svar'
message: "Please use some of `private` modifiers and make property it weak. Use pattern: `IBOutlet private weak var`."
severity: error
delegate:
name: "Delegate"
regex: '(?<!weak\s)var\s\w*(D|d)elegate\w*:'
message: "Please use `weak` for `delegate`. "
severity: error
unnecessary_type:
name: "Unnecessary Type"
regex: '[ @a-zA-Z]*(?:let|var)\s\w*: ([a-zA-Z0-9]*)\?? = \1'
message: "Type definition not needed"
severity: error
unowned:
name: "Unowned"
regex: 'unowned'
message: "Please use `weak` instead. "
severity: error
empty_count_zero:
name: "Empty Count Violation"
regex: '\.count\s*(==|!=|<|<=|>|>=)\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

View File

@ -1,4 +0,0 @@
exclude:
- 'Pods'
- 'Carthage'
- 'RxAlamofire'

View File

@ -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 */

View File

@ -52,7 +52,9 @@ open class BasePassCodeViewModel: BaseViewModel {
return passCodeControllerStateHolder.asDriver()
}
// swiftlint:disable private_variable
public let passCodeText = Variable<String?>(nil)
// swiftlint:enable private_variable
fileprivate var attemptsNumber = 0

View File

@ -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

View File

@ -43,7 +43,9 @@ class ValidationItem {
return validationStateHolder.asObservable()
}
// swiftlint:disable private_variable
let text = Variable<String?>(nil)
// swiftlint:enable private_variable
private(set) var rules: [Rule] = []

View File

@ -3,7 +3,10 @@ import RxSwift
class CellTextFieldViewModel: CellFieldJumpingProtocol {
// swiftlint:disable private_variable
let text: Variable<String?>
// swiftlint:enable private_variable
let placeholder: String
let textFieldSettingsBlock: ItemSettingsBlock<UITextField>?

1
code-quality Submodule

@ -0,0 +1 @@
Subproject commit 817e845592f02fb0d22bf52ff9bb8db3210ddd89