diff --git a/CHANGELOG b/CHANGELOG index cbce932..b397357 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +2.7.5 + - Added .swiftlint.yml that enforces Mobify code style 2.7.4 (February 2, 2017) - Add new classname prefixes to CSS documentation: `pw-` and `qa-` - Add links to alternative CSSComb text editor plugins diff --git a/swift/.swiftlint.yml b/swift/.swiftlint.yml new file mode 100644 index 0000000..43d79ff --- /dev/null +++ b/swift/.swiftlint.yml @@ -0,0 +1,16 @@ +disabled_rules: + - line_length + - file_length + - function_body_length + - todo + - cyclomatic_complexity + - variable_name + - force_cast + - nesting + - function_parameter_count + - force_try + - legacy_constructor + +type_body_length: + - 480 # warning + - 500 # error diff --git a/swift/README.md b/swift/README.md index bf5f08e..bdd24fa 100644 --- a/swift/README.md +++ b/swift/README.md @@ -6,6 +6,27 @@ We also follow the [Swift API design guidelines](https://swift.org/documentation Our overarching goals are conciseness, readability, and simplicity. +## Linting + +Included is a default Mobify Swift Style Guide SwiftLint configuration,`.swiftlint.yml`. + +You can install [SwiftLint](https://github.com/realm/SwiftLint) by command `brew install swiftlint` + +### Integration +Integrate SwiftLint into Xcode to get warnings and errors displayed. You can add a new "Run Script" with: + +```bash +if which swiftlint >/dev/null; then + swiftlint +else + echo "warning: SwiftLint not installed, install using 'brew install swiftlint'" +fi +``` + +Autocorrect is available by command `swiftlint autocorrect` + +For more information on this linter you can visit [this](https://github.com/realm/SwiftLint) page + ## Table of Contents * [Correctness](#correctness) @@ -353,7 +374,7 @@ class BoardLocation { init(row: Int, column: Int) { self.row = row self.column = column - + let closure = { print(self.row) } @@ -418,7 +439,7 @@ Mark classes `final` when inheritance is not intended. Example: ```swift // Turn any generic type into a reference type using this Box class. final class Box { - let value: T + let value: T init(_ value: T) { self.value = value } @@ -440,7 +461,7 @@ func reticulateSplines(spline: [Double]) -> Bool { For functions with long signatures, add line breaks after each parameter and indent them on the same level as the first parameter. ```swift -func reticulateSplines(spline: [Double], +func reticulateSplines(spline: [Double], adjustmentFactor: Double, translateConstant: Int, comment: String) -> Bool { @@ -906,15 +927,15 @@ When coding with conditionals, the left hand margin of the code should be the "g ```swift func computeFFT(context: Context?, inputData: InputData?) throws -> Frequencies { - guard let context = context else { - throw FFTError.noContext + guard let context = context else { + throw FFTError.noContext } - guard let inputData = inputData else { - throw FFTError.noInputData + guard let inputData = inputData else { + throw FFTError.noInputData } - + // use context and input to compute the frequencies - + return frequencies } ``` @@ -1048,4 +1069,3 @@ Prefer Autolayout over springs+struts (autoresizing mask). Autolayout automatica ## Credits Heavily based on [The Official raywenderlich.com Swift Style Guide](https://github.com/raywenderlich/swift-style-guide/blob/master/README.markdown) -