code-size

Enforce SwiftLint complexity and size thresholds on Swift code using a violations baseline.

696|66|Updated Oct 29, 2025
One-click install
npx skills add https://github.com/rshankras/claude-code-apple-skills --skill code-size
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-size
Source: https://github.com/rshankras/claude-code-apple-skills/tree/main/skills/swift/code-size
Command: npx skills add https://github.com/rshankras/claude-code-apple-skills --skill code-size

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Agent-written Swift code grows long and branchy quickly, and hand-reviewing every function for length or complexity does not scale. This Skill sets deterministic SwiftLint thresholds for cyclomatic complexity, function/type/file length, and parameter count, and adopts them via a violations baseline so existing code never blocks the gate.

Core Features & Use Cases

  • Threshold Configuration: Provides a ready-to-merge .swiftlint.yml fragment setting warning/error limits for five built-in rules: cyclomatic_complexity (10/20), function_body_length (50/100), type_body_length (300/500), file_length (500/1000), and function_parameter_count (5/8).
  • Brownfield Baseline Adoption: Freezes existing violations with swiftlint lint --write-baseline and gates only new violations via --strict --baseline, avoiding mass-refactoring of working code.
  • Structural Fix Guidance: Maps each fired rule to a structural remedy (extract functions, split types by responsibility, introduce parameter structs) instead of inline swiftlint:disable suppressions.
  • Use Case: A team whose AI agents generate most of the Swift code merges the fragment into .swiftlint.yml, records a baseline, and adds the strict baseline check to CI so no new over-complex function can merge.

Quick Start

Ask the AI to merge the code-size SwiftLint fragment into the project's .swiftlint.yml, generate a violations baseline, and add a strict baseline lint gate to CI.

Frequently Asked Questions about code-size

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce cyclomatic complexity limits in Swift with SwiftLint?

Set thresholds for the built-in cyclomatic_complexity rule in .swiftlint.yml, such as warning at 10 and error at 20 independent paths per function. Run swiftlint lint --strict in CI so violations fail the build.

How to adopt SwiftLint rules in an existing codebase without mass refactoring?

Record existing violations once with swiftlint lint --write-baseline .swiftlint-baseline.json, then gate with swiftlint lint --strict --baseline so only new violations fail. Fix baselined violations opportunistically when touching that code and regenerate the baseline in the same commit.

What SwiftLint rules limit function and file length?

Five built-in rules cover size: cyclomatic_complexity, function_body_length, type_body_length, file_length, and function_parameter_count. All are enabled by default; you only need to set warning and error thresholds in .swiftlint.yml.

Does SwiftLint baseline work with older SwiftLint versions?

Baseline support requires SwiftLint 0.55 or later. For older versions, record the violation count with swiftlint lint --quiet | wc -l and gate on the current count not exceeding the committed count.

When should I use swiftlint:disable comments?

Inline swiftlint:disable is not a fix and should be avoided because exemptions become scattered and invisible. Rare legitimate exemptions, like generated files, belong in the excluded list in .swiftlint.yml with a comment explaining why.