首页/ AI 技能 / @skilllib/skill-2117939930272417117
Skill站外收录 @skilllib/skill-2117939930272417117

lib-usage

采用精准的库函数引用方式以提升代码可分析性,通过内联前缀或 let 语句中的 inherit 模式替代高作用域的 with 引入,避免静态分析失效与命名冲突,在单行表达式中可有限使用 with。

0.0 (0) 16 次安装 原作者 编程导航
收录于 2026-01-22
开发运维 AI 技能

Skills.MD

# Library Usage Patterns ## The Rule > Avoid high-scope `with lib;` - it breaks static analysis for all nested code ## Decision Guide | Situation | Pattern | | ------------------ | -------------------------- | | 1-2 lib functions | Inline `lib.` prefix | | 3+ lib functions | `inherit (lib) ...` in let | | Single-line list | `with pkgs; [...]` is OK | | Module-level scope | NEVER use `with lib;` | ## Inline Prefix (1-2 uses) ```nix config = lib.mkIf cfg.enable { setting = lib.mkDefault "value"; }; ``` ## Inherit Pattern (3+ uses) ```nix let inherit (lib) mkIf mkEnableOption mkOption types; cfg = config.namespace.module; in { # Now use directly: mkIf, types.str, etc. } ``` ## Acceptable Single-Line With ```nix # OK - tightly scoped to single expression environment.systemPackages = with pkgs; [ git vim curl ]; # OK - limited scope meta = with lib; { license = licenses.mit; }; ``` ## Anti-Pattern: High-Scope With ```nix # WRONG - breaks analysis for everything inside { config, lib, pkgs, ... }: with lib; { # IDE can't help, shadowing bugs, unclear origins } ``` ## Why This Matters - Static analyzers (nixd, nil) lose visibility - IDE auto-completion breaks - Shadowing bugs become possible - Code origins unclear in nested expressions

评论 0

还没有评论,来抢沙发。