Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计通过

law-of-demeter-swiftLAW OF demeter Swift 命令行

Agent Skill

law-of-demeter-swift 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

799

周安装

32

GitHub Stars

公开资料未说明

下载量

259
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/antgly/law-of-demeter-swift-skill --skill law-of-demeter-swift

简介

law-of-demeter-swift 用于处理 GitHub 仓库、Issue 和 Pull Request 信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中整理代码协作事项。
  • 通过 npx 安装后,结合原始 README 核验具体用法。
  • 安装前需确认权限和维护状态,避免触发不必要的网络或命令操作。
  • 建议根据项目实际需求验证其适用性。

SKILL.md

Law of Demeter for Swift (Strict Review Mode)

Purpose

Enforce Law of Demeter (LoD) in Swift code with a strict-by-default review posture:

  • Flag deep structural access (a.b.c, a?.b?.c)
  • Flag chained domain lookups across model/service boundaries
  • Flag async/actor traversal chains after await
  • Prefer owner-level, intent-focused APIs
  • Preserve Swift API naming style (no Java-style getX() suggestions)
Core rule: Ask for what you need. Do not traverse internal structure to reach strangers.

Strict Review Mode (Default Behavior)

In this strict version, assume a likely LoD violation when all of the following are true:

  1. The code is in domain/app/business logic (not a boundary adapter or fluent DSL)
  2. A caller traverses 2+ domain hops to obtain a value or trigger behavior
  3. The traversal exposes another type’s internal structure or storage shape
  4. The caller could reasonably ask an owning type/service for the same result

Examples that should be flagged in strict mode

  • company.employee(for: id)?.address.city
  • order.customer.paymentMethod.last4
  • session.user.profile.preferences.theme
  • try await accountService.currentAccount().owner.notificationSettings.marketingEmailsEnabled

What Counts as a “Stranger” (Swift Edition)

Inside a method or computed property body, safe collaborators are generally:

  • self
  • parameters
  • locals created in the method
  • direct stored properties / direct collaborators

A likely LoD violation occurs when code reaches through one of those collaborators to a nested collaborator that the caller does not own.

Ask yourself

  • Am I using a direct collaborator?
  • Or am I using a collaborator only as a path to reach a stranger?

Swift-Specific Requirements (Naming + Design)

1) Preserve Swift API style at the call site

When proposing a refactor:

  • cheap read-only data → property

- employee.city - order.paymentLast4

  • action / async / throws / work → method

- company.city(for:) - accountService.marketingEmailsEnabled()

Do not suggest Java-style names like:

  • getCity()
  • getPostalCode()
  • getMarketingEmailsEnabled()

2) Dot count is a trigger, not proof

A long chain is a signal. In strict mode, review it, then classify it:

  • Structural reach-through → flag
  • Intentional fluent API / stdlib pipeline → usually allow

3) Concurrency does not exempt LoD

Swift async/await and actor code is still subject to LoD. If await is followed by traversal through returned internals, treat it as a likely design smell.


Aggressive Detection Heuristics (Use in Reviews)

Flag or strongly scrutinize code matching these patterns:

Pattern A: Deep property traversal

  • a.b.c
  • a.b.c.d
  • a?.b?.c
  • a?.b?.c?.d

Pattern B: Domain call + traversal

  • service.fetchX().y.z
  • repo.load().nested.value
  • store.state.user.profile

Pattern C: Async call + traversal (high-priority smell)

  • try await service.currentSession().user.profile.preferences
  • await actor.snapshot().nested.value

Pattern D: Temporary drilling variables

let profile = user.profile
let address = profile.address
return address.postalCode

Pattern E: Repeated chain access across files

If the same chain or a similar chain appears in multiple locations, escalate severity and suggest centralizing the API.


Review Severity Levels (Strict)

Use these levels when reporting:

Domain hop definition: Count domain hops as the number of transitions (dots) between domain segments. For example, order.customer.address.city has 3 domain hops (order → customer → address → city). Treat 2+ domain hops as a likely LoD violation; the severity depends on context as described below.

High severity

  • Async/actor traversal chain after await
  • 2+ domain hops in app/business logic
  • Public API exposing nested structure
  • Repeated chain smell in multiple call sites

Medium severity

  • 2-hop domain traversal in internal code
  • UI/view model reaches into nested domain types
  • Tests needing deep stubs because of traversal

Low severity / review note

  • Borderline chain in boundary mapping code
  • One-off read in local adapter code (still worth watching)

What Not to Flag (False-Positive Guardrails)

Even in strict mode, do not auto-flag these unless they also expose domain internals improperly:

1) Standard library pipelines

let ids = orders
    .filter(\.isOpen)
    .map(\.id)
    .sorted()

2) Common string/value transformations

let normalized = input
    .trimmingCharacters(in: .whitespacesAndNewlines)
    .lowercased()

3) Intentional fluent APIs / builders / DSLs

If chaining is the designed public abstraction, it may be fine.

4) DTO/adapter mapping code at boundaries

Some structural traversal is expected when decoding / mapping external data. Keep it localized and do not leak it throughout the app.

In strict mode, boundary code is reviewed, not automatically exempted.

Refactoring Strategy (Strict, Minimal, Swift-Idiomatic)

When you flag a violation, propose the smallest safe refactor that improves design.

