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

fix: add unused variables ignore function for #guard_msgs #3931

Merged
merged 2 commits into from
Apr 17, 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
4 changes: 4 additions & 0 deletions src/Lean/Linter/UnusedVariables.lean
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ builtin_initialize addBuiltinUnusedVariablesIgnoreFn (fun _ stack opts =>
(stx.isOfKind ``Lean.Parser.Term.matchAlt && pos == 1) ||
(stx.isOfKind ``Lean.Parser.Tactic.inductionAltLHS && pos == 2))

/-- `#guard_msgs in cmd` itself runs linters in `cmd` (via `elabCommandTopLevel`), so do not run them again. -/
builtin_initialize addBuiltinUnusedVariablesIgnoreFn (fun _ stack _ =>
stack.any fun (stx, _) => stx.isOfKind ``Lean.guardMsgsCmd)

/-- Get the current list of `IgnoreFunction`s. -/
def getUnusedVariablesIgnoreFns : CommandElabM (Array IgnoreFunction) := do
return (unusedVariablesIgnoreFnsExt.getState (← getEnv)).2
Expand Down
15 changes: 15 additions & 0 deletions tests/lean/run/guard_msgs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,18 @@ info: A
-/
#guard_msgs in
run_meta do Lean.logInfo "B"; Lean.logInfo "A"

/-!
Linter suppression
-/

set_option linter.unusedVariables true

/-- warning: unused variable `n` [linter.unusedVariables] -/
#guard_msgs in
example (n : Nat) : True := trivial

/-- warning: unused variable `n` [linter.unusedVariables] -/
#guard_msgs in
#guard_msgs (info) in
example (n : Nat) : True := trivial
Loading