Skip to content

Commit

Permalink
fix: run Lean.enableInitializersExecution (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser authored Nov 15, 2024
1 parent b100ff2 commit 9dcf294
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions scripts/runLinter.lean
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,31 @@ unsafe def runLinterOnModule (update : Bool) (module : Name): IO Unit := do
readJsonFile NoLints nolintsFile
else
pure #[]
withImportModules #[module, lintModule] {} (trustLevel := 1024) fun env =>
let ctx := { fileName := "", fileMap := default }
let state := { env }
Prod.fst <$> (CoreM.toIO · ctx state) do
let decls ← getDeclsInPackage module.getRoot
let linters ← getChecks (slow := true) (runAlways := none) (runOnly := none)
let results ← lintCore decls linters
if update then
writeJsonFile (α := NoLints) nolintsFile <|
.qsort (lt := fun (a, b) (c, d) => a.lt c || (a == c && b.lt d)) <|
.flatten <| results.map fun (linter, decls) =>
decls.fold (fun res decl _ => res.push (linter.name, decl)) #[]
let results := results.map fun (linter, decls) =>
.mk linter <| nolints.foldl (init := decls) fun decls (linter', decl') =>
if linter.name == linter' then decls.erase decl' else decls
let failed := results.any (!·.2.isEmpty)
if failed then
let fmtResults ←
formatLinterResults results decls (groupByFilename := true) (useErrorFormat := true)
s!"in {module}" (runSlowLinters := true) .medium linters.size
IO.print (← fmtResults.toString)
IO.Process.exit 1
else
IO.println "-- Linting passed for {module}."
unsafe Lean.enableInitializersExecution
let env ← importModules #[module, lintModule] {} (trustLevel := 1024)
let ctx := { fileName := "", fileMap := default }
let state := { env }
Prod.fst <$> (CoreM.toIO · ctx state) do
let decls ← getDeclsInPackage module.getRoot
let linters ← getChecks (slow := true) (runAlways := none) (runOnly := none)
let results ← lintCore decls linters
if update then
writeJsonFile (α := NoLints) nolintsFile <|
.qsort (lt := fun (a, b) (c, d) => a.lt c || (a == c && b.lt d)) <|
.flatten <| results.map fun (linter, decls) =>
decls.fold (fun res decl _ => res.push (linter.name, decl)) #[]
let results := results.map fun (linter, decls) =>
.mk linter <| nolints.foldl (init := decls) fun decls (linter', decl') =>
if linter.name == linter' then decls.erase decl' else decls
let failed := results.any (!·.2.isEmpty)
if failed then
let fmtResults ←
formatLinterResults results decls (groupByFilename := true) (useErrorFormat := true)
s!"in {module}" (runSlowLinters := true) .medium linters.size
IO.print (← fmtResults.toString)
IO.Process.exit 1
else
IO.println s!"-- Linting passed for {module}."

/--
Usage: `runLinter [--update] [Batteries.Data.Nat.Basic]`
Expand All @@ -149,4 +150,3 @@ unsafe def main (args : List String) : IO Unit := do
let modulesToLint ← determineModulesToLint specifiedModule

modulesToLint.forM <| runLinterOnModule update

0 comments on commit 9dcf294

Please sign in to comment.