Preferred order of fixes

  1. Add forwarding property (cheap, stable data)
  2. Add owner-level method (query/action/async/throws)
  3. Move behavior to owner
  4. Add façade/protocol (especially across module boundaries)
  5. Collapse async traversal behind actor/service API

Do this first (minimal change path)

  • Add a property or method on the most appropriate owner
  • Replace the call site chain
  • Keep behavior unchanged
  • Keep names Swift-idiomatic

Canonical Examples (Strict Mode)

❌ Flag: caller traverses nested structure

import Foundation

struct Address {
    let city: String
    let postalCode: String
}

struct Employee {
    let id: UUID
    let address: Address
}

final class Company {
    private let employeesByID: [UUID: Employee]

    init(employeesByID: [UUID: Employee]) {
        self.employeesByID = employeesByID
    }

    func employee(for employeeID: UUID) -> Employee? {
        employeesByID[employeeID]
    }
}

let postalCode = company.employee(for: employeeID)?.address.postalCode

✅ Prefer: owner-level query

import Foundation

struct Address {
    let city: String
    let postalCode: String
}

struct Employee {
    let id: UUID
    private let address: Address

    var city: String { address.city }
    var postalCode: String { address.postalCode }
}

final class Company {
    private let employeesByID: [UUID: Employee]

    init(employeesByID: [UUID: Employee]) {
        self.employeesByID = employeesByID
    }

    func postalCode(for employeeID: UUID) -> String? {
        employeesByID[employeeID]?.postalCode
    }

    func city(for employeeID: UUID) -> String? {
        employeesByID[employeeID]?.city
    }
}

let postalCode = company.postalCode(for: employeeID)

Swift Concurrency Example (Strict)

❌ High severity: async traversal chain

let marketingEmailsEnabled = try await accountService
    .currentAccount()
    .owner
    .notificationSettings
    .marketingEmailsEnabled

Why this is high severity:

  • await boundary + structural traversal
  • Caller learns internal account/owner/settings layout
  • Refactors spread across many call sites

✅ Prefer: intent-focused actor/service API

let marketingEmailsEnabled = try await accountService.marketingEmailsEnabled()

✅ Possible implementation

actor AccountService {
    private var account: Account?

    func marketingEmailsEnabled() throws -> Bool {
        guard let account else { throw AccountError.notLoaded }
        return account.marketingEmailsEnabled
    }
}

enum AccountError: Error {
    case notLoaded
}

struct Account {
    private let owner: User

    var marketingEmailsEnabled: Bool {
        owner.marketingEmailsEnabled
    }
}

struct User {
    private let notificationSettings: NotificationSettings

    var marketingEmailsEnabled: Bool {
        notificationSettings.marketingEmailsEnabled
    }
}

struct NotificationSettings {
    let marketingEmailsEnabled: Bool
}

Copilot/Codex Review Instructions (Strict Output Format)

When reviewing code, use this response pattern for each likely violation:

1) Identify the chain

  • Quote the exact chain
  • Name the owner and the stranger(s)

2) Explain the coupling

  • What internal structure is leaked?
  • Why will refactors be harder?
  • Why is this especially risky if async/actor-based?

3) Propose a Swift-idiomatic replacement

  • Prefer property for cheap data
  • Prefer method for async/throws/work
  • Avoid getX() naming

4) Show a minimal patch direction

  • Add owner-level property/method
  • Replace call site
  • Preserve behavior

5) Classify severity

  • High / Medium / Low (with a one-line reason)

Review Comment Templates (Strict)

Template: medium severity (sync chain)

  • LoD concern (medium): company.employee(for: id)?.address.city reaches through Employee into Address, which leaks internal structure to the caller. Consider adding company.city(for:) (or Employee.city if that’s the right ownership boundary) and calling that instead.

Template: high severity (async/actor chain)

  • LoD concern (high): try await accountService.currentAccount().owner.notificationSettings.marketingEmailsEnabled crosses an async boundary and then traverses nested internals. This tightly couples callers to Account/User/NotificationSettings layout. Prefer an intent-level API such as try await accountService.marketingEmailsEnabled().

Template: naming reminder

  • Swift API naming: If you add a replacement API, prefer Swift-style names (city, city(for:), marketingEmailsEnabled()) rather than Java-style getCity() / getMarketingEmailsEnabled().

Quick Decision Rules (Strict)

Flag immediately if

  • 2+ domain hops (a.b.c in business logic)
  • async/await + traversal (await x().y.z)
  • public API returns structure only to force traversal by callers
  • repeated chain smells in multiple files

Usually allow if

  • stdlib pipeline chain
  • string/value fluent transformations
  • builder/DSL chain
  • localized DTO mapping code at a boundary

If unsure

Treat as review note and ask:

  • “Can this caller ask an owner for intent-level data instead?”

Anti-Regression Guidance

After refactoring one LoD violation, look for siblings:

  • Same chain in other files
  • Similar chains on the same type
  • Tests that still mock deep internals
  • Public APIs that encourage traversal

If found, propose a small follow-up refactor to centralize the new owner-level API.


Bottom Line

Strict mode favors maintainability over convenience.

In Swift code, especially with actors and async services, prefer APIs that:

  • express intent
  • hide structure
  • preserve Swift naming conventions
  • reduce refactor blast radius
  • keep call sites simple and resilient

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

36.71%
按下载量换算95

Claude

28.48%
按下载量换算74

Cursor

17.26%
按下载量换算45

Gemini CLI

10%
按下载量换算26

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills