Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计提醒

swiftlintswiftlint 命令行

Agent Skill

swiftlint 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,640

周安装

67

GitHub Stars

521

下载量

531
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:swiftlint(swiftlint 命令行)
来源仓库:https://github.com/dpearson2699/swift-ios-skills
仓库路径:skills/swiftlint
安装命令:
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swiftlint
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swiftlint

简介

swiftlint 强制执行 Swift 代码风格规范,通过可配置规则集提升团队协作一致性。

  • 适用于中大型 Swift 项目引入静态检查,减少低级错误与代码异味。
  • 支持规则选择、抑制标记、基线更新与 CI 集成,灵活适应不同编码偏好。
  • 需定期 review 规则变更,避免过度约束影响开发体验或引入误报干扰。
  • swiftlint 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

SwiftLint

SwiftLint enforces Swift style and conventions by linting source files against a configurable rule set. It is the most widely adopted Swift linter. This skill covers setup, configuration, rule selection, suppression, CI integration, and rollout strategy.

SwiftLint is a style enforcement tool, not a style guide. For underlying Swift naming and design conventions, see swift-api-design-guidelines. For architecture patterns, see swift-architecture.

Contents


Recommended Setup

Default: build tool plugin via SimplyDanny/SwiftLintPlugins.

Add the plugin package to Package.swift or via Xcode's package dependencies:

// Package.swift
dependencies: [
  .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "<reviewed-version>")
]

For SwiftPM targets, apply the plugin:

.target(
    name: "MyApp",
    plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")]
)

For Xcode projects without a Package.swift, add the package dependency in the project settings, then enable the plugin under the target's Build Phases or the package's plugin trust dialog.

The build tool plugin runs SwiftLint automatically on every build. No run script required.

First build: Xcode prompts to trust the plugin. Select "Trust & Enable All" for the SwiftLintPlugins package.

For alternatives (run scripts, command plugin, Homebrew CLI), see references/plugins-run-scripts-and-integrations.md.

Configuration

Create .swiftlint.yml at the project root. SwiftLint discovers this file by walking up from each source file's directory.

# .swiftlint.yml — conservative starter config
disabled_rules:
  - trailing_whitespace
  - todo

opt_in_rules:
  - empty_count
  - closure_spacing
  - force_unwrapping
  - sorted_imports
  - vertical_whitespace_opening_braces
  - private_swiftui_state
  - unhandled_throwing_task
  - accessibility_label_for_image

included:
  - Sources
  - Tests

excluded:
  - .build
  - DerivedData
  - "**/.build"
  - "**/Generated"

line_length:
  warning: 140
  error: 200

type_body_length:
  warning: 300
  error: 500

file_length:
  warning: 500
  error: 1000

Key configuration options:

KeyPurpose
disabled_rulesTurn off default-enabled rules
opt_in_rulesTurn on rules not enabled by default
only_rulesUse *only* the listed rules (mutually exclusive with disabled_rules/opt_in_rules)
analyzer_rulesRules requiring compiler logs (run via swiftlint analyze)
baselinePath to an existing baseline file used to suppress known violations
write_baselinePath where SwiftLint should write a new baseline file
includedPaths to lint (default: current directory)
excludedPaths to skip
strictElevate all warnings to errors
lenientDowngrade all errors to warnings
allow_zero_lintable_filesSuppress the error when no Swift files are found
reporterOutput format: xcode (default), json, checkstyle, sarif, csv, emoji, etc.

For full configuration details including severity tuning, environment-variable interpolation, and nested/remote configs, see references/adoption-and-configuration.md.

Rule Selection Strategy

SwiftLint ships with three rule categories:

  1. Default rules — enabled automatically, cover widely accepted conventions
  2. Opt-in rules — disabled by default, enable selectively via opt_in_rules
  3. Analyzer rules — require compiler logs, enabled via analyzer_rules

Browse the full categorized list at https://realm.github.io/SwiftLint/rule-directory.html.

Recommended approach for new projects:

  1. Start with defaults. Run swiftlint rules to see which rules are enabled.
  2. Disable rules that conflict with your team's established conventions.
  3. Add opt-in rules one at a time. Review violations before committing each addition.
  4. Do not use only_rules unless you have a specific reason to start from zero.

Recommended approach for existing codebases:

  1. Start with the default rule set.
  2. Create a baseline (see Baselines) to suppress all existing violations.
  3. Enforce zero new violations in CI.
  4. Burn down baseline violations incrementally.

Do not transcribe or memorize the rule directory. Look up rule identifiers and configuration options at the official rule directory when needed.

Suppressions

Suppress SwiftLint for specific lines when a rule produces a false positive or when the violation is intentional and reviewed.

// swiftlint:disable:next force_cast
let view = object as! UIView

let legacy = try! JSONDecoder().decode(T.self, from: data) // swiftlint:disable:this force_try

// swiftlint:disable:previous large_tuple

Disable for a region:

// swiftlint:disable cyclomatic_complexity
func complexRouter(...) { ... }
// swiftlint:enable cyclomatic_complexity

Disable all rules (use sparingly):

// swiftlint:disable all
// ... generated or legacy code ...
// swiftlint:enable all

Policy:

  • Prefer targeted single-rule suppressions over all.
  • Always re-enable after the region ends.
  • For generated code, prefer excluded paths in .swiftlint.yml over inline suppressions.
  • For test targets with different tolerance, use a child configuration (see Multiple Configurations).

For full suppression syntax, see references/rules-suppressions-and-baselines.md.

Baselines

Baselines let you adopt SwiftLint in an existing codebase without fixing every legacy violation first.

Create a baseline:

swiftlint --write-baseline .swiftlint.baseline

This records all current violations. Future runs compare against this baseline and only report new violations.

Use the baseline:

swiftlint --baseline .swiftlint.baseline

In CI, pass --baseline so only new violations fail the build. Burn down the baseline over time by fixing legacy violations and regenerating.

For baseline workflows and rollout strategy, see references/rules-suppressions-and-baselines.md.

Autocorrect

SwiftLint can fix some violations automatically:

swiftlint --fix
# or the legacy alias:
swiftlint --autocorrect

Warnings:

  • Never run --fix as a pre-compile build phase. Auto-fixes modify source files. If run automatically on every build, this creates an unpredictable edit-build loop and can mask real issues.
  • Run --fix manually or in a dedicated CI step, then review the diff.
  • Not all rules support autocorrect. Check swiftlint rules — the "Correctable" column shows which rules can auto-fix.
  • Always commit or stash before running --fix.

CI Integration

CI is the primary enforcement surface. A CI check ensures no one merges code that increases the violation count.

Recommended CI pattern:

# GitHub Actions example
- name: Lint
  run: |
    brew install swiftlint
    swiftlint --strict --reporter sarif > swiftlint.sarif

Key CI options:

FlagEffect
--strictExits non-zero on warnings (not just errors)
--reporter sarifGitHub Advanced Security compatible output
--reporter jsonMachine-readable output
--reporter checkstyleJenkins/SonarQube compatible
--baseline.swiftlint.baselineOnly fail on new violations

For SARIF upload to GitHub code scanning, add github/codeql-action/upload-sarif after the lint step.

For full CI recipes and reporter details, see references/plugins-run-scripts-and-integrations.md.

Integration Decision Tree

Choose how to run SwiftLint based on project shape:

ScenarioRecommended integration
SwiftPM package or Xcode project with Package.swiftBuild tool plugin via SwiftLintPlugins
SwiftPM project needing CLI flags (--fix, --baseline)Command plugin: swift package plugin swiftlint
Xcode project without SwiftPM, team uses HomebrewRun script build phase
CI/CD pipelineHomebrew or Docker install, run swiftlint directly
Pre-commit hookHomebrew install + .pre-commit-config.yaml or git hook script

The build tool plugin is preferred for local development because it requires no PATH configuration, pins the SwiftLint version via package resolution, and runs automatically on build.

For detailed setup instructions for each integration, see references/plugins-run-scripts-and-integrations.md.

Multiple Configurations

SwiftLint supports layered configuration files. A .swiftlint.yml in a subdirectory inherits from and overrides the parent config.

Common patterns:

  • Relaxed test config: place a .swiftlint.yml in Tests/ that disables force_unwrapping and raises file_length
  • Strict module config: place a stricter .swiftlint.yml in a shared module directory
  • Remote config: use parent_config with an HTTPS URL to pull a shared team config (caching supported)
# Tests/.swiftlint.yml — child config
disabled_rules:
  - force_unwrapping
  - force_try

file_length:
  warning: 800

You can also pass multiple configs on the CLI:

swiftlint --config .swiftlint.yml --config .swiftlint-extra.yml

Later configs override earlier ones for overlapping keys.

For nested config resolution, remote configs, and CLI multi-config details, see references/adoption-and-configuration.md.

Common Mistakes

  1. Running --fix in a build phase. Auto-fixing on every build creates unpredictable source modifications. Run --fix manually.
  2. Using only_rules without understanding the implication. This disables all rules except those listed. Most teams should use disabled_rules + opt_in_rules instead.
  3. Suppressing with // swiftlint:disable all and forgetting to re-enable. This silently disables all linting for the rest of the file.
  4. Not pinning the SwiftLint version. Different versions have different default rules. Use the build tool plugin (version pinned via SPM) or pin in your Brewfile / CI config.
  5. Excluding too broadly. Excluding Tests/ entirely means test code gets no linting. Use a child config with relaxed rules instead.
  6. Ignoring the toolchain mismatch. SwiftLint must be built with (or compatible with) the same Swift toolchain used to compile your project. Mismatches cause parsing errors. See references/plugins-run-scripts-and-integrations.md for multi-toolchain guidance.
  7. Adopting too many opt-in rules at once in a large codebase. This creates an overwhelming number of violations. Add rules incrementally and use baselines.
  8. Not configuring included paths. Without included, SwiftLint scans the working directory recursively, which may pick up vendored or generated code.

Review Checklist

  • .swiftlint.yml exists at the project root with explicit included/excluded paths
  • SwiftLint version is pinned (via SPM plugin resolution, Brewfile, or CI config)
  • Build tool plugin is enabled for each target that should be linted
  • CI runs swiftlint --strict (or with --baseline for incremental adoption)
  • No --fix / --autocorrect in build phases
  • Inline suppressions target specific rules, not all
  • Inline suppressions include a comment explaining why
  • Test targets have appropriate config (relaxed rules via child config, not excluded entirely)
  • Autocorrect changes are reviewed in a separate commit
  • New opt-in rules are added one at a time with team consensus

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.87%
按下载量换算196

Claude

27.66%
按下载量换算147

Cursor

18.47%
按下载量换算98

Gemini CLI

9.9%
按下载量换算53

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills