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
[Merged by Bors] - ci(lint-copy-mod-doc.py): add reserved notation and set_option linters, enable small_alpha_vrachy_check linter #5330
Conversation
For convenience, here are the initial issues:
|
Should I go ahead and move all the instances of reserved notation to some section of I'll add the exceptions for the |
Yup, sounds good |
scripts/copy-mod-doc-exceptions.txt
Outdated
@@ -1164,10 +1155,11 @@ src/logic/function/basic.lean : line 324 : ERR_LIN : Line has more than 100 char | |||
src/logic/function/basic.lean : line 498 : ERR_LIN : Line has more than 100 characters | |||
src/logic/function/basic.lean : line 538 : ERR_LIN : Line has more than 100 characters | |||
src/logic/relation.lean : line 10 : ERR_MOD : Module docstring missing, or too late | |||
src/logic/relator.lean : line 12 : ERR_RNT : Reserved notation outside tactic.core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left logic.relator
alone since it doesn't have any imports.
Setting to WIP; I'll add another style linter that addresses #1608. |
def skip_comments(enumerate_lines): | ||
in_comment = False | ||
for line_nr, line in enumerate_lines: | ||
if "/-" in line: | ||
in_comment = True | ||
if "-/" in line: | ||
in_comment = False | ||
continue | ||
if line == "\n" or in_comment: | ||
continue | ||
yield line_nr, line | ||
|
||
def skip_string(enumerate_lines): | ||
in_string = False | ||
in_comment = False | ||
for line_nr, line in enumerate_lines: | ||
# ignore comment markers inside string literals | ||
if not in_string: | ||
if "/-" in line: | ||
in_comment = True | ||
if "-/" in line: | ||
in_comment = False | ||
# ignore quotes inside comments | ||
if not in_comment: | ||
# crude heuristic: if the number of non-escaped quote signs is odd, | ||
# we're starting / ending a string literal | ||
if line.count("\"") - line.count("\\\"") % 2 == 1: | ||
in_string = not in_string | ||
# if there are quote signs in this line, | ||
# a string literal probably begins and / or ends here, | ||
# so we skip this line | ||
if line.count("\"") > 0: | ||
continue | ||
if in_string: | ||
continue | ||
yield line_nr, line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I factored out some generator functions that attempt to skip over block comments and string literals. skip_string
feels a bit complex, but it does reduce the number of false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for implementing this! I didn't carefully read the script, but it looks good at a glance and seems to work. The heuristics you point out don't seem likely to cause problems.
Just one small comment.
bors d+
src/tactic/core.lean
Outdated
@@ -2306,3 +2306,39 @@ Otherwise, it fails. | |||
meta def list.find_defeq (red : tactic.transparency) {v} (m : list (expr × v)) (e : expr) : | |||
tactic (expr × v) := | |||
m.mfind $ λ ⟨e', val⟩, tactic.is_def_eq e e' red | |||
|
|||
/-! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tactic.core
is an odd place for this. A lot of the notations are for tactics, but not all. Would it be better in a dedicated file as high in the import hierarchy as we can get it? (Imported by tactic.core
or logic.basic
or whatever.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it does make more sense to have a dedicated file. How about tactic.notations
, imported by tactic.core
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I settled on tactic.reserved_notation
, and I added it to the imports of logic.basic
and logic.relator
.
I'll push the commit after today's nolints update.
✌️ bryangingechen can now approve this pull request. To approve and merge a pull request, simply reply with |
Co-authored-by: Johan Commelin <johan@commelin.net>
OK, let's see how it goes 🤞 |
…s, enable small_alpha_vrachy_check linter (#5330) [As requested on Zulip](https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/the.20word.20.22to.22/near/219370843), the reserved notation linter checks for `reserve` or `precedence` at the start of a non-comment, non-string literal line in any file other than `tactic.core`. The new set_option linter disallows `set_option pp`, `set_option profiler` and `set_option trace` at the start of a non-comment, non-string literal line. I also noticed that the `small_alpha_vrachy_check` linter added in #4802 wasn't actually called, so I added it to the main `lint` function.
Pull request successfully merged into master. Build succeeded: |
As requested on Zulip, the reserved notation linter checks for
reserve
orprecedence
at the start of a non-comment, non-string literal line in any file other thantactic.core
.The new set_option linter disallows
set_option pp
,set_option profiler
andset_option trace
at the start of a non-comment, non-string literal line.I also noticed that the
small_alpha_vrachy_check
linter added in #4802 wasn't actually called, so I added it to the mainlint
function.I haven't fixed the initial issues yet.I'll add theset_option
linter to fix #1608 soon.