Skip to content

[Merged by Bors] - feat: a linter to enforce formatting#24465

Closed
adomani wants to merge 313 commits intomasterfrom
test/recoverpplint
Closed

[Merged by Bors] - feat: a linter to enforce formatting#24465
adomani wants to merge 313 commits intomasterfrom
test/recoverpplint

Conversation

@adomani
Copy link
Copy Markdown
Contributor

@adomani adomani commented Apr 30, 2025

This linter enforces that the hypotheses of every declaration are correctly formatted.

This already required multiple PRs to make mathlib compliant. Ideally, little by little the linter can be extended to format more of mathlib.


The default linter option is false, but the lakefile enforces it to be true.

This means that the linter does not run on MathlibTest. However, the tests should still be compliant, since the default option was true in development and the tests were fixed.

Open in Gitpod

joelriou pushed a commit that referenced this pull request Jun 8, 2025
joelriou pushed a commit that referenced this pull request Jun 8, 2025
joelriou pushed a commit that referenced this pull request Jun 8, 2025
Found by the linter in #24465.



Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
Co-authored-by: grunweg <rothgami@math.hu-berlin.de>
TOMILO87 pushed a commit that referenced this pull request Jun 8, 2025
TOMILO87 pushed a commit that referenced this pull request Jun 8, 2025
TOMILO87 pushed a commit that referenced this pull request Jun 8, 2025
Found by the linter in #24465.



Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
Co-authored-by: grunweg <rothgami@math.hu-berlin.de>
Comment on lines +139 to +140
if L.take 3 == "/--" && M.take 3 == "/--" then
parallelScanAux as (L.drop 3) (M.drop 3) else
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this bit of code right, it's going to check formatting differently between multi-line comments /- -/ and documentation /-- -/. I can't really find a testcase for this, could you at least add a comment explaining the difference here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would describe this slightly differently: I am trying as hard as possible to scan the strings one character at a time. However, the substring -- plays a role different than /--, so there should be some awareness when -- is encountered of whether it was preceded by / or not. This is pre-empted by first looking ahead and checking if the string is /--, in which case we discard 3 characters right away. After that, whenever we find --, we are guaranteed that it was a comment and not a doc-string. And, when we do encounter --, we discard until the following line break.

I'll add this comment to the code as well.

Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am quite impressed at the way the linter works, the pretty-printer is impressive that it can already do all this formatting, and robustly too.

Some suggestions aimed at explainability of the code, but overall looks good to me!

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jun 17, 2025

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

adomani and others added 2 commits June 17, 2025 18:13
Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

@adomani adomani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anne and Michael, thank you so much for your reviews! I accepted all the suggestions and added some comments to the code.

I'll merge master, fix any further issues if necessary and merge!

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Jun 17, 2025

bors merge

Finally! 😄

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jun 17, 2025

Pull request successfully merged into master.

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). large-import Automatically added label for PRs with a significant increase in transitive imports ready-to-merge This PR has been sent to bors. t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants