Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

SwiftLint Configuration #148

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions swift/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 30 additions & 10 deletions swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this automatically point to the mobify-code-style .swiftlint.yml file?

Copy link
Contributor

@kerrmarin kerrmarin Mar 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the swiftlint yaml file lives in the root of your iOS project. To point it to the code style lint file we would have to... make a symlink? We could probably do that as part of a postinstall npm hook

else
echo "warning: SwiftLint not installed, install using 'brew install swiftlint'"
fi
```

autocorrect is available by command `swiftlint autocorrect`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autocorrect (capitalized)...


for more information on this linter you can visit [this](https://github.com/realm/SwiftLint) page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For (capitalized)...


## Table of Contents

* [Correctness](#correctness)
Expand Down Expand Up @@ -353,7 +374,7 @@ class BoardLocation {
init(row: Int, column: Int) {
self.row = row
self.column = column

let closure = {
print(self.row)
}
Expand Down Expand Up @@ -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<T> {
let value: T
let value: T
init(_ value: T) {
self.value = value
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
```
Expand Down Expand Up @@ -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)