Skip to content

Commit 06adfb2

Browse files
authored
Refactor FXIOS-7301 - Remove 1 closure_body_length violation from LegacyBookmarkDetailPanel.swift, and decrease threshold (#25542)
* Decrease warning and error threshold * Extract addFolderAndDescendants logic to a new function * Use the new function to add folder and descendants * Remove the inner function
1 parent 2de11f4 commit 06adfb2

File tree

2 files changed

+57
-46
lines changed

2 files changed

+57
-46
lines changed

.swiftlint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ line_length:
103103
ignores_interpolated_strings: true
104104

105105
closure_body_length:
106-
warning: 49
107-
error: 49
106+
warning: 45
107+
error: 45
108108

109109
file_header:
110110
required_string: |

firefox-ios/Client/Frontend/Library/Bookmarks/Legacy/LegacyBookmarkDetailPanel.swift

+55-44
Original file line numberDiff line numberDiff line change
@@ -272,57 +272,68 @@ class LegacyBookmarkDetailPanel: SiteTableViewController, BookmarksRefactorFeatu
272272

273273
var bookmarkFolders: [(folder: BookmarkFolderData, indent: Int)] = []
274274

275-
func addFolderAndDescendants(_ folder: BookmarkFolderData, indent: Int = 0) {
276-
// Do not append itself and the top "root" folder to this list as
277-
// bookmarks cannot be stored directly within it.
278-
if folder.guid != BookmarkRoots.RootGUID && folder.guid != self.bookmarkNodeGUID {
279-
bookmarkFolders.append((folder, indent))
280-
}
281-
282-
var folderChildren: [BookmarkNodeData]?
283-
// Suitable to be appended
284-
if folder.guid != self.bookmarkNodeGUID {
285-
folderChildren = folder.children
286-
}
287-
288-
func addFolder(childFolder: BookmarkFolderData) {
289-
// Any "root" folders (i.e. "Mobile Bookmarks") should
290-
// have an indentation of 0.
291-
if childFolder.isRoot {
292-
addFolderAndDescendants(childFolder)
293-
}
294-
// Otherwise, all non-root folder should increase the
295-
// indentation by 1.
296-
else {
297-
addFolderAndDescendants(childFolder, indent: indent + 1)
298-
}
299-
}
300-
301-
for case let childFolder as BookmarkFolderData in folderChildren ?? [] {
302-
// Only append desktop folders if they already contain bookmarks
303-
if !BookmarkRoots.DesktopRoots.contains(childFolder.guid) {
304-
addFolder(childFolder: childFolder)
305-
} else {
306-
switch bookmarksCountResult {
307-
case .success(let bookmarkCount):
308-
if (bookmarkCount > 0 && BookmarkRoots.DesktopRoots.contains(childFolder.guid))
309-
|| !self.isBookmarkRefactorEnabled {
310-
addFolder(childFolder: childFolder)
311-
}
312-
case .failure(let error):
313-
self.logger.log("Error counting bookmarks: \(error)", level: .debug, category: .library)
314-
}
315-
}
316-
}
317-
}
318-
addFolderAndDescendants(rootFolder)
275+
self.addFolderAndDescendants(rootFolder,
276+
bookmarkFolders: &bookmarkFolders,
277+
bookmarksCountResult: bookmarksCountResult)
319278
self.bookmarkFolders = bookmarkFolders
320279
self.tableView.reloadData()
321280
}
322281
}
323282
}
324283
}
325284

285+
private func addFolderAndDescendants(_ folder: BookmarkFolderData,
286+
bookmarkFolders: inout [(folder: BookmarkFolderData, indent: Int)],
287+
bookmarksCountResult: Result<Int, any Error>,
288+
indent: Int = 0) {
289+
// Do not append itself and the top "root" folder to this list as
290+
// bookmarks cannot be stored directly within it.
291+
if folder.guid != BookmarkRoots.RootGUID && folder.guid != self.bookmarkNodeGUID {
292+
bookmarkFolders.append((folder, indent))
293+
}
294+
295+
var folderChildren: [BookmarkNodeData]?
296+
// Suitable to be appended
297+
if folder.guid != self.bookmarkNodeGUID {
298+
folderChildren = folder.children
299+
}
300+
301+
func addFolder(childFolder: BookmarkFolderData) {
302+
// Any "root" folders (i.e. "Mobile Bookmarks") should
303+
// have an indentation of 0.
304+
if childFolder.isRoot {
305+
addFolderAndDescendants(childFolder,
306+
bookmarkFolders: &bookmarkFolders,
307+
bookmarksCountResult: bookmarksCountResult)
308+
}
309+
// Otherwise, all non-root folder should increase the
310+
// indentation by 1.
311+
else {
312+
addFolderAndDescendants(childFolder,
313+
bookmarkFolders: &bookmarkFolders,
314+
bookmarksCountResult: bookmarksCountResult,
315+
indent: indent + 1)
316+
}
317+
}
318+
319+
for case let childFolder as BookmarkFolderData in folderChildren ?? [] {
320+
// Only append desktop folders if they already contain bookmarks
321+
if !BookmarkRoots.DesktopRoots.contains(childFolder.guid) {
322+
addFolder(childFolder: childFolder)
323+
} else {
324+
switch bookmarksCountResult {
325+
case .success(let bookmarkCount):
326+
if (bookmarkCount > 0 && BookmarkRoots.DesktopRoots.contains(childFolder.guid))
327+
|| !self.isBookmarkRefactorEnabled {
328+
addFolder(childFolder: childFolder)
329+
}
330+
case .failure(let error):
331+
logger.log("Error counting bookmarks: \(error)", level: .debug, category: .library)
332+
}
333+
}
334+
}
335+
}
336+
326337
func updateSaveButton() {
327338
guard bookmarkNodeType == .bookmark else { return }
328339

0 commit comments

Comments
 (0)