@@ -50,28 +50,28 @@ func test(s: String) {
5050 // --- constructing a String.Index from integer ---
5151
5252 let ix1 = String . Index ( encodedOffset: s. count) // GOOD
53- let ix2 = String . Index ( encodedOffset: ns. length) // BAD: NSString length used in String.Index
54- let ix3 = String . Index ( encodedOffset: s. utf8. count) // BAD: String.utf8 length used in String.Index
55- let ix4 = String . Index ( encodedOffset: s. utf16. count) // BAD: String.utf16 length used in String.Index
56- let ix5 = String . Index ( encodedOffset: s. unicodeScalars. count) // BAD: string.unicodeScalars length used in String.Index
53+ let ix2 = String . Index ( encodedOffset: ns. length) // BAD: NSString length used in String.Index [NOT DETECTED]
54+ let ix3 = String . Index ( encodedOffset: s. utf8. count) // BAD: String.utf8 length used in String.Index [NOT DETECTED]
55+ let ix4 = String . Index ( encodedOffset: s. utf16. count) // BAD: String.utf16 length used in String.Index [NOT DETECTED]
56+ let ix5 = String . Index ( encodedOffset: s. unicodeScalars. count) // BAD: string.unicodeScalars length used in String.Index [NOT DETECTED]
5757 print ( " String.Index ' \( ix1. encodedOffset) ' / ' \( ix2. encodedOffset) ' ' \( ix3. encodedOffset) ' ' \( ix4. encodedOffset) ' ' \( ix5. encodedOffset) ' " )
5858
5959 let ix6 = s. index ( s. startIndex, offsetBy: s. count / 2 ) // GOOD
60- let ix7 = s. index ( s. startIndex, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index
60+ let ix7 = s. index ( s. startIndex, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index [NOT DETECTED]
6161 print ( " index ' \( ix6. encodedOffset) ' / ' \( ix7. encodedOffset) ' " )
6262
6363 var ix8 = s. startIndex
6464 s. formIndex ( & ix8, offsetBy: s. count / 2 ) // GOOD
6565 var ix9 = s. startIndex
66- s. formIndex ( & ix9, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index
66+ s. formIndex ( & ix9, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index [NOT DETECTED]
6767 print ( " formIndex ' \( ix8. encodedOffset) ' / ' \( ix9. encodedOffset) ' " )
6868
6969 // --- constructing an NSRange from integers ---
7070
7171 let range1 = NSMakeRange ( 0 , ns. length) // GOOD
7272 let range2 = NSMakeRange ( 0 , s. count) // BAD: String length used in NSMakeRange
73- let range3 = NSMakeRange ( 0 , s. reversed ( ) . count) // BAD: String length used in NSMakeRange
74- let range4 = NSMakeRange ( 0 , s. distance ( from: s. startIndex, to: s. endIndex) ) // BAD: String length used in NSMakeRange
73+ let range3 = NSMakeRange ( 0 , s. reversed ( ) . count) // BAD: String length used in NSMakeRange [NOT DETECTED]
74+ let range4 = NSMakeRange ( 0 , s. distance ( from: s. startIndex, to: s. endIndex) ) // BAD: String length used in NSMakeRange [NOT DETECTED]
7575 print ( " NSMakeRange ' \( range1. description) ' / ' \( range2. description) ' ' \( range3. description) ' ' \( range4. description) ' " )
7676
7777 let range5 = NSRange ( location: 0 , length: ns. length) // GOOD
@@ -81,43 +81,43 @@ func test(s: String) {
8181 // --- String operations using an integer directly ---
8282
8383 let str1 = s. dropFirst ( s. count - 1 ) // GOOD
84- let str2 = s. dropFirst ( ns. length - 1 ) // BAD: NSString length used in String
84+ let str2 = s. dropFirst ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
8585 print ( " dropFirst ' \( str1) ' / ' \( str2) ' " )
8686
8787 let str3 = s. dropLast ( s. count - 1 ) // GOOD
88- let str4 = s. dropLast ( ns. length - 1 ) // BAD: NSString length used in String
88+ let str4 = s. dropLast ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
8989 print ( " dropLast ' \( str3) ' / ' \( str4) ' " )
9090
9191 let str5 = s. prefix ( s. count - 1 ) // GOOD
92- let str6 = s. prefix ( ns. length - 1 ) // BAD: NSString length used in String
92+ let str6 = s. prefix ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
9393 print ( " prefix ' \( str5) ' / ' \( str6) ' " )
9494
9595 let str7 = s. suffix ( s. count - 1 ) // GOOD
96- let str8 = s. suffix ( ns. length - 1 ) // BAD: NSString length used in String
96+ let str8 = s. suffix ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
9797 print ( " suffix ' \( str7) ' / ' \( str8) ' " )
9898
9999 let nstr1 = ns. character ( at: ns. length - 1 ) // GOOD
100100 let nmstr1 = nms. character ( at: nms. length - 1 ) // GOOD
101- let nstr2 = ns. character ( at: s. count - 1 ) // BAD: String length used in NSString
102- let nmstr2 = nms. character ( at: s. count - 1 ) // BAD: String length used in NString
101+ let nstr2 = ns. character ( at: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
102+ let nmstr2 = nms. character ( at: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
103103 print ( " character ' \( nstr1) ' ' \( nmstr1) ' / ' \( nstr2) ' ' \( nmstr2) ' " )
104104
105105 let nstr3 = ns. substring ( from: ns. length - 1 ) // GOOD
106106 let nmstr3 = nms. substring ( from: nms. length - 1 ) // GOOD
107- let nstr4 = ns. substring ( from: s. count - 1 ) // BAD: String length used in NSString
108- let nmstr4 = nms. substring ( from: s. count - 1 ) // BAD: String length used in NString
107+ let nstr4 = ns. substring ( from: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
108+ let nmstr4 = nms. substring ( from: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
109109 print ( " substring from ' \( nstr3) ' ' \( nmstr3) ' / ' \( nstr4) ' ' \( nmstr4) ' " )
110110
111111 let nstr5 = ns. substring ( to: ns. length - 1 ) // GOOD
112112 let nmstr5 = nms. substring ( to: nms. length - 1 ) // GOOD
113- let nstr6 = ns. substring ( to: s. count - 1 ) // BAD: String length used in NSString
114- let nmstr6 = nms. substring ( to: s. count - 1 ) // BAD: String length used in NString
113+ let nstr6 = ns. substring ( to: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
114+ let nmstr6 = nms. substring ( to: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
115115 print ( " substring to ' \( nstr5) ' ' \( nmstr5) ' / ' \( nstr6) ' ' \( nmstr6) ' " )
116116
117117 let nmstr7 = NSMutableString ( string: s)
118118 nmstr7. insert ( " * " , at: nms. length - 1 ) // GOOD
119119 let nmstr8 = NSMutableString ( string: s)
120- nmstr8. insert ( " * " , at: s. count - 1 ) // BAD: String length used in NSString
120+ nmstr8. insert ( " * " , at: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
121121 print ( " insert ' \( nmstr7) ' / ' \( nmstr8) ' " )
122122}
123123
0 commit comments