0Pricing
Swift Academy · Lesson

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 — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

Is the “SwiftFormat / SwiftLint basics” lesson free?

Yes — the full text of “SwiftFormat / SwiftLint basics” is free to read here on the web, and the Swift Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

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

  1. SwiftFormat / SwiftLint basics
  2. Style guide, API design guidelines
  3. Documenting code (DocC intro)
← Back to Swift Academy