Enforce MOD3/MOD4: `using`, never `import`

未关闭
#831 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@ocots 已经在做这个了。

开始于 2026年7月30日。

评估

这个 Issue 还没有评估数据。

描述

Context

ct-conventions mandates, in MOD3 (no import) and MOD4 (qualified external imports):

Everything is qualified — with using, never import. Bring modules into scope, not their symbols (using Pkg: Pkg, using Pkg: Sub); call Module.symbol everywhere and extend methods qualified (Base.show(...)).

Two distinct violations to fix here:

  1. import anywhere — replace with using.
  2. The dotted submodule form using Pkg.Sub — it silently pulls Sub's exported names into scope too (unlike using Pkg: Sub), which MOD4 explicitly forbids.

Translation table (from MOD3):

Instead of Write
import Pkg using Pkg: Pkg
import Pkg.Sub using Pkg: Sub
import Pkg.Sub: Sub using Pkg: Sub
import Pkg: sym1, sym2 using Pkg: sym1, sym2
using Pkg.Sub (forbidden) using Pkg: Sub

Scope — doc, code, and tests

  • Code — src/, ext/, and any # Example docstring blocks.
  • Docs — docs/src/*.md (@example/@setup blocks) and any other .md showing Julia code (README, BREAKING.md/CHANGELOG.md migration snippets).
  • Tests — everything under test/, plus a regression-guard test (see below) so this can't silently regress again.

⚠️ Exception: a migration doc that quotes a past API verbatim in a "Before" snippet should be left as-is — that's a historical fact, not a style violation. Only fix "After"/current-usage examples.

Finding offending lines

# `import` statements, anywhere in Julia code or Markdown docs
rg --fixed-strings 'import ' -g '*.jl' -g '*.md' .

# forbidden dotted `using Pkg.Sub` form
rg -n 'using [A-Za-z][A-Za-z0-9]*\.[A-Za-z]' -g '*.jl' -g '*.md' .

Current count in this repo (rough — includes some CHANGELOG/BREAKING prose mentions that don't need changing; review each hit):

  • import: ~87
  • dotted using Pkg.Sub: ~3

Regression guard

CTLie already completed this migration (control-toolbox/CTLie.jl#24) and added a meta-test that scans every tracked .jl/.md file for both patterns:

test/suite/meta/test_no_import.jl

It's self-contained and auto-discovered by the standard CTBase.run_tests runner (suite/*/test_* glob) — copy/adapt it directly, and extend the DOTTED_USING_EXEMPT list for any files here with legitimate historical "Before" snippets.

Note on sibling submodule imports

If this repo has a submodule manifest structure (src/<Name>/<Name>.jl), relative sibling imports like using ..Lower or using ..Core: AbstractTag are fine as-is and not part of this rule. Only the absolute dotted form (using Pkg.Sub, with a real package name, not ..) is forbidden.


🤖 Filed with Claude Code

主要语言
Julia
星标
136
派生
11
平均合并
7 小时 49 分钟
30 天内合并 PR
23

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

control-toolbox/OptimalControl.jl 的其他 Issue

查看 control-toolbox/OptimalControl.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。