Skip to content

Commit

Permalink
Fix lint 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
chicio committed Oct 12, 2024
1 parent 3e63627 commit 75d0cc8
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
excluded:
- Demo/Demo Ubuntu/.build
- .build
- build

type_name:
min_length: 4
Expand Down
21 changes: 12 additions & 9 deletions Demo/Demo watchOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import SwiftUI
import ID3TagEditor

struct ContentView: View {
@State private var tag: ID3Tag? = nil
@State private var tag: ID3Tag?

var body: some View {
VStack {
if let validTag = tag {
Image(uiImage: UIImage(data: (validTag.frames[.attachedPicture(.frontCover)] as! ID3FrameAttachedPicture).picture)!)
.resizable()
.frame(width: 50, height: 50)
Text((validTag.frames[.title] as! ID3FrameWithStringContent).content)
Text((validTag.frames[.album] as! ID3FrameWithStringContent).content)
Text((validTag.frames[.genre] as! ID3FrameGenre).description!)
if let data = (validTag.frames[.attachedPicture(.frontCover)] as? ID3FrameAttachedPicture)?.picture,
let validImage = UIImage(data: data) {
Image(uiImage: validImage)
.resizable()
.frame(width: 50, height: 50)
}
Text((validTag.frames[.title] as? ID3FrameWithStringContent)?.content ?? "")
Text((validTag.frames[.album] as? ID3FrameWithStringContent)?.content ?? "")
Text((validTag.frames[.genre] as? ID3FrameGenre)?.description ?? "")
}
}
.padding()
.onAppear {
let id3TagEditor = ID3TagEditor()
tag = try! id3TagEditor.read(from: PathLoader().pathFor(name: "example", fileType: "mp3"))
tag = try? id3TagEditor.read(from: PathLoader().pathFor(name: "example", fileType: "mp3"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// Demo_watchOSApp.swift
// DemoWatchOSApp.swift
// Demo watchOS Watch App
//
// Created by Fabrizio Duroni on 11.10.2024.
// Copyright © 2024 Fabrizio Duroni. All rights reserved.
// 2024 Fabrizio Duroni.
//

import SwiftUI

@main
struct Demo_watchOS_Watch_AppApp: App {
struct DemoWatchOSApp: App {
var body: some Scene {
WindowGroup {
ContentView()
Expand Down
2 changes: 1 addition & 1 deletion Scripts/swiftlint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fi

# Type a script or drag a script file from your workspace to insert its path.
if which swiftlint >/dev/null; then
swiftlint
swiftlint lint --config .swiftlint.yml
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
2 changes: 2 additions & 0 deletions Source/Create/ID3FrameCreatorsFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ class ID3FrameCreatorsFactory {
+ ID3iTunesFrameCreatorsFactory.make()
}
}

// swiftlint:enable line_length
2 changes: 2 additions & 0 deletions Source/Create/ID3RecordingTimesFrameCreatorsFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ class ID3RecordingTimesFrameCreatorsFactory {
]
}
}

// swiftlint:enable line_length
2 changes: 2 additions & 0 deletions Source/Create/ID3iTunesFrameCreatorsFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ class ID3iTunesFrameCreatorsFactory {
]
}
}

// swiftlint:enable line_length
2 changes: 1 addition & 1 deletion Source/Frame/FrameName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct FrameNamesWithLocalizedContent {
FrameType.comment: enumerateLocalizedFrameName(frameName: FrameName.comment)
]
}

private func enumerateLocalizedFrameName(frameName: (ID3FrameContentLanguage) -> FrameName) -> [FrameName] {
return ID3FrameContentLanguage.allCases.map({ frameName($0) })
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Frame/ID3FrameContentLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,6 @@ public enum ID3FrameContentLanguage: String, Equatable, Hashable, CaseIterable {
/// Invalid/Unknown language.
case unknown
}

// swiftlint:enable type_body_length
// swiftlint:enable file_length
2 changes: 2 additions & 0 deletions Source/Parse/ID3FrameContentParsingOperationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ class ID3FrameContentParsingOperationFactory {
]
}
}

// swiftlint:enable line_length
6 changes: 3 additions & 3 deletions Source/Parse/ID3FrameStringContentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ID3FrameStringContentParser {

let frameContent = frame.subdata(in: frameContentRangeStart..<frame.count)
let encoding = stringEncodingDetector.detect(frame: frame, version: version)

if let frameContentAsString = String(data: frameContent, encoding: encoding) {
return paddingRemover.removeFrom(string: frameContentAsString)
} else {
Expand All @@ -39,10 +39,10 @@ class ID3FrameStringContentParser {
Given the compatibility between iso latin 1 and utf-8 (the latter is a unicode super set of the first one)
we try as last resot to convert to utf-8 and get the result. If it fails, return nil.
*/
if let fallbackUtf8Content = String(data: frameContent, encoding: .utf8) {
if let fallbackUtf8Content = String(data: frameContent, encoding: .utf8) {
return paddingRemover.removeFrom(string: fallbackUtf8Content)
}

return nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Tag/ID3TagToStringAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

// swiftlint:disable line_length
// swiftlint:disable function_body_length

import Foundation

Expand Down Expand Up @@ -75,3 +74,5 @@ class ID3TagToStringAdapter {
})
}
}

// swiftlint:enable line_length
56 changes: 30 additions & 26 deletions Tests/Acceptance/ID3TagEditorAcceptanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ID3TagEditorAcceptanceTest {
let path = PathLoader().pathFor(name: "example-cover-png", fileType: "png")
let cover = try Data(contentsOf: URL(fileURLWithPath: path))
let id3Tag = try id3TagEditor.read(from: PathLoader().pathFor(name: "example-v23", fileType: "mp3"))

#expect(id3Tag?.properties.version == .version3)
#expect((id3Tag?.frames[.title] as? ID3FrameWithStringContent)?.content == "A title")
#expect((id3Tag?.frames[.album] as? ID3FrameWithStringContent)?.content == "An album")
Expand Down Expand Up @@ -182,7 +182,7 @@ struct ID3TagEditorAcceptanceTest {
let mp3 = try Data(
contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-v3-corrupted", fileType: "mp3"))
)

#expect(throws: ID3TagEditorError.corruptedFile.self) {
try id3TagEditor.read(mp3: mp3)
}
Expand Down Expand Up @@ -373,8 +373,8 @@ struct ID3TagEditorAcceptanceTest {
)
}
#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -405,8 +405,8 @@ struct ID3TagEditorAcceptanceTest {
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -435,10 +435,10 @@ struct ID3TagEditorAcceptanceTest {
andSaveTo: pathMp3Generated
)
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -555,10 +555,10 @@ struct ID3TagEditorAcceptanceTest {
andSaveTo: NSHomeDirectory() + "/example-v3-additional-data.mp3"
)
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -597,7 +597,7 @@ struct ID3TagEditorAcceptanceTest {

#expect(
newMp3 ==
(try! Data(contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-v3-additional-data",
(try? Data(contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-v3-additional-data",
fileType: "mp3"))))
)
}
Expand Down Expand Up @@ -625,8 +625,8 @@ struct ID3TagEditorAcceptanceTest {
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -657,8 +657,8 @@ struct ID3TagEditorAcceptanceTest {
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand All @@ -682,7 +682,7 @@ struct ID3TagEditorAcceptanceTest {
.subtitle: ID3FrameWithStringContent(content: "Subtitle V2")
]
)

#expect(throws: Never.self) {
try id3TagEditor.write(
tag: id3Tag,
Expand All @@ -692,8 +692,8 @@ struct ID3TagEditorAcceptanceTest {
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -735,8 +735,8 @@ struct ID3TagEditorAcceptanceTest {
)
}
#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand Down Expand Up @@ -779,8 +779,8 @@ struct ID3TagEditorAcceptanceTest {
}

#expect(
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try! Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3Generated))) ==
(try? Data(contentsOf: URL(fileURLWithPath: pathMp3ToCompare)))
)
}

