Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint automation testing on existing files #4

Merged
merged 4 commits into from
Jan 1, 2025
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
11 changes: 4 additions & 7 deletions .github/workflows/swift-lint.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# .github/workflows/swiftlint.yml
name: Swift Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run SwiftLint
uses: norio-nomura/[email protected]
- uses: actions/checkout@v3
- name: Run SwiftLint
uses: norio-nomura/[email protected]
10 changes: 5 additions & 5 deletions DesignPatterns/Factory/factory-practice-2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
func attack()
func defend()

var HP: Int { get }

Check warning on line 7 in DesignPatterns/Factory/factory-practice-2.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HP' should be between 3 and 40 characters long (identifier_name)
var MP: Int { get }

Check warning on line 8 in DesignPatterns/Factory/factory-practice-2.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MP' should be between 3 and 40 characters long (identifier_name)
var weaponType: String { get }
var armorType: String { get }
}
Expand All @@ -30,11 +30,11 @@
print("Warrior is defending.")
}

var HP: Int {

Check warning on line 33 in DesignPatterns/Factory/factory-practice-2.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HP' should be between 3 and 40 characters long (identifier_name)
return 100
}

var MP: Int {

Check warning on line 37 in DesignPatterns/Factory/factory-practice-2.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MP' should be between 3 and 40 characters long (identifier_name)
return 57
}

Expand All @@ -47,13 +47,13 @@
}
}

class CharacterFactory {
class CharacterFactory {
static func createCharacter(character: CharacterType) throws -> Character {
switch character {
case .warrior:
return Warrior()
default:
throw CharacterError.invalidCharacterType
case .warrior:
return Warrior()
default:
throw CharacterError.invalidCharacterType
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions DesignPatterns/Factory/factory-practice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ protocol Document {
/// Opens the document from the specified file path
/// - Parameter filePath: The path to the document
func openDocument(filePath: String)

/// Saves the document
func saveDocument()

/// The file extension for this document type
var fileExtension: String { get }

/// The size of the document in kilobytes
var fileSizeKB: Int { get }
}
Expand All @@ -28,15 +28,15 @@ class PDF: Document {
print("PDF file has been opened")
print("Reading file..")
}
func saveDocument(){

func saveDocument() {
print("PDF document has been saved")
}

var fileExtension: String {
return ".pdf"
}

var fileSizeKB: Int {
return 32
}
Expand All @@ -47,15 +47,15 @@ class Word: Document {
print("Word document has been opened")
print("Reading file...")
}
func saveDocument(){

func saveDocument() {
print("Word document has been saved")
}

var fileExtension: String {
return ".word"
}

var fileSizeKB: Int {
return 64
}
Expand All @@ -66,15 +66,15 @@ class Text: Document {
print("Text document has been opened")
print("Reading file...")
}

func saveDocument() {
print("Text document has been saved")
}

var fileExtension: String {
return ".txt"
}

var fileSizeKB: Int {
return 16
}
Expand Down Expand Up @@ -103,19 +103,19 @@ class DocumentFactory {
// Processor
class DocumentProcessor {
private let document: Document

init(documentType: DocumentType) throws {
self.document = try DocumentFactory.createDocument(fileExtension: documentType)
}

func processDocument(filePath: String) throws {
guard !filePath.isEmpty else {
throw DocumentError.invalidFilePath
}

document.openDocument(filePath: filePath)
document.saveDocument()

print("Processing complete: ")
print("- Size: \(document.fileSizeKB)KB")
print("- Extension: \(document.fileExtension)")
Expand Down
8 changes: 4 additions & 4 deletions DesignPatterns/Factory/factory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CreditCard: PaymentMethod {
print("Processing credit card payment of $\(amount)")
print("Fee applied: $\(fee)")
}

var fee: Double {
return 2.5
}
Expand All @@ -21,7 +21,7 @@ class PayPal: PaymentMethod {
print("Processing PayPal payment of $\(amount)")
print("Fee applied: $\(fee)")
}

var fee: Double {
return 3.0
}
Expand All @@ -32,7 +32,7 @@ class BankTransfer: PaymentMethod {
print("Processing bank transfer of $\(amount)")
print("Fee applied: $\(fee)")
}

var fee: Double {
return 1.0
}
Expand All @@ -44,7 +44,7 @@ class ApplePay: PaymentMethod {
print("Processing Apple Pay payment of $\(amount)")
print("Fee applied: $\(fee)")
}

var fee: Double {
return 1.5
}
Expand Down
18 changes: 15 additions & 3 deletions Sources/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# .swiftlint.yml
included:
- Sources
excluded:
- Tests
- .build

disabled_rules:
- trailing_whitespace
- function_body_length
- type_body_length
- file_length
- identifier_name
- force_cast
- force_try
- cyclomatic_complexity
- nesting
- multiple_closures_with_trailing_closure
- todo
- type_name
line_length:
warning: 120
error: 200

opt_in_rules:
- empty_count
- missing_docs
- missing_docs
27 changes: 27 additions & 0 deletions test.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
struct UserAccount {
var userName: String
var userAge: Int
var isActive: Bool

func printUserDetails() {
print("\(userName) is \(userAge) years old")
if isActive == true {
print("Account is active")
} else {
print("Account is inactive")
}
}

func calculateDiscount() -> Double {
var discount: Double = 0.0
if userAge > 60 {
discount = 0.2
} else if userAge > 30 {
discount = 0.1
}
return discount
}
}

let newUser = UserAccount(userName: "john", userAge: 25, isActive: true)
newUser.printUserDetails()
Loading