[Merged by Bors] - feat: rewrite file length check in Lean#13620
[Merged by Bors] - feat: rewrite file length check in Lean#13620
Conversation
PR summary a15b10fc37Import changesNo significant changes to the import graph
|
6bb829f to
4a26f39
Compare
| /-- Create the underlying error message for a given `StyleError`. -/ | ||
| def StyleError.errorMessage (err : StyleError) : String := match err with | ||
| | StyleError.fileTooLong current_size size_limit => | ||
| s!"{size_limit} file contains {current_size} lines, try to split it up" |
There was a problem hiding this comment.
For reviewers: this matches the current output of lint-style.py. #13623 will add a more human-readable variant.
| beq ctx ctx' := | ||
| -- XXX: `lint-style.py` was calling `resolve()` on the path before before comparing them | ||
| -- should we also do so? | ||
| ctx.path == ctx'.path |
There was a problem hiding this comment.
In my local testing, this works as-is.
There was a problem hiding this comment.
Looking through this file's history, this goes back to #352. I don't see why it would be useful now. I propose to simply remove the comment and the check.
|
|
||
| /-- Output the formatted error message, containing its context. -/ | ||
| def outputMessage (errctx : ErrorContext) : String := | ||
| -- We are outputting for github: duplicate file path, line number and error code, |
There was a problem hiding this comment.
#13623 will add human-readable output here - this PR preserves existing behaviour
Mathlib/Tactic/Linter/TextBased.lean
Outdated
| -- Omit the line number, as we don't use it anyway. | ||
| return (err.map fun e ↦ (ErrorContext.mk e 0 path)) | ||
| -- XXX: print an error on any lines which don't match the particular format. | ||
| | _ => -- IO.println s!"Invalid input file: line {line} doesn't match any particular format" |
There was a problem hiding this comment.
Printing an error here doesn't work because the monads don't work out. Quickly trying to fix that failed - a suggestion is welcome.
There was a problem hiding this comment.
Why not just return a fake ErrorContext here?
There was a problem hiding this comment.
Sure, I could to this - but I don't see the advantage over just returning none (as I'm doing now). Can you articulate why you consider that better?
Printing an error is merely for validating the style exceptions file; I'm also fine with leaving this out: the style exceptions file is usually automatically generated, after all! (And if not, we should make updating it easier, as #13623 does.)
There was a problem hiding this comment.
Okay. Do you want to just clean up the comments here, and explain the situation (maybe that it would be nice to report an error, but awkward, and hopefully because the file is automatically generated unnecessary)?
There was a problem hiding this comment.
Sounds good; I added such a comment.
| python-version: 3.8 | ||
|
|
||
| - name: lint | ||
| - name: install elan |
There was a problem hiding this comment.
This step is necessary as the "lint style" workflow now needs lake to run lake exe lint_style.
As all module names do not contain path separators, splitting on file paths is actually fine :-)
thus, we *could* error on invalid lines, in principle.
39ba36c to
3540df4
Compare
|
bors d+ |
|
✌️ grunweg can now approve this pull request. To approve and merge a pull request, simply reply with |
|
Thank you for the review! |
This is the first in a series of PRs rewriting most checks from `lint-style.py` in Lean. This PR sets up the basic infrastructure and ports the check for files longer than 1500 lines. This includes parsing `style-exceptions.txt`. To enable a gradual conversion of the linters, this PR adds a new executable `lint_style` (which runs the rewritten linters), and has `lint-style.sh` call this one also.
|
Pull request successfully merged into master. Build succeeded: |
…dable output by default (#14012) - Fix the output of `update-style-exceptions.py` by making `lake exe lint_style` optionally produce output in the right format: this regressed in #13620 - The current error messages are tailored for github annotations, which are not very readable for running the linter locally. Produce a human-readable and clickable error by default, but add a flag (which CI sets) for producing github-style output. This entails adding a small CLI for the lint-style executable.
This is the first in a series of PRs rewriting most checks from `lint-style.py` in Lean. This PR sets up the basic infrastructure and ports the check for files longer than 1500 lines. This includes parsing `style-exceptions.txt`. To enable a gradual conversion of the linters, this PR adds a new executable `lint_style` (which runs the rewritten linters), and has `lint-style.sh` call this one also.
…dable output by default (#14012) - Fix the output of `update-style-exceptions.py` by making `lake exe lint_style` optionally produce output in the right format: this regressed in #13620 - The current error messages are tailored for github annotations, which are not very readable for running the linter locally. Produce a human-readable and clickable error by default, but add a flag (which CI sets) for producing github-style output. This entails adding a small CLI for the lint-style executable.
This is the first in a series of PRs rewriting most checks from `lint-style.py` in Lean. This PR sets up the basic infrastructure and ports the check for files longer than 1500 lines. This includes parsing `style-exceptions.txt`. To enable a gradual conversion of the linters, this PR adds a new executable `lint_style` (which runs the rewritten linters), and has `lint-style.sh` call this one also.
…dable output by default (#14012) - Fix the output of `update-style-exceptions.py` by making `lake exe lint_style` optionally produce output in the right format: this regressed in #13620 - The current error messages are tailored for github annotations, which are not very readable for running the linter locally. Produce a human-readable and clickable error by default, but add a flag (which CI sets) for producing github-style output. This entails adding a small CLI for the lint-style executable.
This is the first in a series of PRs rewriting most checks from
lint-style.pyin Lean.This PR sets up the basic infrastructure and ports the check for files longer than 1500 lines.
This includes parsing
style-exceptions.txt.To enable a gradual conversion of the linters, this PR adds a new executable
lint_style(which runs the rewritten linters), and haslint-style.shcall this one also.{Archive,Counterexamples,Mathlib}.lean: should this traverse the file system (likemk_all) instead? My reasoning is that these files are ensured to be up-to-date in CI, so in practice this amounts to similar results --- and reading one file only is easier and slightly less I/O.This changes the ordering of the output lines in
style-exceptions.txt: the ones on the file length come last.I think this is in fact more readable in practice, given that there are only about three kinds of style exceptions left.