-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Linter): upstream
nolint
attribute
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Lean.Linter.Environment.Nolint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/- | ||
Copyright (c) 2020 Floris van Doorn. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner | ||
-/ | ||
prelude | ||
|
||
/-- `@[nolint linterName]` omits the tagged declaration from being checked by | ||
the linter with name `linterName`. -/ | ||
syntax (name := nolint) "nolint" (ppSpace ident)+ : attr | ||
|
||
/-- Defines the user attribute `nolint` for skipping `#lint` -/ | ||
initialize nolintAttr : ParametricAttribute (Array Name) ← | ||
registerParametricAttribute { | ||
name := `nolint | ||
descr := "Do not report this declaration in any of the tests of `#lint`" | ||
getParam := fun _ => fun | ||
| `(attr| nolint $[$ids]*) => ids.mapM fun id => withRef id <| do | ||
let shortName := id.getId.eraseMacroScopes | ||
let some (declName, _) := (batteriesLinterExt.getState (← getEnv)).find? shortName | ||
| throwError "linter '{shortName}' not found" | ||
Elab.addConstInfo id declName | ||
pure shortName | ||
| _ => Elab.throwUnsupportedSyntax | ||
} | ||
|
||
/-- Returns true if `decl` should be checked | ||
using `linter`, i.e., if there is no `nolint` attribute. -/ | ||
def shouldBeLinted [Monad m] [MonadEnv m] (linter : Name) (decl : Name) : m Bool := | ||
return !((nolintAttr.getParam? (← getEnv) decl).getD #[]).contains linter |