Enable SwiftLint rule 'cyclomatic_complexity' and fix violation which is reasonable
This commit is contained in:
parent
8345bb89a4
commit
2cdd0e2521
3 changed files with 39 additions and 51 deletions
|
|
@ -32,7 +32,7 @@ whitelist_rules:
|
||||||
- control_statement
|
- control_statement
|
||||||
- convenience_type
|
- convenience_type
|
||||||
- custom_rules
|
- custom_rules
|
||||||
# - cyclomatic_complexity
|
- cyclomatic_complexity
|
||||||
- deployment_target
|
- deployment_target
|
||||||
- discarded_notification_center_observer
|
- discarded_notification_center_observer
|
||||||
- discouraged_direct_init
|
- discouraged_direct_init
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ class PasswordEditorTableViewController: UITableViewController {
|
||||||
additionsCell?.contentTextView.setContentOffset(.zero, animated: false)
|
additionsCell?.contentTextView.setContentOffset(.zero, animated: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swiftlint:disable:next cyclomatic_complexity
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cellData = tableData[indexPath.section][indexPath.row]
|
let cellData = tableData[indexPath.section][indexPath.row]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,62 +63,49 @@ class ExtensionViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
}
|
}
|
||||||
|
|
||||||
for extensionItem in extensionItems {
|
for extensionItem in extensionItems {
|
||||||
if let itemProviders = extensionItem.attachments {
|
guard let itemProviders = extensionItem.attachments else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for provider in itemProviders {
|
for provider in itemProviders {
|
||||||
// search using the extensionContext inputs
|
// search using the extensionContext inputs
|
||||||
if provider.hasItemConformingToTypeIdentifier(OnePasswordExtensionActions.findLogin) {
|
if provider.hasItemConformingToTypeIdentifier(OnePasswordExtensionActions.findLogin) {
|
||||||
provider.loadItem(forTypeIdentifier: OnePasswordExtensionActions.findLogin, options: nil) { item, _ -> Void in
|
provider.loadItem(forTypeIdentifier: OnePasswordExtensionActions.findLogin, options: nil) { item, _ in
|
||||||
let dictionary = item as! NSDictionary
|
self.updateExtension(with: self.getUrl(from: item as! NSDictionary), action: .findLogin)
|
||||||
var url: String?
|
}
|
||||||
|
} else if provider.hasItemConformingToTypeIdentifier(kUTTypePropertyList as String) {
|
||||||
|
provider.loadItem(forTypeIdentifier: kUTTypePropertyList as String, options: nil) { item, _ in
|
||||||
|
if let dictionary = item as? NSDictionary, let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary {
|
||||||
|
self.updateExtension(with: self.getUrl(from: results))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if provider.hasItemConformingToTypeIdentifier(kUTTypeURL as String) {
|
||||||
|
provider.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil) { item, _ in
|
||||||
|
self.updateExtension(with: (item as? NSURL)!.host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getUrl(from dictionary: NSDictionary) -> String? {
|
||||||
if var urlString = dictionary[OnePasswordExtensionKey.URLStringKey] as? String {
|
if var urlString = dictionary[OnePasswordExtensionKey.URLStringKey] as? String {
|
||||||
if !urlString.hasPrefix("http://"), !urlString.hasPrefix("https://") {
|
if !urlString.hasPrefix("http://"), !urlString.hasPrefix("https://") {
|
||||||
urlString = "http://" + urlString
|
urlString = "http://" + urlString
|
||||||
}
|
}
|
||||||
url = URL(string: urlString)?.host
|
return URL(string: urlString)?.host
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateExtension(with url: String?, action: Action = .fillBrowser) {
|
||||||
|
// Set text, set active, and force search.
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
self?.extensionAction = .findLogin
|
self?.extensionAction = action
|
||||||
// force search (set text, set active, force search)
|
|
||||||
self?.searchBar.text = url
|
self?.searchBar.text = url
|
||||||
self?.searchBar.becomeFirstResponder()
|
self?.searchBar.becomeFirstResponder()
|
||||||
self?.searchBarSearchButtonClicked((self?.searchBar)!)
|
self?.searchBarSearchButtonClicked((self?.searchBar)!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if provider.hasItemConformingToTypeIdentifier(kUTTypePropertyList as String) {
|
|
||||||
provider.loadItem(forTypeIdentifier: kUTTypePropertyList as String, options: nil) { item, _ -> Void in
|
|
||||||
var url: String?
|
|
||||||
if let dictionary = item as? NSDictionary,
|
|
||||||
let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary,
|
|
||||||
var urlString = results[OnePasswordExtensionKey.URLStringKey] as? String {
|
|
||||||
if !urlString.hasPrefix("http://"), !urlString.hasPrefix("https://") {
|
|
||||||
urlString = "http://" + urlString
|
|
||||||
}
|
|
||||||
url = URL(string: urlString)?.host
|
|
||||||
}
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
|
||||||
self?.extensionAction = .fillBrowser
|
|
||||||
// force search (set text, set active, force search)
|
|
||||||
self?.searchBar.text = url
|
|
||||||
self?.searchBar.becomeFirstResponder()
|
|
||||||
self?.searchBarSearchButtonClicked((self?.searchBar)!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if provider.hasItemConformingToTypeIdentifier(kUTTypeURL as String) {
|
|
||||||
provider.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil) { item, _ -> Void in
|
|
||||||
let url = (item as? NSURL)!.host
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
|
||||||
self?.extensionAction = .fillBrowser
|
|
||||||
// force search (set text, set active, force search)
|
|
||||||
self?.searchBar.text = url
|
|
||||||
self?.searchBar.becomeFirstResponder()
|
|
||||||
self?.searchBarSearchButtonClicked((self?.searchBar)!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// define cell contents, and set long press action
|
// define cell contents, and set long press action
|
||||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue