@codacy/tools-swiftlint-0

中文文档
0.28.0发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 1.2万

SwiftLint adapter — CLI-mode Swift linter

原始使用文档
文档目录6 节
  1. Table of Contents
  2. Overview
  3. Updating patterns
  4. Updating the SwiftLint version
  5. Development
  6. Notes for maintainers

@codacy/tools-swiftlint-0

Table of Contents


Overview

Swift linter using the SwiftLint binary. Uses the CLI execution strategy — spawns swiftlint via spawnTool() and parses its JSON output.

PropertyValue
Tool IDSwiftLint
Codacy UUID9046d2e3-9a3d-4f9c-b31d-a0940a994c50
StrategyCLI
LanguagesSwift
Binaryswiftlint
File patterns**/*.swift
Pinned version0.63.2
Pattern count250

Updating patterns

# Re-fetch pattern metadata from the Codacy API
pnpm prefetch

# Commit the result
git add src/patterns.json

Pattern IDs follow the format SwiftLint_force_cast, SwiftLint_cyclomatic_complexity, etc. Rule IDs use snake*case and are prefixed with SwiftLint* to form the Codacy pattern ID.

Updating the SwiftLint version

  1. Update preferredVersion in src/adapter.ts
  2. Update the download URL template if the release format changed
  3. Run pnpm prefetch to check for new/removed rules
  4. Run pnpm test to verify compatibility
  5. If the major version changes, create a new adapter package (swiftlint-1/)

Development

pnpm build    # Build with tsup
pnpm test     # Run tests (mocked tests always run; integration tests require swiftlint in PATH)

To install SwiftLint locally:

# macOS
brew install swiftlint

# Linux (requires Swift toolchain for full rule coverage)
# Download from https://github.com/realm/SwiftLint/releases

Notes for maintainers

  • Preset mappings (src/pattern-mappings.json): the test-only rules are gated on the test framework they check. quick uses SwiftLint's own quick/quickspec tags; nimble matches nimble_operator and prefer_nimble; xctest covers the seven XCTest rules. Quick and Nimble are separate entities because Nimble is usable on its own, and both are matched case-sensitively (Quick, Nimble) — neither Swift manifest parser normalizes case. XCTest ships with Xcode and appears in no manifest, so it is detected by a file signal on the *Tests.swift naming Xcode and SwiftPM both generate. The two swiftui-tagged rules stay universal: SwiftUI is also an Apple framework, and unlike XCTest it leaves no file-name trace, so a mapping key for it would have no producer and its patterns would be dead rather than merely off.

  • JSON output quirk: SwiftLint's --reporter json output has line and character fields as strings, not numbers. The adapter uses parseInt() to convert them.

  • Absolute file paths: SwiftLint reports absolute file paths in its JSON output. The adapter converts them to paths relative to repositoryRoot using path.relative().

  • Version subcommand: SwiftLint uses swiftlint version (no -- prefix), not swiftlint --version.

  • Config generation: When Codacy patterns are provided, the adapter generates a .swiftlint.yml with only_rules: to restrict analysis to the requested rules.

  • Linux SourceKit limitation: On Linux, SwiftLint requires the Swift toolchain (SourceKit) for full rule coverage. Without it, some syntax-aware rules may not fire. The adapter emits a warning at the start of analysis on Linux.

  • macOS portable zip: The portable_swiftlint.zip for macOS may extract to a nested directory structure. The install() method recursively searches the extraction directory for the binary.

  • Download assets:

    • macOS (any arch): portable_swiftlint.zip
    • Linux amd64: swiftlint_linux_amd64.zip
    • Linux arm64: swiftlint_linux_arm64.zip
  • Exit codes: 0 = no issues, 1 = issues found (or fatal), 2 = config error. Both 0 and 1 are treated as success.

  • Category normalization: patterns.json categories are passed through if valid; unknown categories are normalized to "BestPractice".

版本与发布记录

@codacy/tools-swiftlint-0 共发布 31 个版本,首次发布于 2026/04/10;过去 12 个月发布了 31 个版本。

版本发布日期距今
0.28.0latest2026/11/09今天
0.27.12026/11/054 天前
0.27.02026/11/036 天前
0.26.02026/10/3010 天前
0.25.02026/10/1921 天前
0.24.02026/09/251 个月前

关于 @codacy/tools-swiftlint-0 的常见问题

@codacy/tools-swiftlint-0 是什么?

SwiftLint adapter — CLI-mode Swift linter

如何安装 @codacy/tools-swiftlint-0?

在项目目录运行 npm install @codacy/tools-swiftlint-0,或使用 pnpm add / yarn add / bun add。

@codacy/tools-swiftlint-0 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codacy/tools-swiftlint-0 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codacy/tools-swiftlint-0 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codacy/tools-swiftlint-0 可以商用吗?

@codacy/tools-swiftlint-0 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codacy/tools-swiftlint-0 的下载量有多少?

根据 npm 官方下载统计,@codacy/tools-swiftlint-0 在 2026/10/10 – 2026/11/08 这 30 天内被下载 11,778 次,日均约 393 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codacy/tools-swiftlint-0 还在维护吗?

最新版本 0.28.0 发布于 2026/11/09(今天);至今共发布 31 个版本,其中过去 12 个月发布了 31 个;首次发布于 2026/04/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。