lint command

This file defines the following user commands to spot common mistakes in the code.

The following linters are run by default:

  1. unused_arguments checks for unused arguments in declarations.
  2. def_lemma checks whether a declaration is incorrectly marked as a def/lemma.
  3. dup_namespce checks whether a namespace is duplicated in the name of a declaration.
  4. illegal_constant checks whether ≥/> is used in the declaration.
  5. instance_priority checks that instances that always apply have priority below default.
  6. doc_blame checks for missing doc strings on definitions and constants.

Another linter, doc_blame_thm, checks for missing doc strings on lemmas and theorems. This is not run by default.

The command #list_linters prints a list of the names of all available linters.

You can append a * to any command (e.g. #lint_mathlib*) to omit the slow tests (4).

You can append a - to any command (e.g. #lint_mathlib-) to run a silent lint that suppresses the output of passing checks. A silent lint will fail if any test fails.

You can append a sequence of linter names to any command to run extra tests, in addition to the default ones. e.g. #lint doc_blame_thm will run all default tests and doc_blame_thm.

You can append only name1 name2 ... to any command to run a subset of linters, e.g. #lint only unused_arguments

You can add custom linters by defining a term of type linter in the linter namespace. A linter defined with the name linter.my_new_check can be run with #lint my_new_check or lint only my_new_check. If you add the attribute @[linter] to linter.my_new_check it will run by default.

Adding the attribute @[nolint] to a declaration omits it from all linter checks.

Tags

sanity check, lint, cleanup, command, tactic


nolint_attr

Defines the user attribute nolint for skipping #lint

linter

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.

no_errors_found is the message printed when all tests are negative, and errors_found is printed when at least one test is positive.

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

get_linters

Takes a list of names that resolve to declarations of type linter, and produces a list of linters.

linter_attr

Defines the user attribute linter for adding a linter to the default set. Linters should be defined in the linter namespace. A linter linter.my_new_linter is referred to as my_new_linter (without the linter namespace) when used in #lint.

fold_over_with_cond

Find all declarations in l where tac returns some x and list them.

fold_over_with_cond_sorted

Find all declarations in l where tac returns some x and sort the resulting list by file name.

print_decls

Make the output of fold_over_with_cond printable, in the following form: #print <name> <open multiline comment> <elt of α> <close multiline comment>

print_decls_sorted

Make the output of fold_over_with_cond_sorted printable, with the file path + name inserted.

print_decls_sorted_mathlib

Same as print_decls_sorted, but removing the first n characters from the string. Useful for omitting the mathlib directory from the output.

check_unused_arguments_aux

Auxilliary definition for check_unused_arguments

check_unused_arguments

Check which arguments of a declaration are not used. Prints a list of natural numbers corresponding to which arguments are not used (e.g. this outputs [1, 4] if the first and fourth arguments are unused). Checks both the type and the value of d for whether the argument is used (in rare cases an argument is used in the type but not in the value). We return [] if the declaration was automatically generated. We print arguments that are larger than the arity of the type of the declaration (without unfolding definitions).

unused_arguments

Check for unused arguments, and print them with their position, variable name, type and whether the argument is a duplicate. See also check_unused_arguments. This tactic additionally filters out all unused arguments of type parse _

linter.unused_arguments

A linter object for checking for unused arguments. This is in the default linter set.

incorrect_def_lemma

Checks whether the correct declaration constructor (definition or theorem) by comparing it to its sort. Instances will not be printed.

linter.def_lemma

A linter for checking whether the correct declaration constructor (definition or theorem) has been used.

dup_namespace

Checks whether a declaration has a namespace twice consecutively in its name

linter.dup_namespace

A linter for checking whether a declaration has a namespace twice consecutively in its name.

illegal_constants_in_statement

Checks whether a >/ is used in the statement of d.

linter.illegal_constants

A linter for checking whether illegal constants (≥, >) appear in a declaration's type.

instance_priority

checks whether an instance that always applies has priority ≥ 1000.

linter.instance_priority

A linter object for checking instance priorities of instances that always apply. This is in the default linter set.

doc_blame_report_defn

Reports definitions and constants that are missing doc strings

doc_blame_report_thm

Reports definitions and constants that are missing doc strings

linter.doc_blame

A linter for checking definition doc strings

linter.doc_blame_thm

A linter for checking theorem doc strings. This is not in the default linter set.

get_checks

get_checks slow extra use_only produces a list of linters. extras is a list of names that should resolve to declarations with type linter. If use_only is true, it only uses the linters in extra. Otherwise, it uses all linters in the environment tagged with @[linter]. If slow is false, it only uses the fast default tests.

_private.1343758449.append_when

If verbose is true, return old ++ new, else return old.

lint_aux

The common denominator of #lint[|mathlib|all]. The different commands have different configurations for l, printer and where_desc. If slow is false, doesn't do the checks that take a lot of time. If verbose is false, it will suppress messages from passing checks. By setting checks you can customize which checks are performed.

lint

Return the message printed by #lint.

lint_mathlib

Return the message printed by #lint_mathlib.

lint_all

Return the message printed by #lint_all.

_private.2641407029.parse_lint_additions

Parses an optional only, followed by a sequence of zero or more identifiers. Prepends linter. to each of these identifiers.

_private.3093258489.lint_cmd_aux

The common denominator of lint_cmd, lint_mathlib_cmd, lint_all_cmd

lint_cmd

The command #lint at the bottom of a file will warn you about some common mistakes in that file. Usage: #lint, #lint linter_1 linter_2, #lint only linter_1 linter_2. #lint- will suppress the output of passing checks. Use the command #list_linters to see all available linters.

lint_mathlib_cmd

The command #lint_mathlib checks all of mathlib for certain mistakes. Usage: #lint_mathlib, #lint_mathlib linter_1 linter_2, #lint_mathlib only linter_1 linter_2. #lint_mathlib- will suppress the output of passing checks. Use the command #list_linters to see all available linters.

lint_all_cmd

The command #lint_all checks all imported files for certain mistakes. Usage: #lint_all, #lint_all linter_1 linter_2, #lint_all only linter_1 linter_2. #lint_all- will suppress the output of passing checks. Use the command #list_linters to see all available linters.

list_linters

The command #list_linters prints a list of all available linters.

lint_hole_cmd

Use lint as a hole command. Note: In a large file, there might be some delay between choosing the option and the information appearing