Skip to content

Commit 041d04e

Browse files
farhanpatelStephan Leroux
authored and
Stephan Leroux
committedFeb 21, 2017
No Bug - Remove uses of legacy constructors and enable the rule in swiftlint.
1 parent f23c201 commit 041d04e

19 files changed

+45
-36
lines changed
 

‎.swiftlint.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
disabled_rules: # rule identifiers to exclude from running
2-
- legacy_constructor
32
- variable_name
43
- legacy_cggeometry_functions
5-
- legacy_constant
64
- todo
75
- trailing_newline
86
- empty_count

‎Client/Extensions/GeometryExtensions.swift

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ extension CGRect {
1515
}
1616
}
1717

18+
extension UIEdgeInsets {
19+
init(equalInset inset: CGFloat) {
20+
top = inset
21+
left = inset
22+
right = inset
23+
bottom = inset
24+
}
25+
}
26+
1827
/**
1928
Generates the affine transform for transforming the first CGRect into the second one
2029

‎Client/Frontend/Browser/LoginsHelper.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class LoginsHelper: TabHelper {
8585
range: nil,
8686
locale: nil)!
8787
string.replaceSubrange(range, with: replace)
88-
let nsRange = NSMakeRange(string.characters.distance(from: string.startIndex, to: range.lowerBound),
89-
replace.characters.count)
88+
let nsRange = NSRange(location: string.characters.distance(from: string.startIndex, to: range.lowerBound),
89+
length: replace.characters.count)
9090
ranges.append(nsRange)
9191
}
9292

‎Client/Frontend/Browser/TabLocationView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class TabLocationView: UIView {
219219
if let httplessURL = url?.absoluteDisplayString, let baseDomain = url?.baseDomain {
220220
// Highlight the base domain of the current URL.
221221
let attributedString = NSMutableAttributedString(string: httplessURL)
222-
let nsRange = NSMakeRange(0, httplessURL.characters.count)
222+
let nsRange = NSRange(location: 0, length: httplessURL.characters.count)
223223
attributedString.addAttribute(NSForegroundColorAttributeName, value: baseURLFontColor, range: nsRange)
224224
attributedString.colorSubstring(baseDomain, withColor: hostFontColor)
225225
attributedString.addAttribute(UIAccessibilitySpeechAttributePitch, value: NSNumber(value: TabLocationViewUX.BaseURLPitch), range: nsRange)

‎Client/Frontend/Browser/TabTrayController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class TabCell: UICollectionViewCell {
126126
self.closeButton = UIButton()
127127
self.closeButton.setImage(UIImage(named: "stop"), for: UIControlState())
128128
self.closeButton.tintColor = UIColor.lightGray
129-
self.closeButton.imageEdgeInsets = UIEdgeInsetsMake(TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset)
129+
self.closeButton.imageEdgeInsets = UIEdgeInsets(equalInset: TabTrayControllerUX.CloseButtonEdgeInset)
130130

131131
self.innerStroke = InnerStrokedView(frame: self.backgroundHolder.frame)
132132
self.innerStroke.layer.backgroundColor = UIColor.clear.cgColor
@@ -963,7 +963,7 @@ fileprivate class TabLayoutDelegate: NSObject, UICollectionViewDelegateFlowLayou
963963
}
964964

965965
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
966-
return UIEdgeInsetsMake(TabTrayControllerUX.Margin, TabTrayControllerUX.Margin, TabTrayControllerUX.Margin, TabTrayControllerUX.Margin)
966+
return UIEdgeInsets(equalInset: TabTrayControllerUX.Margin)
967967
}
968968

969969
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {

‎Client/Frontend/Browser/TopTabsLayout.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TopTabsLayoutDelegate: NSObject, UICollectionViewDelegateFlowLayout {
1515
}
1616

1717
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
18-
return UIEdgeInsetsMake(0, TopTabsUX.TopTabsBackgroundShadowWidth, 0, TopTabsUX.TopTabsBackgroundShadowWidth)
18+
return UIEdgeInsets(top: 0, left: TopTabsUX.TopTabsBackgroundShadowWidth, bottom: 0, right: TopTabsUX.TopTabsBackgroundShadowWidth)
1919
}
2020

2121
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {

‎Client/Frontend/Browser/TopTabsViews.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class TopTabCell: UICollectionViewCell {
6868
let closeButton = UIButton()
6969
closeButton.setImage(UIImage(named: "topTabs-closeTabs"), for: UIControlState())
7070
closeButton.tintColor = UIColor.lightGray
71-
closeButton.imageEdgeInsets = UIEdgeInsetsMake(TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset, TabTrayControllerUX.CloseButtonEdgeInset)
71+
72+
closeButton.imageEdgeInsets = UIEdgeInsets(equalInset: TabTrayControllerUX.CloseButtonEdgeInset)
7273
return closeButton
7374
}()
7475

‎Client/Frontend/Home/ReaderPanel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ReadingListTableViewCell: UITableViewCell {
165165
if !unread {
166166
// mimic light gray visual dimming by "dimming" the speech by reducing pitch
167167
let lowerPitchString = NSMutableAttributedString(string: string as String)
168-
lowerPitchString.addAttribute(UIAccessibilitySpeechAttributePitch, value: NSNumber(value: ReadingListTableViewCellUX.ReadAccessibilitySpeechPitch as Float), range: NSMakeRange(0, lowerPitchString.length))
168+
lowerPitchString.addAttribute(UIAccessibilitySpeechAttributePitch, value: NSNumber(value: ReadingListTableViewCellUX.ReadAccessibilitySpeechPitch as Float), range: NSRange(location: 0, length: lowerPitchString.length))
169169
label = NSAttributedString(attributedString: lowerPitchString)
170170
} else {
171171
label = string as AnyObject

‎Client/Frontend/Intro/IntroViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class IntroViewController: UIViewController, UIScrollViewDelegate {
363363
paragraphStyle.alignment = .center
364364

365365
let string = NSMutableAttributedString(string: text)
366-
string.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, string.length))
366+
string.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: string.length))
367367
return string
368368
}
369369

‎Client/Frontend/Reader/ReadabilityTabHelper.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ReadabilityTabHelper: TabHelper {
2121
let readabilitySource = try? NSMutableString(contentsOfFile: readabilityPath, encoding: String.Encoding.utf8.rawValue),
2222
let readabilityTabHelperPath = Bundle.main.path(forResource: ReadabilityTabHelper.name(), ofType: "js"),
2323
let readabilityTabHelperSource = try? NSMutableString(contentsOfFile: readabilityTabHelperPath, encoding: String.Encoding.utf8.rawValue) {
24-
readabilityTabHelperSource.replaceOccurrences(of: "%READABILITYJS%", with: readabilitySource as String, options: NSString.CompareOptions.literal, range: NSMakeRange(0, readabilityTabHelperSource.length))
24+
readabilityTabHelperSource.replaceOccurrences(of: "%READABILITYJS%", with: readabilitySource as String, options: NSString.CompareOptions.literal, range: NSRange(location: 0, length: readabilityTabHelperSource.length))
2525
let userScript = WKUserScript(source: readabilityTabHelperSource as String, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true)
2626
tab.webView!.configuration.userContentController.addUserScript(userScript)
2727
}

‎Client/Frontend/Reader/ReaderModeHandlers.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ struct ReaderModeHandlers {
5959
do {
6060
let readerViewLoading = try NSMutableString(contentsOfFile: readerViewLoadingPath, encoding: String.Encoding.utf8.rawValue)
6161
readerViewLoading.replaceOccurrences(of: "%ORIGINAL-URL%", with: url.absoluteString,
62-
options: NSString.CompareOptions.literal, range: NSMakeRange(0, readerViewLoading.length))
62+
options: NSString.CompareOptions.literal, range: NSRange(location: 0, length: readerViewLoading.length))
6363
readerViewLoading.replaceOccurrences(of: "%LOADING-TEXT%", with: NSLocalizedString("Loading content…", comment: "Message displayed when the reader mode page is loading. This message will appear only when sharing to Firefox reader mode from another app."),
64-
options: NSString.CompareOptions.literal, range: NSMakeRange(0, readerViewLoading.length))
64+
options: NSString.CompareOptions.literal, range: NSRange(location: 0, length: readerViewLoading.length))
6565
readerViewLoading.replaceOccurrences(of: "%LOADING-FAILED-TEXT%", with: NSLocalizedString("The page could not be displayed in Reader View.", comment: "Message displayed when the reader mode page could not be loaded. This message will appear only when sharing to Firefox reader mode from another app."),
66-
options: NSString.CompareOptions.literal, range: NSMakeRange(0, readerViewLoading.length))
66+
options: NSString.CompareOptions.literal, range: NSRange(location: 0, length: readerViewLoading.length))
6767
readerViewLoading.replaceOccurrences(of: "%LOAD-ORIGINAL-TEXT%", with: NSLocalizedString("Load original page", comment: "Link for going to the non-reader page when the reader view could not be loaded. This message will appear only when sharing to Firefox reader mode from another app."),
68-
options: NSString.CompareOptions.literal, range: NSMakeRange(0, readerViewLoading.length))
68+
options: NSString.CompareOptions.literal, range: NSRange(location: 0, length: readerViewLoading.length))
6969
return GCDWebServerDataResponse(html: readerViewLoading as String)
7070
} catch _ {
7171
}

‎Client/Frontend/Reader/ReaderModeUtils.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ struct ReaderModeUtils {
2525
do {
2626
let tmpl = try NSMutableString(contentsOfFile: tmplPath, encoding: String.Encoding.utf8.rawValue)
2727
tmpl.replaceOccurrences(of: "%READER-CSS%", with: css as String,
28-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
28+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
2929

3030
tmpl.replaceOccurrences(of: "%READER-STYLE%", with: initialStyle.encode(),
31-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
31+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
3232

3333
tmpl.replaceOccurrences(of: "%READER-DOMAIN%", with: simplifyDomain(readabilityResult.domain),
34-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
34+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
3535

3636
tmpl.replaceOccurrences(of: "%READER-URL%", with: readabilityResult.url,
37-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
37+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
3838

3939
tmpl.replaceOccurrences(of: "%READER-TITLE%", with: readabilityResult.title,
40-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
40+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
4141

4242
tmpl.replaceOccurrences(of: "%READER-CREDITS%", with: readabilityResult.credits,
43-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
43+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
4444

4545
tmpl.replaceOccurrences(of: "%READER-CONTENT%", with: readabilityResult.content,
46-
options: NSString.CompareOptions(), range: NSMakeRange(0, tmpl.length))
46+
options: NSString.CompareOptions(), range: NSRange(location: 0, length: tmpl.length))
4747

4848
return tmpl as String
4949
} catch _ {

‎Client/Frontend/Settings/AppSettingsOptions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class SyncNowSetting: WithAccountSetting {
126126
let formattedLabel = timestampFormatter.string(from: Date.fromTimestamp(timestamp))
127127
let attributedString = NSMutableAttributedString(string: formattedLabel)
128128
let attributes = [NSForegroundColorAttributeName: UIColor.gray, NSFontAttributeName: UIFont.systemFont(ofSize: 12, weight: UIFontWeightRegular)]
129-
let range = NSMakeRange(0, attributedString.length)
129+
let range = NSRange(location: 0, length: attributedString.length)
130130
attributedString.setAttributes(attributes, range: range)
131131
return attributedString
132132
}

‎Client/Frontend/Settings/LoginDetailViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class LoginDetailViewController: SensitiveViewController {
129129
let itemsToHideSeperators: [InfoItem] = [.passwordItem, .lastModifiedSeparator]
130130
itemsToHideSeperators.forEach { item in
131131
let cell = tableView.cellForRow(at: IndexPath(row: item.rawValue, section: 0))
132-
cell?.separatorInset = UIEdgeInsetsMake(0, cell?.bounds.width ?? 0, 0, 0)
132+
cell?.separatorInset = UIEdgeInsets(top: 0, left: cell?.bounds.width ?? 0, bottom: 0, right: 0)
133133
}
134134

135135
// Rows to display full width seperator

‎Client/Frontend/Widgets/AutocompleteTextField.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate {
8181
if let text = text {
8282
if !text.isEmpty {
8383
let attributedString = NSMutableAttributedString(string: text)
84-
attributedString.addAttribute(NSBackgroundColorAttributeName, value: highlightColor, range: NSMakeRange(0, (text).characters.count))
84+
attributedString.addAttribute(NSBackgroundColorAttributeName, value: highlightColor, range: NSRange(location: 0, length: (text).characters.count))
8585
attributedText = attributedString
8686

8787
enteredText = ""
@@ -167,7 +167,7 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate {
167167
if suggestion.startsWith(normalizeString(enteredText)) && normalizeString(enteredText).characters.count < suggestion.characters.count {
168168
let endingString = suggestion.substring(from: suggestion.characters.index(suggestion.startIndex, offsetBy: normalizeString(enteredText).characters.count))
169169
let completedAndMarkedString = NSMutableAttributedString(string: enteredText + endingString)
170-
completedAndMarkedString.addAttribute(NSBackgroundColorAttributeName, value: highlightColor, range: NSMakeRange(enteredText.characters.count, endingString.characters.count))
170+
completedAndMarkedString.addAttribute(NSBackgroundColorAttributeName, value: highlightColor, range: NSRange(location: enteredText.characters.count, length: endingString.characters.count))
171171
attributedText = completedAndMarkedString
172172
completionActive = true
173173
previousSuggestion = suggestion

‎Client/Frontend/Widgets/SnackBar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class SnackBar: UIView {
188188
}
189189

190190
contentView.snp.remakeConstraints { make in
191-
make.top.left.right.equalTo(self).inset(UIEdgeInsetsMake(UIConstants.DefaultPadding, UIConstants.DefaultPadding, UIConstants.DefaultPadding, UIConstants.DefaultPadding))
191+
make.top.left.right.equalTo(self).inset(UIEdgeInsets(equalInset: UIConstants.DefaultPadding))
192192
}
193193

194194
if let img = imageView.image {

‎Client/Frontend/Widgets/TwoLineCell.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TwoLineTableViewCell: UITableViewCell {
4040

4141
indentationWidth = 0
4242
layoutMargins = UIEdgeInsets.zero
43-
separatorInset = UIEdgeInsetsMake(0, TwoLineCellUX.ImageSize + 2 * TwoLineCellUX.BorderViewMargin, 0, 0)
43+
separatorInset = UIEdgeInsets(top: 0, left: TwoLineCellUX.ImageSize + 2 * TwoLineCellUX.BorderViewMargin, bottom: 0, right: 0)
4444
}
4545

4646
required init?(coder aDecoder: NSCoder) {
@@ -54,7 +54,7 @@ class TwoLineTableViewCell: UITableViewCell {
5454

5555
override func prepareForReuse() {
5656
super.prepareForReuse()
57-
separatorInset = UIEdgeInsetsMake(0, TwoLineCellUX.ImageSize + 2 * TwoLineCellUX.BorderViewMargin, 0, 0)
57+
separatorInset = UIEdgeInsets(top: 0, left: TwoLineCellUX.ImageSize + 2 * TwoLineCellUX.BorderViewMargin, bottom: 0, right: 0)
5858
twoLineHelper.setupDynamicFonts()
5959
}
6060

@@ -82,7 +82,7 @@ class HistoryTableViewCell: TwoLineTableViewCell {
8282
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
8383
super.init(style: UITableViewCellStyle.subtitle, reuseIdentifier: reuseIdentifier)
8484
contentView.addSubview(borderView)
85-
separatorInset = UIEdgeInsetsMake(0, TwoLineCellUX.BorderFrameSize + 2 * TwoLineCellUX.BorderViewMargin, 0, 0)
85+
separatorInset = UIEdgeInsets(top: 0, left: TwoLineCellUX.BorderFrameSize + 2 * TwoLineCellUX.BorderViewMargin, bottom: 0, right: 0)
8686

8787
borderView.frame = CGRect(x: TwoLineCellUX.BorderViewMargin, y: TwoLineCellUX.BorderViewMargin, width: TwoLineCellUX.BorderFrameSize, height: TwoLineCellUX.BorderFrameSize)
8888
borderView.layer.borderWidth = 0.5
@@ -102,7 +102,7 @@ class HistoryTableViewCell: TwoLineTableViewCell {
102102

103103
override func prepareForReuse() {
104104
super.prepareForReuse()
105-
separatorInset = UIEdgeInsetsMake(0, TwoLineCellUX.BorderFrameSize + 2 * TwoLineCellUX.BorderViewMargin, 0, 0)
105+
separatorInset = UIEdgeInsets(top: 0, left: TwoLineCellUX.BorderFrameSize + 2 * TwoLineCellUX.BorderViewMargin, bottom: 0, right: 0)
106106
}
107107

108108
required init?(coder aDecoder: NSCoder) {

‎Extensions/SendTo/InstructionsViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private func highlightLink(_ s: NSString, withColor color: UIColor) -> NSAttribu
2626
let end = s.range(of: ">")
2727
s = s.replacingCharacters(in: end, with: "") as NSString
2828
let a = NSMutableAttributedString(string: s as String)
29-
let r = NSMakeRange(start.location, end.location-start.location)
29+
let r = NSRange(location: start.location, length: end.location-start.location)
3030
a.addAttribute(NSForegroundColorAttributeName, value: color, range: r)
3131
return a
3232
}

‎Shared/UserAgent.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ open class UserAgent {
6767
let webKitVersionRegex = try! NSRegularExpression(pattern: "AppleWebKit/([^ ]+) ", options: [])
6868

6969
let match = webKitVersionRegex.firstMatch(in: userAgent, options:[],
70-
range: NSMakeRange(0, userAgent.characters.count))
70+
range: NSRange(location: 0, length: userAgent.characters.count))
7171

7272
if match == nil {
7373
print("Error: Unable to determine WebKit version in UA.")
@@ -98,15 +98,16 @@ open class UserAgent {
9898

9999
// Spoof platform section
100100
let platformRegex = try! NSRegularExpression(pattern: "\\([^\\)]+\\)", options: [])
101-
guard let platformMatch = platformRegex.firstMatch(in: userAgent as String, options:[], range: NSMakeRange(0, userAgent.length)) else {
101+
guard let platformMatch = platformRegex.firstMatch(in: userAgent as String, options:[], range: NSRange(location: 0, length: userAgent.length)) else {
102102
print("Error: Unable to determine platform in UA.")
103103
return String(userAgent)
104104
}
105105
userAgent.replaceCharacters(in: platformMatch.range, with: "(Macintosh; Intel Mac OS X 10_11_1)")
106106

107107
// Strip mobile section
108108
let mobileRegex = try! NSRegularExpression(pattern: " FxiOS/[^ ]+ Mobile/[^ ]+", options: [])
109-
guard let mobileMatch = mobileRegex.firstMatch(in: userAgent as String, options:[], range: NSMakeRange(0, userAgent.length)) else {
109+
110+
guard let mobileMatch = mobileRegex.firstMatch(in: userAgent as String, options:[], range: NSRange(location: 0, length: userAgent.length)) else {
110111
print("Error: Unable to find Mobile section in UA.")
111112
return String(userAgent)
112113
}

0 commit comments

Comments
 (0)
Please sign in to comment.