SwiftFormat / SwiftLint basics
Set up SwiftFormat to auto-format code and SwiftLint to flag style issues. Run locally and in CI with simple, beginner-friendly rules.
SwiftFormat / SwiftLint basics is a free Swift Academy lesson on CoddyKit. This is lesson 1 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 3 lessons in total.
Why format & lint?
Goal: Keep code consistent and readable.
- SwiftFormat → auto-format source
- SwiftLint → flag style issues
- Run locally and in CI for steady quality
SwiftFormat: getting started
SwiftFormat rewrites files to a uniform style. Keep a .swiftformat in the repo and run it before commits.
// Install & run (examples):
// mint install nicklockwood/SwiftFormat // via Mint
// swiftformat . // format repo
// swiftformat Sources --config .swiftformat // use config file
//
// Minimal .swiftformat (put in repo root):
// --ifdef no
// --wrapcollections before-first
// --maxwidth 100
print("SwiftFormat: run to auto-format code consistently")SwiftLint: basics
SwiftLint analyzes files and reports violations. Configure rules in .swiftlint.yml; keep limits beginner-friendly.
// Install & run (examples):
// brew install swiftlint // macOS example
// swiftlint lint // check whole repo
// swiftlint lint --strict // fail on warnings in CI
//
// Minimal .swiftlint.yml (example):
// disabled_rules:
// - trailing_whitespace
// opt_in_rules:
// - empty_count
// line_length: 100
// identifier_name:
// min_length: 3
print("SwiftLint: report style issues with configurable rules")From violation to clean code
Formatting fixes spacing and line breaks; lint rules nudge names and usage. Keep examples tiny so beginners see the difference.
// BEFORE (bad spacing, short name, unused let)
//let x=1
//print( "Hi" )
//
// AFTER (formatted & lint-friendly):
let count = 1
print("Hi")
print("count =", count)Automation workflow
Automate both tools: run locally before committing; in CI use --strict to block regressions.
// Simple pre-commit idea (document in README):
// swiftformat . && swiftlint lint --strict
//
// GitHub Actions (sketch) — put in CI config, not here:
// - run: swiftformat --version && swiftformat .
// - run: swiftlint lint --strict
//
// Tip: start lenient (warnings), then turn strict in CI once the repo is clean.
print("Automate: run format+lint locally and in CI")Good starting rules
Beginner-friendly defaults:
- line_length: 100
- identifier_name.min_length: 3
- allow simple trailing commas
- disable a few noisy rules early (enable later)
Formatter vs linter
Quick check: Which tool auto-formats code?
Recap
Recap: Use SwiftFormat to write clean, consistent source and SwiftLint to enforce style rules. Keep configs simple, run locally, and gate CI with --strict.
Learn Swift with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 122
- Lessons
- 409
Frequently Asked Questions
Is the “SwiftFormat / SwiftLint basics” lesson free?
Yes — any 3 lessons of the Swift Academy learning path, including “SwiftFormat / SwiftLint basics”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 3 lessons in total.
What will I learn in “SwiftFormat / SwiftLint basics”?
Set up SwiftFormat to auto-format code and SwiftLint to flag style issues. Run locally and in CI with simple, beginner-friendly rules. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
How long does the “SwiftFormat / SwiftLint basics” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- SwiftFormat / SwiftLint basics
- Style guide, API design guidelines
- Documenting code (DocC intro)