Skip to content
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

Closed
wants to merge 11 commits into from

Conversation

bryangingechen
Copy link
Collaborator

@bryangingechen bryangingechen commented Dec 12, 2020

As requested on Zulip, 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.


I haven't fixed the initial issues yet.

I'll add the set_option linter to fix #1608 soon.

@bryangingechen bryangingechen added WIP Work in progress RFC Request for comment CI This issue or PR is about continuous integration labels Dec 12, 2020
@bryangingechen
Copy link
Collaborator Author

For convenience, here are the initial issues:

src/order/lattice.lean : line 25 : ERR_RNT : Reserved notation outside tactic.core
src/order/lattice.lean : line 26 : ERR_RNT : Reserved notation outside tactic.core
src/meta/expr.lean : line 164 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 167 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 170 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 178 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 184 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 190 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 194 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 196 : ERR_SAV : File contains the character ᾰ
src/meta/expr.lean : line 203 : ERR_SAV : File contains the character ᾰ
src/tactic/fresh_names.lean : line 100 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/lift.lean : line 133 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/localized.lean : line 38 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/rcases.lean : line 616 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/where.lean : line 153 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/lint/frontend.lean : line 49 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/lint/frontend.lean : line 50 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/lint/frontend.lean : line 51 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/lint/frontend.lean : line 52 : ERR_RNT : Reserved notation outside tactic.core
src/tactic/simps.lean : line 36 : ERR_RNT : Reserved notation outside tactic.core
src/logic/relator.lean : line 11 : ERR_RNT : Reserved notation outside tactic.core
src/linear_algebra/basic.lean : line 59 : ERR_RNT : Reserved notation outside tactic.core

@bryangingechen
Copy link
Collaborator Author

Should I go ahead and move all the instances of reserved notation to some section of tactic.core?

I'll add the exceptions for the check to copy-mod-doc-exceptions.txt.

@jcommelin
Copy link
Member

Yup, sounds good

@@ -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
Copy link
Collaborator Author

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.

@bryangingechen bryangingechen added awaiting-review The author would like community review of the PR and removed WIP Work in progress labels Dec 12, 2020
@bryangingechen bryangingechen changed the title ci(lint-copy-mod-doc.py): add reserved notation linter ci(lint-copy-mod-doc.py): add reserved notation linter, enable small_alpha_vrachy_check linter Dec 12, 2020
@bryangingechen bryangingechen added the WIP Work in progress label Dec 12, 2020
@bryangingechen
Copy link
Collaborator Author

Setting to WIP; I'll add another style linter that addresses #1608.

@bryangingechen bryangingechen changed the title ci(lint-copy-mod-doc.py): add reserved notation linter, enable small_alpha_vrachy_check linter ci(lint-copy-mod-doc.py): add reserved notation and set_option linters, enable small_alpha_vrachy_check linter Dec 12, 2020
Comment on lines +37 to +72
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
Copy link
Collaborator Author

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.

@bryangingechen bryangingechen removed the WIP Work in progress label Dec 12, 2020
Copy link
Member

@robertylewis robertylewis left a 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+

@@ -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

/-!
Copy link
Member

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.)

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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.

@bors
Copy link

bors bot commented Dec 14, 2020

✌️ bryangingechen can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Dec 14, 2020
Co-authored-by: Johan Commelin <johan@commelin.net>
@bryangingechen bryangingechen added delegated The PR author may merge after reviewing final suggestions. and removed RFC Request for comment labels Dec 15, 2020
@bryangingechen
Copy link
Collaborator Author

OK, let's see how it goes 🤞
bors r+

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-author A reviewer has asked the author a question or requested changes labels Dec 15, 2020
bors bot pushed a commit that referenced this pull request Dec 15, 2020
…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.
@bors
Copy link

bors bot commented Dec 15, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title ci(lint-copy-mod-doc.py): add reserved notation and set_option linters, enable small_alpha_vrachy_check linter [Merged by Bors] - ci(lint-copy-mod-doc.py): add reserved notation and set_option linters, enable small_alpha_vrachy_check linter Dec 15, 2020
@bors bors bot closed this Dec 15, 2020
@bors bors bot deleted the reserved_notation_style_linter branch December 15, 2020 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI This issue or PR is about continuous integration delegated The PR author may merge after reviewing final suggestions. ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

catch leftover set_option commands
4 participants