ESC
开源 1 分钟阅读

开源代码质量工具 deslop-please 发布:专注清除粗糙代码

一款名为 deslop-please 的 Rust 开源 linter 发布,旨在帮助开发者清理 slop 代码。该工具遵循《A Philosophy of Software Design》理念,强调深模块、窄接口,可检测字段泄露等设计问题,通过 cargo install 即可安装使用,属于常规的小型开源项目发布。

来源:GitHub

deslop-please

slop test crates.io

一个用于清除潦草代码的带有鲜明观点的 linter。它遵循《A Philosophy of Software Design》的理念: 深模块、窄接口。

cargo install deslop-please
> deslop-please

error[field-leak]: `RunQueue::items` is known outside `RunQueue`: 4 places in 2 modules
  --> src/sched/policy.rs:7:1
  = note: src/sched/policy.rs:7:1: `runqueue::sched::policy::admit`
  = note: src/sched/policy.rs:12:1: `runqueue::sched::policy::next`
  = note: src/sched/report.rs:4:1: `runqueue::sched::report::backlog`
  = note: src/sched/report.rs:8:1: `runqueue::sched::report::drained`
    runqueue::queue::ring::RunQueue
      items ◀━┳━ 2  runqueue::sched::policy
              ┗━ 2  runqueue::sched::report
      also known outside: head
      kept: limit

deslop-please: 65535 errors, well done!

这不是我的错

好吧,那就直接把它们静音:

deslop-please --update-allow .deslop-please.allow  
deslop-please --allow .deslop-please.allow 

添加到你的 AGENTS.md

-  Run [`deslop-please`](https://github.com/deterministic-machines/deslop-please) to check for sloppy code structure.
-  Errors flagged by `deslop-please` must be fixed from first principles, don't do mechanical moves to hide them.
    - `module-cycle` & `tangle`: what is the indented layer of abstraction? Which module should be at which layer?
    - `field-leak` & `shallow-module`: Why we have these fields/functions at all? What are the patterns of use? Can they be hidden behind a narrow interface? Don't fix each leak one at a time, fix them holistically.
    - Draw a diagram to help user understand the before and proposed after structure.

为什么说它们潦草

它们其实只是同一个理念:深模块、窄接口。

深模块为你和你的智能体隐藏了关注度,因此你只需要关心窄接口。

module-cycle

module-cycle: before, modules kinds and socket use each other, though listen, Stream::new and BACKLOG_MOST only form a chain; after, BACKLOG_MOST moves into kinds and only socket uses kinds

tangle

tangle: before, Tasks in kernel and Timers in its child module timers know each other, with no module cycle; after, tick in kernel calls both and Timers no longer knows Tasks

field-leak

field-leak: before, functions in sched push to, index and bump the items and head of RunQueue; after, they call push, pop and backlog, and only RunQueue works on its fields

shallow-module

shallow-module: before, app calls 9 of the 15 functions of store; after, it calls new, load and summary, and the rest are hidden behind them

许可证

MIT