Expand All @@ -801,12 +801,11 @@ struct ID3TagEditorAcceptanceTest {
#expect(throws: Never.self) {
try id3TagEditor.write(
tag: id3Tag,
to: PathLoader().pathFor(name: "frames-after-attached-picture",fileType: "mp3"),
to: PathLoader().pathFor(name: "frames-after-attached-picture", fileType: "mp3"),
andSaveTo: pathMp3Generated
)
}


let tag = try id3TagEditor.read(from: pathMp3Generated)
#expect((tag?.frames[.discPosition] as? ID3FramePartOfTotal)?.part == 1)
#expect((tag?.frames[.discPosition] as? ID3FramePartOfTotal)?.total == 3)
Expand Down Expand Up @@ -924,3 +923,8 @@ struct ID3TagEditorAcceptanceTest {
("testCommentWithUTF8EncodingAndNoContentDescription", testCommentWithUTF8EncodingAndNoContentDescription)
]
}

// swiftlint:enable type_body_length
// swiftlint:enable function_body_length
// swiftlint:enable line_length
// swiftlint:enable file_length
5 changes: 5 additions & 0 deletions Tests/Acceptance/ID3TagEditorWriteReadAcceptanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,8 @@ struct ID3TagEditorWriteReadAcceptanceTest {
("testReadWritev4", testReadWritev4)
]
}

