Skip to content

Commit 612f4f3

Browse files
committed
Add even more example violations
1 parent 4744f45 commit 612f4f3

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

assets/ScreenshotExample.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import Foundation
22

3-
class MyViewController : UIViewController { // space before colon
4-
var userName:String = "" // no space after colon; redundant type
5-
let x = 5 // short variable name
3+
class MyViewController : UIViewController { // space before colon
4+
var userName:String? = "" // no space after colon; redundant type
5+
let x = 5 // short variable name
66

7-
func doSomething(arg: Int) { // unused parameter
8-
let result = userName as! String // force cast
7+
func doSomething(arg: Int) { // unused parameter
8+
let result = userName as! String // force cast
99

10-
if(result.count > 0) { // control statement parentheses; use !isEmpty
10+
if(result.count > 0 && x > 1) { // control statement parentheses; use !isEmpty; prefer condition list
1111
print("User name is not empty")
12+
return
13+
} else { // unnecessary else
14+
print("User name is empty")
1215
}
1316

14-
// try! someRiskyOperation() // SwiftLint is syntax-aware -> no violation here
15-
try! someRiskyOperation() // force try
17+
// try! someOperation() // SwiftLint is syntax-aware -> no violation here
18+
try! MyViewController.someOperation() // force try; prefer Self
1619
}
1720

18-
func someRiskyOperation() async throws { // unnecessary async; unnecessary throws
19-
// Implementation
21+
final class func someOperation() async throws { // final class -> static; unnecessary async; unnecessary throws
22+
if let userName = userName {} // shorthand optional binding; empty block
2023
}
2124
}
25+

assets/screenshot.png

26.1 KB
Loading

0 commit comments

Comments
 (0)