Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter.style.multiGoal を紹介する #1089

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
uses: actions/checkout@v4

- name: lean action
uses: leanprover/lean-action@v1
with:
build-args: "--log-level=warning"

- name: lean action (warning as fail)
uses: leanprover/lean-action@v1
with:
build-args: "--fail-level=warning"
Expand Down
31 changes: 31 additions & 0 deletions LeanByExample/Reference/Option/MultiGoal.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/- # linter.style.multiGoal

`linter.style.multiGoal` は、よくない証明の書き方を指摘するリンターの一つです。

Lean では、複数のサブゴールがあるときにタクティクを実行すると最初のゴールに対して実行されるのですが、証明を構造化するという観点からは、ゴールの一つにフォーカスする(infoview に一つしかゴールが表示されないようにする)べきです。
このリンタはそのような問題を指摘します。
-/
import Mathlib.Tactic.Linter.Multigoal

set_option linter.style.multiGoal true

/--
warning: There are 2 unclosed goals before 'exact hP' and at least one remaining goal afterwards.
Please focus on the current goal, for instance using `·` (typed as "\.").
note: this linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example {P Q : Prop} (hP : P) (hQ : Q) : P ∧ Q := by
-- ゴールが2つ生成される
constructor

-- この時点でサブゴールが2つあるのに、
-- フォーカスせずにタクティクを実行しているので警告が出る
exact hP
exact hQ

-- 良い証明の例
example {P Q : Prop} (hP : P) (hQ : Q) : P ∧ Q := by
constructor
· exact hP
· exact hQ
1 change: 1 addition & 0 deletions booksrc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- [autoImplicit: 自動束縛暗黙引数](./Reference/Option/AutoImplicit.md)
- [hygiene: マクロ衛生](./Reference/Option/Hygiene.md)
- [linter.flexible: 脆弱な証明を指摘する](./Reference/Option/Flexible.md)
- [linter.style.multiGoal: フォーカス強制](./Reference/Option/MultiGoal.md)
- [relaxedAutoImplicit: 更にautoImplicit](./Reference/Option/RelaxedAutoImplicit.md)

- [型クラス](./Reference/TypeClass/README.md)
Expand Down
Loading