Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Enable SwiftLint and fix issues #2292

Merged
merged 4 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
disabled_rules:
- function_parameter_count
- line_length
- identifier_name
- type_name
- function_body_length
- type_body_length
- force_try
- force_cast
- trailing_whitespace
- cyclomatic_complexity
- identifier_name
- type_name
- line_length
- file_length
- large_tuple
- nesting

included:
- Classes
- FreetimeTests
- Local\ Pods
excluded:
- Pods
- Local Pods
- Playgrounds
- Sample
- Local\ Pods/SwipeCellKit

reporter: "xcode"
6 changes: 3 additions & 3 deletions Classes/Bookmark/BookmarkCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class BookmarkCell: SwipeSelectableCell {

override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = .white

contentView.clipsToBounds = true
Expand Down Expand Up @@ -84,14 +84,14 @@ final class BookmarkCell: SwipeSelectableCell {
string: "\(viewModel.bookmark.owner)/\(viewModel.bookmark.name)",
attributes: [
.font: Styles.Text.secondaryBold.preferredFont,
.foregroundColor: Styles.Colors.Gray.light.color,
.foregroundColor: Styles.Colors.Gray.light.color
]
)
detailString.append(NSAttributedString(
string: " #\(viewModel.bookmark.number)",
attributes: [
.font: Styles.Text.secondary.preferredFont,
.foregroundColor: Styles.Colors.Gray.light.color,
.foregroundColor: Styles.Colors.Gray.light.color
]
))
detailLabel.attributedText = detailString
Expand Down
20 changes: 10 additions & 10 deletions Classes/Bookmark/BookmarkNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ final class BookmarkNavigationController {
}

// MARK: Public API

var navigationItem: UIBarButtonItem {
let item = UIBarButtonItem()
configureNavigationItem(item)
return item
}

func configureNavigationItem(_ item: UIBarButtonItem) {

let accessibilityLabel: String
let imageName: String
let selector: Selector

if store.contains(model) {
imageName = "nav-bookmark-selected"
accessibilityLabel = Constants.Strings.removeBookmark
Expand All @@ -45,7 +45,7 @@ final class BookmarkNavigationController {
accessibilityLabel = Constants.Strings.bookmark
selector = #selector(BookmarkNavigationController.add(sender:))
}

item.accessibilityLabel = accessibilityLabel
item.image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate)
item.target = self
Expand All @@ -54,7 +54,7 @@ final class BookmarkNavigationController {
item.width = 0
item.imageInsets = BookmarkNavigationController.iconImageInset
}

//for timeframe between viewDidLoad() and bookmark info is loaded
static var disabledNavigationItem: UIBarButtonItem {
let item = UIBarButtonItem()
Expand All @@ -63,20 +63,20 @@ final class BookmarkNavigationController {
item.imageInsets = BookmarkNavigationController.iconImageInset
return item
}

// MARK: Private API

@objc func add(sender: UIBarButtonItem) {
Haptic.triggerSelection()
sender.action = #selector(BookmarkNavigationController.remove(sender:))
sender.image = UIImage(named: "nav-bookmark-selected")?.withRenderingMode(.alwaysTemplate)
store.add(model)
}

@objc func remove(sender: UIBarButtonItem) {
sender.action = #selector(BookmarkNavigationController.add(sender:))
sender.image = UIImage(named: "nav-bookmark")?.withRenderingMode(.alwaysTemplate)
store.remove(model)
}

}
3 changes: 1 addition & 2 deletions Classes/Bookmark/BookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ TabNavRootViewControllerType {
collectionView.collectionViewLayout.invalidateForOrientationChange()
}
}

override func viewWillDisappear(_ animated: Bool) {
searchBar.resignFirstResponder()
}


private func update(animated: Bool) {
adapter.performUpdates(animated: animated)
}
Expand Down
15 changes: 7 additions & 8 deletions Classes/Image Upload/ImageUploadTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ class ImageUploadTableViewController: UITableViewController {

return viewController
}

override func viewDidLoad() {
super.viewDidLoad()

// Set the preview image
previewImageView.image = image


// Set the right button item to spinning until we have compression info
setRightBarItemSpinning()

Expand All @@ -76,7 +75,7 @@ class ImageUploadTableViewController: UITableViewController {
]
)
titleTextField.delegate = self

// Compress and encode the image in the background to speed up the upload process
image.compressAndEncode { [weak self] result in
switch result {
Expand Down Expand Up @@ -159,18 +158,18 @@ class ImageUploadTableViewController: UITableViewController {
client.canUploadImage { [weak self] error in
// Ensure that we do have enough tokens, otherwise remove the upload button
if let error = error as? ImgurClient.ImgurError {

switch error {
case .endpointError(let response):
Squawk.showError(message: response)

case .rateLimitExceeded:
Squawk.showError(message: NSLocalizedString("Rate Limit reached, cannot upload!", comment: ""))

default:
Squawk.showGenericError()
}

self?.navigationItem.rightBarButtonItem = nil
return
}
Expand Down Expand Up @@ -201,7 +200,7 @@ class ImageUploadTableViewController: UITableViewController {
}
}
}

@IBAction func didPressPreviewImage() {
let previewViewController = NYTPhotosViewController(photos: [IssueCommentPhoto(image: image, data: nil)])
present(previewViewController, animated: trueUnlessReduceMotionEnabled)
Expand Down
10 changes: 5 additions & 5 deletions Classes/Image Upload/ImgurClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ final class ImgurClient {
enum ImgurError: Error {
// missingLink: - Received a valid response, but no link was available in the payload
case missingLink

// endpointError: - We got an error back from Imgur, where the parameter is their response
case endpointError(String)

// malformedResponse: - We got a response back from Imgur, but it did not contain values we expected
case malformedResponse

// rateLimitExceeded: - We are too close to the Imgur rate limit, so no images are being permitted
case rateLimitExceeded
}
Expand Down Expand Up @@ -56,7 +56,7 @@ final class ImgurClient {
completion(ImgurError.malformedResponse)
return
}

if let error = data["error"] as? String {
completion(ImgurError.endpointError(error))
return
Expand All @@ -73,7 +73,7 @@ final class ImgurClient {
completion(ImgurError.rateLimitExceeded)
return
}

completion(nil)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Issues/AddCommentClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class AddCommentClient {
let mutation = AddCommentMutation(subject_id: subjectId, body: bodyWithSignature)
client.client.mutate(mutation, result: { data in
data.addComment?.commentEdge.node
}) { result in
}, completion: { result in
switch result {
case .success(let commentNode):
let fragments = commentNode.fragments
Expand All @@ -67,7 +67,7 @@ final class AddCommentClient {
}
Squawk.show(error: error)
}
}
})
}

}
2 changes: 1 addition & 1 deletion Classes/Issues/Assignees/IssueAssigneeAvatarCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class IssueAssigneeAvatarCell: UICollectionViewCell {
imageView.layer.borderWidth = 1.0 / UIScreen.main.scale
imageView.clipsToBounds = true
imageView.accessibilityIgnoresInvertColors = true

contentView.addSubview(imageView)
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Issues/Assignees/IssueAssigneeUserCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class IssueAssigneeUserCell: UICollectionViewCell, ListBindable {
imageView.layer.borderWidth = 1.0 / UIScreen.main.scale
imageView.clipsToBounds = true
imageView.accessibilityIgnoresInvertColors = true

contentView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
Expand Down
8 changes: 4 additions & 4 deletions Classes/Issues/Branches/IssueBranchesSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import UIKit
import IGListKit

final class IssueTargetBranchSectionController: ListSectionController {

var object: IssueTargetBranchModel?

override func didUpdate(to object: Any) {
guard let object = object as? IssueTargetBranchModel else { return }
self.object = object
}

override func sizeForItem(at index: Int) -> CGSize {
guard let width = collectionContext?.insetContainerSize.width else { fatalError("Collection context must be set") }
return CGSize(width: width, height: self.object?.targetBranchText.viewSize(in: width).height ?? 0)
}

override func cellForItem(at index: Int) -> UICollectionViewCell {
guard let object = self.object,
let cell = collectionContext?.dequeueReusableCell(of: IssueTargetBranchCell.self, for: self, at: index) as? IssueTargetBranchCell
Expand Down
5 changes: 2 additions & 3 deletions Classes/Issues/Branches/IssueTargetBranchCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import UIKit
import SnapKit

final class IssueTargetBranchCell: StyledTextViewCell {

static let inset = UIEdgeInsets.zero

}

}
11 changes: 5 additions & 6 deletions Classes/Issues/Branches/IssueTargetBranchModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import IGListKit
import StyledTextKit

final class IssueTargetBranchModel: ListDiffable {

let targetBranchText: StyledTextRenderer


init(branch: String, width: CGFloat) {
let builder = StyledTextBuilder(styledText: StyledText(
style: Styles.Text.secondary.with(foreground: Styles.Colors.Gray.medium.color)
Expand All @@ -29,19 +28,19 @@ final class IssueTargetBranchModel: ListDiffable {
style: Styles.Text.secondaryCode.with(foreground: Styles.Colors.Gray.dark.color)
))
.save()

self.targetBranchText = StyledTextRenderer(
string: builder.build(),
contentSizeCategory: .small
).warm(width: width)
}

// MARK: ListDiffable

func diffIdentifier() -> NSObjectProtocol {
return targetBranchText.diffIdentifier()
}

func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
if self === object { return true }
guard let object = object as? IssueTargetBranchModel else { return false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
imageView.configureForAvatar()
imageView.isUserInteractionEnabled = true
imageView.accessibilityIgnoresInvertColors = true

imageView.addGestureRecognizer(UITapGestureRecognizer(
target: self,
action: #selector(IssueCommentDetailCell.onTapAvatar))
Expand Down
2 changes: 1 addition & 1 deletion Classes/Issues/Comments/Images/IssueCommentImageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class IssueCommentImageCell: IssueCommentBaseCell, ListBindable {

imageView.contentMode = .scaleAspectFit
imageView.accessibilityIgnoresInvertColors = true

contentView.addSubview(imageView)

spinner.hidesWhenStopped = true
Expand Down
1 change: 0 additions & 1 deletion Classes/Issues/Comments/IssueCommentBaseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,3 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
}

}

Loading