-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FXIOS-8821 [SwiftLint] for_where #19889
Changes from all commits
91d87b4
b8a1e6e
18ca703
b8a9637
4936c26
1f5f9cb
86e6504
215f226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,28 +192,27 @@ private class TPStatsBlocklists { | |
return nil | ||
} | ||
|
||
domainSearch: for rule in rules { | ||
// First, test the top-level filters to see if this URL might be blocked. | ||
if rule.regex.firstMatch(in: resourceString, options: .anchored, range: resourceRange) != nil { | ||
// Check the domain exceptions. If a domain exception matches, this filter does not apply. | ||
for domainRegex in (rule.domainExceptions ?? []) { | ||
if domainRegex.firstMatch(in: resourceString, options: [], range: resourceRange) != nil { | ||
continue domainSearch | ||
} | ||
for rule in rules { | ||
guard let _ = rule.regex.firstMatch(in: resourceString, options: .anchored, range: resourceRange) else { | ||
continue | ||
} | ||
let hasDomainException = rule.domainExceptions?.contains { domainRegex in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add the comment back here as well:
|
||
domainRegex.firstMatch(in: resourceString, options: [], range: resourceRange) != nil | ||
} ?? false | ||
guard !hasDomainException else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Although guarding can make the early exits more readable in this case the inversion makes me a bit confused. |
||
continue | ||
} | ||
if let baseDomain = url.baseDomain, !permittedDomains.isEmpty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this comment should be added back too:
|
||
let range = NSRange(location: 0, length: baseDomain.count) | ||
let isPermittedDomain = permittedDomains.contains { ignoreDomain in | ||
ignoreDomain.firstMatch(in: baseDomain, options: [], range: range) != nil | ||
} | ||
|
||
// Check the whitelist. | ||
if let baseDomain = url.baseDomain, !permittedDomains.isEmpty { | ||
let range = NSRange(location: 0, length: baseDomain.count) | ||
for ignoreDomain in permittedDomains { | ||
if ignoreDomain.firstMatch(in: baseDomain, options: [], range: range) != nil { | ||
return nil | ||
} | ||
} | ||
guard !isPermittedDomain else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is a permitted domain we should return nil instead of continuing. |
||
continue | ||
} | ||
|
||
return rule.list | ||
} | ||
|
||
return rule.list | ||
} | ||
|
||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,15 +81,11 @@ public class KeyboardHelper: NSObject { | |
* Delegates are weakly held. | ||
*/ | ||
public func addDelegate(delegate: KeyboardHelperDelegate) { | ||
for weakDelegate in delegates { | ||
// Reuse any existing slots that have been deallocated. | ||
if weakDelegate.delegate == nil { | ||
weakDelegate.delegate = delegate | ||
return | ||
} | ||
if let availableSlot = delegates.first(where: { $0.delegate == nil }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the comment back:
|
||
availableSlot.delegate = delegate | ||
} else { | ||
delegates.append(WeakKeyboardDelegate(delegate)) | ||
} | ||
|
||
delegates.append(WeakKeyboardDelegate(delegate)) | ||
} | ||
|
||
@objc func keyboardWillShow(notification: NSNotification) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,29 +27,21 @@ class SearchHistoryUtils { | |||||||||||||||
|
||||||||||||||||
static func pushSearchToStack(with searchedText: String) { | ||||||||||||||||
// Check whether the lastSearch is the current search. If not, remove subsequent searches | ||||||||||||||||
if let lastSearch = currentStack.last, !lastSearch.isCurrentSearch { | ||||||||||||||||
for index in 0..<currentStack.count { | ||||||||||||||||
if currentStack[index].isCurrentSearch { | ||||||||||||||||
currentStack.removeSubrange(index+1..<currentStack.count) | ||||||||||||||||
break | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
if let lastIndex = currentStack.firstIndex(where: { !$0.isCurrentSearch }) { | ||||||||||||||||
currentStack.removeSubrange(lastIndex + 1..<currentStack.count) | ||||||||||||||||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change doesn't look correct. The stack should only be cleaned up if the lastSearch is not the current search.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, the change might not be correct. We want go and look for searches to be removed only if the last search is not the current search. Then we look for the first search that is current search and remove everything after it (not including it). After that we mark everything as not being current search and only afteeer that we add the new search and mark it accordingly. Ugh that was a lot. A similar implementation the might be more clear can be: static func pushSearchToStack(with searchedText: String) {
// Check if the stack is empty and directly append if it is
guard !currentStack.isEmpty else {
currentStack.append(textSearched(text: searchedText, isCurrentSearch: true))
return
}
// Find the last `current search` and truncate the stack beyond this point
if let lastIndex = currentStack.lastIndex(where: { $0.isCurrentSearch }) {
currentStack = Array(currentStack.prefix(upTo: lastIndex + 1))
}
// Mark all as not current in a single pass and append new search
currentStack = currentStack.map { textSearched(text: $0.text, isCurrentSearch: false) }
currentStack.append(textSearched(text: searchedText, isCurrentSearch: true))
} To show an example we start with Then we truncate after index 2 We set everything to false Then we add the search |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
for index in 0..<currentStack.count { | ||||||||||||||||
for index in currentStack.indices { | ||||||||||||||||
currentStack[index].isCurrentSearch = false | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
currentStack.append(textSearched(text: searchedText, isCurrentSearch: true)) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
static func pullSearchFromStack() -> String? { | ||||||||||||||||
for search in currentStack { | ||||||||||||||||
if search.isCurrentSearch { | ||||||||||||||||
return search.text | ||||||||||||||||
} | ||||||||||||||||
for search in currentStack where search.isCurrentSearch { | ||||||||||||||||
return search.text | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add the comment back in:
// First, test the top-level filters to see if this URL might be blocked.