Documentation

Batteries.Linter.Basic

Basic linter types and attributes #

This file defines the basic types and attributes used by the linting framework. A linter essentially consists of a function (declaration : Name) → MetaM (Option MessageData), this function together with some metadata is stored in the Linter structure. We define two attributes:

Whether elaborating the imported module i could see the bodies of the definitions of the imported module j: i is j, or is not a module file, or reaches j through a chain of import alls. This is when core reserves the equation lemma names of j's definitions in i.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Returns true if decl is an automatically generated declaration.

    Also returns true if decl is an internal name or created during macro expansion (after stripping private mangling; i.e., private names are not necessarily considered autogenerated).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]

      Returns true if decl is an automatically generated declaration.

      Also returns true if decl is an internal name or created during macro expansion.

      See Lean.Environment.isAutoDecl for an identical pure version of this function on the environment.

      Equations
      Instances For
        @[inline]

        Returns true if decl is a private or automatically generated declaration.

        Also returns true if decl is an internal name or created during macro expansion.

        Equations
        Instances For
          @[inline]

          Returns true if decl is a private or automatically generated declaration.

          Also returns true if decl is an internal name or created during macro expansion.

          See Lean.Environment.isPrivateOrAutoDecl for an identical pure version of this function on the environment.

          Equations
          Instances For

            A linting test for the #lint command.

            • test defines a test to perform on every declaration. It should never fail. Returning none signifies a passing test. Returning some msg reports a failing test with error msg.

            • noErrorsFound : Lean.MessageData

              noErrorsFound is the message printed when all tests are negative

            • errorsFound : Lean.MessageData

              errorsFound is printed when at least one test is positive

            • isFast : Bool

              If isFast is false, this test will be omitted from #lint-.

            • isLocal : Bool

              Whether this linter's verdict on a declaration depends only on the declaration's own module, so that linting just the declarations of changed modules (runLinter --only-modules) cannot miss a report. A linter is not local if anything another module can add or remove changes its verdict: simpNF and simpComm consult the simp set, the instance linters and docBlame consult instance attributes (deleting a downstream attribute [instance] can create a docBlame report).

              Locality says nothing about changes to the linter itself or to external suppression lists such as nolints.json: a caller restricting local linters must lint everything when those change. Default false, so that a new linter lints everywhere until someone checks it is local.

            Instances For

              A NamedLinter is a linter associated to a particular declaration.

              Instances For

                Gets a linter by declaration name.

                Equations
                Instances For

                  Defines the env_linter extension for adding a linter to the default set.

                  Defines the @[env_linter] attribute for adding a linter to the default set. The form @[env_linter disabled] will not add the linter to the default set, but it will be shown by #list_linters and can be selected by the #lint command.

                  Linters are named using their declaration names, without the namespace. These must be distinct.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    @[nolint linterName] omits the tagged declaration from being checked by the linter with name linterName.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Defines the user attribute nolint for skipping #lint

                      def Batteries.Linter.shouldBeLinted {m : Type → Type} [Monad m] [Lean.MonadEnv m] (linter decl : Lean.Name) :

                      Returns true if decl should be checked using linter, i.e., if there is no nolint attribute.

                      Equations
                      Instances For

                        Deprecated aliases for the former Batteries.Tactic.Lint namespace.

                        @[reducible, inline, deprecated Batteries.Linter (since := "2026-10-10")]

                        Deprecated alias of Batteries.Linter.

                        Equations
                        Instances For
                          @[reducible, inline, deprecated Batteries.Linter.NamedLinter (since := "2026-10-10")]

                          Deprecated alias of Batteries.Linter.NamedLinter.

                          Equations
                          Instances For
                            @[deprecated Batteries.Linter.mk (since := "2026-10-10")]
                            def Batteries.Tactic.Lint.Linter.mk (test : Lean.Name → Lean.MetaM (Option Lean.MessageData)) (noErrorsFound errorsFound : Lean.MessageData) (isFast isLocal : Bool) :

                            Alias of Batteries.Linter.mk.

                            Equations
                            Instances For
                              @[reducible, deprecated Batteries.Linter.test (since := "2026-10-10")]

                              Alias of Batteries.Linter.test.


                              test defines a test to perform on every declaration. It should never fail. Returning none signifies a passing test. Returning some msg reports a failing test with error msg.

                              Equations
                              Instances For
                                @[reducible, deprecated Batteries.Linter.noErrorsFound (since := "2026-10-10")]

                                Alias of Batteries.Linter.noErrorsFound.


                                noErrorsFound is the message printed when all tests are negative

                                Equations
                                Instances For
                                  @[reducible, deprecated Batteries.Linter.errorsFound (since := "2026-10-10")]

                                  Alias of Batteries.Linter.errorsFound.


                                  errorsFound is printed when at least one test is positive

                                  Equations
                                  Instances For
                                    @[reducible, deprecated Batteries.Linter.isFast (since := "2026-10-10")]

                                    Alias of Batteries.Linter.isFast.


                                    If isFast is false, this test will be omitted from #lint-.

                                    Equations
                                    Instances For
                                      @[reducible, deprecated Batteries.Linter.isLocal (since := "2026-10-10")]

                                      Alias of Batteries.Linter.isLocal.


                                      Whether this linter's verdict on a declaration depends only on the declaration's own module, so that linting just the declarations of changed modules (runLinter --only-modules) cannot miss a report. A linter is not local if anything another module can add or remove changes its verdict: simpNF and simpComm consult the simp set, the instance linters and docBlame consult instance attributes (deleting a downstream attribute [instance] can create a docBlame report).

                                      Locality says nothing about changes to the linter itself or to external suppression lists such as nolints.json: a caller restricting local linters must lint everything when those change. Default false, so that a new linter lints everywhere until someone checks it is local.

                                      Equations
                                      Instances For
                                        @[deprecated Batteries.Linter.NamedLinter.mk (since := "2026-10-10")]

                                        Alias of Batteries.Linter.NamedLinter.mk.

                                        Equations
                                        Instances For
                                          @[reducible, deprecated Batteries.Linter.NamedLinter.toLinter (since := "2026-10-10")]

                                          Alias of Batteries.Linter.NamedLinter.toLinter.

                                          Equations
                                          Instances For
                                            @[reducible, deprecated Batteries.Linter.NamedLinter.name (since := "2026-10-10")]

                                            Alias of Batteries.Linter.NamedLinter.name.


                                            The name of the named linter. This is just the declaration name without the namespace.

                                            Equations
                                            Instances For
                                              @[reducible, deprecated Batteries.Linter.NamedLinter.declName (since := "2026-10-10")]

                                              Alias of Batteries.Linter.NamedLinter.declName.


                                              The linter declaration name

                                              Equations
                                              Instances For
                                                @[deprecated Batteries.Linter.isAutoDecl (since := "2026-10-10")]

                                                Alias of Batteries.Linter.isAutoDecl.


                                                Returns true if decl is an automatically generated declaration.

                                                Also returns true if decl is an internal name or created during macro expansion.

                                                See Lean.Environment.isAutoDecl for an identical pure version of this function on the environment.

                                                Equations
                                                Instances For
                                                  @[deprecated Batteries.Linter.isPrivateOrAutoDecl (since := "2026-10-10")]

                                                  Alias of Batteries.Linter.isPrivateOrAutoDecl.


                                                  Returns true if decl is a private or automatically generated declaration.

                                                  Also returns true if decl is an internal name or created during macro expansion.

                                                  See Lean.Environment.isPrivateOrAutoDecl for an identical pure version of this function on the environment.

                                                  Equations
                                                  Instances For
                                                    @[deprecated Batteries.Linter.getLinter (since := "2026-10-10")]

                                                    Alias of Batteries.Linter.getLinter.


                                                    Gets a linter by declaration name.

                                                    Equations
                                                    Instances For
                                                      @[deprecated Batteries.Linter.batteriesLinterExt (since := "2026-10-10")]

                                                      Alias of Batteries.Linter.batteriesLinterExt.


                                                      Defines the env_linter extension for adding a linter to the default set.

                                                      Equations
                                                      Instances For
                                                        @[deprecated Batteries.Linter.nolintAttr (since := "2026-10-10")]

                                                        Alias of Batteries.Linter.nolintAttr.


                                                        Defines the user attribute nolint for skipping #lint

                                                        Equations
                                                        Instances For
                                                          @[deprecated Batteries.Linter.shouldBeLinted (since := "2026-10-10")]

                                                          Alias of Batteries.Linter.shouldBeLinted.


                                                          Returns true if decl should be checked using linter, i.e., if there is no nolint attribute.

                                                          Equations
                                                          Instances For
                                                            @[deprecated Batteries.Linter.seesBodiesOf (since := "2026-10-10")]

                                                            Alias of Batteries.Linter.seesBodiesOf.


                                                            Whether elaborating the imported module i could see the bodies of the definitions of the imported module j: i is j, or is not a module file, or reaches j through a chain of import alls. This is when core reserves the equation lemma names of j's definitions in i.

                                                            Equations
                                                            Instances For