forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathomit_needless_words.swift
34 lines (27 loc) · 2.08 KB
/
omit_needless_words.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// RUN: %target-parse-verify-swift -Womit-needless-words
class C1 {
init(tasteString: String) { } // expected-warning{{'init(tasteString:)' could be named 'init(taste:)'}}{{8-8=taste }}
func processWithString(_ string: String, toInt: Int) { } // expected-warning{{'processWithString(_:toInt:)' could be named 'process(with:to:)'}}{{8-25=process}} {{26-27=with}} {{44-44=to }}
func processWithInt(_ value: Int) { } // expected-warning{{'processWithInt' could be named 'process(with:)'}}{{8-22=process}}
}
extension String {
static var randomString: String { return "" } // expected-warning{{'randomString' could be named 'random'}}{{14-26=random}}
var wonkycasedString: String { return self } // expected-warning{{'wonkycasedString' could be named 'wonkycased'}}{{7-23=wonkycased}}
}
func callSites(_ s: String) {
let c1 = C1(tasteString: "blah") // expected-warning{{'init(tasteString:)' could be named 'init(taste:)'}}{{15-26=taste}}
c1.processWithString("a", toInt: 1) // expected-warning{{'processWithString(_:toInt:)' could be named 'process(with:to:)'}}{{6-23=process}}{{29-34=to}}
c1.processWithInt(5) // expected-warning{{'processWithInt' could be named 'process(with:)'}}{{6-20=process}}
_ = String.randomString // expected-warning{{'randomString' could be named 'random'}}{{14-26=random}}
_ = s.wonkycasedString // expected-warning{{'wonkycasedString' could be named 'wonkycased'}}{{9-25=wonkycased}}
}
struct MagicNameString { }
extension String {
func appendStrings(_ strings: [String]) { } // expected-warning{{'appendStrings' could be named 'append'}}{{8-21=append}}
func appendObjects(_ objects: [AnyObject]) { } // expected-warning{{'appendObjects' could be named 'append'}}{{8-21=append}}
func appendMagicNameStrings(_ strings: [MagicNameString]) { } // expected-warning{{'appendMagicNameStrings' could be named 'append'}}{{8-30=append}}
}
class NSArray {
func arrayByAddingObject(_ x: AnyObject) -> NSArray { return NSArray() } // expected-warning{{'arrayByAddingObject' could be named 'adding' [-Womit-needless-words]}}{{8-27=adding}}
}
func emptyFirstParamName(_: Int) { }