// swiftlint:enable type_body_length
// swiftlint:enable function_body_length
// swiftlint:enable line_length
// swiftlint:enable file_length
2 changes: 1 addition & 1 deletion Tests/Create/ID3FrameHeaderCreatorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct ID3FrameHeaderCreatorTest {

#expect(header == [UInt8]("USLT".utf8) + [0x11, 0x00])
}

static let allTests = [
("create", create)
]
Expand Down
4 changes: 2 additions & 2 deletions Tests/Create/ID3TagCreatorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ struct ID3TagCreatorTest {
}
}

@Test func testGenerateValidData() {
@Test func testGenerateValidData() throws {
let id3FrameCreators = [MockID3FrameCreatorsChain(frames: [0x22, 0x33])]
let id3FramesCreator = ID3FramesCreator(id3FrameCreators: id3FrameCreators)
let id3TagHeaderCreator = ID3TagHeaderCreator(uInt32ToByteArrayAdapter: MockUInt32ToByteArrayAdapter(),
id3TagConfiguration: ID3TagConfiguration())
let id3TagCreator = ID3TagCreator(id3FramesCreator: id3FramesCreator, id3TagHeaderCreator: id3TagHeaderCreator)

#expect(
try! id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()) ==
try id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()) ==
Data(ID3TagConfiguration().headerFor(version: .version3)
+ [0x0, 0x3, 0x2, 0x22, 0x33] + [UInt8](repeating: 0x0, count: 2048)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ID3AttachedPictureFrameContentParsingOperationTest {
id3FrameConfiguration: ID3FrameConfiguration(),
pictureTypeAdapter: MockPictureTypeAdapter()
)

await confirmation("attached picture") { parsed in
attachedPictureFrameContentParsingOperation.parse(
frame: Data([0x89, 0x50, 0x4E, 0x47, 0x11, 0x11]),
Expand Down
8 changes: 6 additions & 2 deletions Tests/Parse/ID3LocalizedFrameParsingOperationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import Testing

struct ID3LocalizedFrameParsingOperationTest {
@Test func testParsingValidFrame() async {
let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(frameName: FrameName.unsynchronizedLyrics)
let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(
frameName: FrameName.unsynchronizedLyrics
)

await confirmation("unsynchronised lyrics") { fulfill in
lyricsOperation.parse(frame: frameV3Valid(), version: .version3) { (_, frame) in
Expand All @@ -26,7 +28,9 @@ struct ID3LocalizedFrameParsingOperationTest {
}

@Test func testParsingInvalidLanguage() async {
let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(frameName: FrameName.unsynchronizedLyrics)
let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(
frameName: FrameName.unsynchronizedLyrics
)

await confirmation("unsynchronised lyrics") { fulfill in
lyricsOperation.parse(frame: frameV3InvalidLanguage(), version: .version3) { (_, frame) in
Expand Down
Loading

0 comments on commit 75d0cc8

Please sign in to comment.