From ca6110787ec7d2d6b790ef41eb2a71b15d823329 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:16:25 -0300 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=A4=96=20Add=20swiftlint=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/swiftlint.yml | 16 ++++++++++++++++ .swiftlint.yml | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/swiftlint.yml diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.yml new file mode 100644 index 0000000..df8e5d0 --- /dev/null +++ b/.github/workflows/swiftlint.yml @@ -0,0 +1,16 @@ +name: SwiftLint + +on: + pull_request: + paths: + - '.github/workflows/swiftlint.yml' + - '.swiftlint.yml' + - '**/*.swift' + +jobs: + SwiftLint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: GitHub Action for SwiftLint + uses: norio-nomura/action-swiftlint@3.2.1 diff --git a/.swiftlint.yml b/.swiftlint.yml index 3dfa380..2a1c64e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -83,9 +83,9 @@ opt_in_rules: # some rules are only opt-in - sorted_imports - switch_case_on_newline included: # paths to include during linting. `--path` is ignored if present. - - NadaADeclarar + - Sources excluded: # paths to ignore during linting. Takes precedence over `included`. - - NadaADeclararTests + - Sources/NadaADeclararTests # configurable rules can be customized from this configuration file # binary rules can set their severity level From b6104f305e4781d0a7a86d5e7d19ab0165e29151 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:24:24 -0300 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20implicit=5Freturn=20wa?= =?UTF-8?q?rnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/NadaADeclarar/CNPJ.swift | 4 ++-- Sources/NadaADeclarar/CPF.swift | 9 +++++---- Sources/NadaADeclarar/FiscalRegions.swift | 10 ++++------ Sources/NadaADeclarar/Parser.swift | 10 +++++----- Sources/NadaADeclarar/Protocols.swift | 8 ++++---- Tests/NadaADeclararTests/CPFTests.swift | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Sources/NadaADeclarar/CNPJ.swift b/Sources/NadaADeclarar/CNPJ.swift index da96fc7..c1262f2 100644 --- a/Sources/NadaADeclarar/CNPJ.swift +++ b/Sources/NadaADeclarar/CNPJ.swift @@ -46,7 +46,7 @@ public struct CNPJ: NadaADeclararNumberProtocol, Generatable, NumberParsedInfoIn - Returns: `true` if the CNPJ represents a headquarters; otherwise, `false`. */ public var isHeadquarters: Bool { - return branchNumber == "0001" + branchNumber == "0001" } /** @@ -55,7 +55,7 @@ public struct CNPJ: NadaADeclararNumberProtocol, Generatable, NumberParsedInfoIn - Returns: A string representing the branch number. */ public var branchNumber: String { - return numberParsedInfo.parts.dropLast().last! // swiftlint:disable:this force_unwrapping + numberParsedInfo.parts.dropLast().last! // swiftlint:disable:this force_unwrapping } /** diff --git a/Sources/NadaADeclarar/CPF.swift b/Sources/NadaADeclarar/CPF.swift index 9a90963..00d6591 100644 --- a/Sources/NadaADeclarar/CPF.swift +++ b/Sources/NadaADeclarar/CPF.swift @@ -102,9 +102,10 @@ public struct CPF: NadaADeclararNumberProtocol, Generatable, NumberParsedInfoInt - allSameDigitsAreValid: A flag indicating whether a CPF with all same digits is valid. Defaults to `false`. - Returns: `true` if the CPF is valid, `false` otherwise. */ - func isValid(validationAlgorythm: Validator.ValidationAlgorythm = .simple, - allSameDigitsAreValid: Bool = false) -> Bool { - return validator.isValid(validationAlgorythm: validationAlgorythm, - allSameDigitsAreValid: allSameDigitsAreValid) + func isValid( + validationAlgorythm: Validator.ValidationAlgorythm = .simple, + allSameDigitsAreValid: Bool = false + ) -> Bool { + validator.isValid(validationAlgorythm: validationAlgorythm, allSameDigitsAreValid: allSameDigitsAreValid) } } diff --git a/Sources/NadaADeclarar/FiscalRegions.swift b/Sources/NadaADeclarar/FiscalRegions.swift index 648b3cf..5be67ad 100644 --- a/Sources/NadaADeclarar/FiscalRegions.swift +++ b/Sources/NadaADeclarar/FiscalRegions.swift @@ -30,17 +30,15 @@ extension State: Hashable { } public static func == (lhs: State, rhs: State) -> Bool { - return ( - lhs.initials == rhs.initials && - lhs.name == rhs.name && - lhs.fiscalRegion == rhs.fiscalRegion - ) + lhs.initials == rhs.initials && + lhs.name == rhs.name && + lhs.fiscalRegion == rhs.fiscalRegion } } extension State: CustomStringConvertible { public var description: String { - return "State: \(name) (\(initials)) Fiscal Region: \(fiscalRegion)" + "State: \(name) (\(initials)) Fiscal Region: \(fiscalRegion)" } } diff --git a/Sources/NadaADeclarar/Parser.swift b/Sources/NadaADeclarar/Parser.swift index 5c6c15e..836bbff 100644 --- a/Sources/NadaADeclarar/Parser.swift +++ b/Sources/NadaADeclarar/Parser.swift @@ -182,15 +182,15 @@ extension Parser.Info: Hashable { hasher.combine(plainNumber) hasher.combine(maskedNumber) let checkDigitsHashValue = checkDigits.reduce(5_381) { - return ($0 << 5) &+ $0 &+ Int($1) + ($0 << 5) &+ $0 &+ Int($1) } hasher.combine(checkDigitsHashValue) } static func == (lhs: Parser.Info, rhs: Parser.Info) -> Bool { - return (lhs.plainNumber == rhs.plainNumber && - lhs.maskedNumber == rhs.maskedNumber && - lhs.checkDigits == rhs.checkDigits && - lhs.parts == rhs.parts) + lhs.plainNumber == rhs.plainNumber && + lhs.maskedNumber == rhs.maskedNumber && + lhs.checkDigits == rhs.checkDigits && + lhs.parts == rhs.parts } } diff --git a/Sources/NadaADeclarar/Protocols.swift b/Sources/NadaADeclarar/Protocols.swift index 0871a30..aa81333 100644 --- a/Sources/NadaADeclarar/Protocols.swift +++ b/Sources/NadaADeclarar/Protocols.swift @@ -14,15 +14,15 @@ protocol NumberParsedInfoInterface: Hashable { extension NumberParsedInfoInterface { public var plainNumber: String { - return numberParsedInfo.plainNumber + numberParsedInfo.plainNumber } public var maskedNumber: String { - return numberParsedInfo.maskedNumber + numberParsedInfo.maskedNumber } public var checkDigits: [Int] { - return numberParsedInfo.checkDigits + numberParsedInfo.checkDigits } public func hash(into hasher: inout Hasher) { @@ -30,6 +30,6 @@ extension NumberParsedInfoInterface { } public static func == (lhs: Self, rhs: Self) -> Bool { - return lhs.numberParsedInfo == rhs.numberParsedInfo + lhs.numberParsedInfo == rhs.numberParsedInfo } } diff --git a/Tests/NadaADeclararTests/CPFTests.swift b/Tests/NadaADeclararTests/CPFTests.swift index de705d6..dd1b4f3 100644 --- a/Tests/NadaADeclararTests/CPFTests.swift +++ b/Tests/NadaADeclararTests/CPFTests.swift @@ -4,7 +4,7 @@ import XCTest class CPFTests: XCTestCase, ListImporter { lazy var cpfGroup: Set! = { - return CPFTests.generatedNumberList() + CPFTests.generatedNumberList() }() func testCPFSet() { From e3af5295374dd4a29b66474089e405e8ee826769 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:37:42 -0300 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=9A=A8=20Disable=20explicit=5Ftype=5F?= =?UTF-8?q?interface=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftlint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 2a1c64e..3c6f201 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -64,7 +64,7 @@ opt_in_rules: # some rules are only opt-in - conditional_returns_on_newline - empty_count - explicit_init - - explicit_type_interface + # - explicit_type_interface - fatal_error_message - file_header - first_where @@ -95,7 +95,6 @@ closure_spacing: error conditional_returns_on_newline: error empty_count: error explicit_init: error -explicit_type_interface: error force_cast: error attributes: From aa7fc80efbf49d23ee4d27a1d28cf75ef865ad04 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:38:51 -0300 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9E=95=20Add=20SwiftLint=20plugin=20depe?= =?UTF-8?q?ndency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Package.resolved | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ Package.swift | 10 ++++-- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..71e9d5e --- /dev/null +++ b/Package.resolved @@ -0,0 +1,86 @@ +{ + "pins" : [ + { + "identity" : "collectionconcurrencykit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git", + "state" : { + "revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95", + "version" : "0.2.0" + } + }, + { + "identity" : "cryptoswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "state" : { + "revision" : "c9c3df6ab812de32bae61fc0cd1bf6d45170ebf0", + "version" : "1.8.2" + } + }, + { + "identity" : "sourcekitten", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/SourceKitten.git", + "state" : { + "revision" : "fd4df99170f5e9d7cf9aa8312aa8506e0e7a44e7", + "version" : "0.35.0" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", + "version" : "1.4.0" + } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "303e5c5c36d6a558407d364878df131c3546fad8", + "version" : "510.0.2" + } + }, + { + "identity" : "swiftlint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/realm/SwiftLint.git", + "state" : { + "revision" : "b515723b16eba33f15c4677ee65f3fef2ce8c255", + "version" : "0.55.1" + } + }, + { + "identity" : "swiftytexttable", + "kind" : "remoteSourceControl", + "location" : "https://github.com/scottrhoyt/SwiftyTextTable.git", + "state" : { + "revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", + "version" : "0.9.0" + } + }, + { + "identity" : "swxmlhash", + "kind" : "remoteSourceControl", + "location" : "https://github.com/drmohundro/SWXMLHash.git", + "state" : { + "revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", + "version" : "7.0.2" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76", + "version" : "5.1.2" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift index 06c3cc0..2587363 100644 --- a/Package.swift +++ b/Package.swift @@ -11,14 +11,20 @@ let package = Package( name: "NadaADeclarar", targets: ["NadaADeclarar"]), ], + dependencies: [ + .package(url: "https://github.com/realm/SwiftLint.git", from: .init(0, 55, 0)) + ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .target( - name: "NadaADeclarar"), + name: "NadaADeclarar", + plugins: [ + .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint") + ]), .testTarget( name: "NadaADeclararTests", dependencies: ["NadaADeclarar"], - resources: [.process("Resources")]) + resources: [.process("Resources")]), ] ) From 7b8631030c4023ae0dbef239a8a241f7f1692d46 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:40:41 -0300 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20identifier=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Identifier Name Violation: Variable name 'i' should be between 3 and 40 characters long (identifier_name) --- Sources/NadaADeclarar/Parser.swift | 6 +++--- Sources/NadaADeclarar/Validator.swift | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/NadaADeclarar/Parser.swift b/Sources/NadaADeclarar/Parser.swift index 836bbff..e60f1fb 100644 --- a/Sources/NadaADeclarar/Parser.swift +++ b/Sources/NadaADeclarar/Parser.swift @@ -139,9 +139,9 @@ public struct Parser { } var offset = 0 - for i in 0..= 0 && v < 10, "verification number out of range 0 <= v <= 9") - nextBasicNumber.append(String(v)) - expectedCheckDigits.insert(v, at: i) + let verificationNumber = (remainder < 2) ? 0 : moduloNumber - remainder + assert(verificationNumber >= 0 && verificationNumber < 10, "verification number out of range 0 <= v <= 9") + nextBasicNumber.append(String(verificationNumber)) + expectedCheckDigits.insert(verificationNumber, at: index) } return expectedCheckDigits } From 2ce41c599433604a4646ed948cb664216bc5acdb Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:45:17 -0300 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20legacy=5Frandom=20warn?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Legacy Random Violation: Prefer using `type.random(in:)` over legacy functions (legacy_random) --- Sources/NadaADeclarar/Generator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/NadaADeclarar/Generator.swift b/Sources/NadaADeclarar/Generator.swift index 7a7bdd0..44509e1 100644 --- a/Sources/NadaADeclarar/Generator.swift +++ b/Sources/NadaADeclarar/Generator.swift @@ -42,7 +42,7 @@ extension Generatable { let basicNumberLength = NumberParsedType.numberLength - NumberParsedType.checkDigitsCount var randomNumber = "" for _ in 0 ..< basicNumberLength { - randomNumber += String(arc4random() % 10) + randomNumber += String(Int.random(in: 0...9)) } return randomNumber } From 6aa0e6ec5a51ba6bb609731c81ecba2959595d68 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 22:49:36 -0300 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=92=9A=20Fix=20swift=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/swift.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 5645dcd..4cdca98 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -12,7 +12,7 @@ on: jobs: build: - runs-on: macos-latest + runs-on: macos-12.0 steps: - uses: actions/checkout@v4 From 8fc9be5a0e3cd6952199968ca8415b727788368b Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Sun, 7 Jul 2024 23:12:32 -0300 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=92=9A=20Fix=20codeql=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codeql.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 63e3608..eb45a38 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -45,7 +45,7 @@ jobs: matrix: include: - language: swift - build-mode: autobuild + build-mode: manual # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' # Use `c-cpp` to analyze code written in C, C++ or both # Use 'java-kotlin' to analyze code written in Java, Kotlin or both @@ -79,13 +79,7 @@ jobs: # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - if: matrix.build-mode == 'manual' shell: bash - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 + run: swift build -v - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From 478157d6786d776d294c452f06583982ba289263 Mon Sep 17 00:00:00 2001 From: Lucien Doellinger Date: Mon, 8 Jul 2024 07:43:19 -0300 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A4=96=20Fix=20swift=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/swift.yml | 2 +- Package.swift | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 4cdca98..5645dcd 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -12,7 +12,7 @@ on: jobs: build: - runs-on: macos-12.0 + runs-on: macos-latest steps: - uses: actions/checkout@v4 diff --git a/Package.swift b/Package.swift index 2587363..8b96723 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,9 @@ import PackageDescription let package = Package( name: "NadaADeclarar", + platforms: [ + .macOS(.v12) // Update this line + ], products: [ // Products define the executables and libraries a package produces, making them visible to other packages. .library(