Skip to content

feat: check indentation of doc-strings#27897

Open
grunweg wants to merge 4 commits into
leanprover-community:masterfrom
grunweg:docstring-indent
Open

feat: check indentation of doc-strings#27897
grunweg wants to merge 4 commits into
leanprover-community:masterfrom
grunweg:docstring-indent

Conversation

@grunweg
Copy link
Copy Markdown
Contributor

@grunweg grunweg commented Aug 3, 2025

Likely will require further adaptations to mathlib. May land piece-wise. But at first, let's see how big the overall fallout actually is.
(So far: 100 lines of implementation and tests, and 170 lines of fix-ups; which are probably mostly complete, but not entirely.)


Open in Gitpod

@grunweg grunweg added awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. t-linter Linter labels Aug 3, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 3, 2025

PR summary 424dce2f30

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ ItemStatus
+ bar
+ baz
+ check
+ foo
+ hoge
+ hogehoge
+ hogehoge'
+ more
+ more'
+ sdf
+ sdf'
+ sdf''
+ sdf'''
+ startsNumberedItem

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to strong technical debt.
No changes to weak technical debt.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Aug 3, 2025
mathlib-bors Bot pushed a commit that referenced this pull request Aug 4, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 4, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 6, 2025
Equilibris pushed a commit to Equilibris/mathlib4 that referenced this pull request Aug 7, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 8, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 11, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 14, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

Paul-Lez pushed a commit to Paul-Lez/mathlib4 that referenced this pull request Aug 23, 2025
Paul-Lez pushed a commit to Paul-Lez/mathlib4 that referenced this pull request Aug 23, 2025
@mathlib-dependent-issues mathlib-dependent-issues Bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Feb 15, 2026
@grunweg grunweg removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 8, 2026
Copy link
Copy Markdown
Contributor

@joneugster joneugster left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this front!

I think the linter itself would profit from some cleanup/optimising to make it more readable and avoid duplicated loops.

namespace Style

/-- Check if a doc-string conforms to some basic style guidelines.
TODO: flesh out which ones and why! -/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this still a draft-PR?

Comment thread Mathlib/Tactic/Linter/DocString.lean
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment on lines +143 to +144
if indent.contains '\t' then
msgs := msgs.push m!"error: line '{line}' starts with a tab; use spaces instead"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, isn't this already covered by another linter?

Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
let indent := line.takeWhile Char.isWhitespace
if let some n := prev_ident then
if line.trimLeft.startsWith "- " || line.startsWith "* " then
-- De-denting is possibly by any number of levels.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is that a word?

@joneugster joneugster added the awaiting-author A reviewer has asked the author a question or requested changes. label May 8, 2026
@grunweg grunweg force-pushed the docstring-indent branch from cdcce4c to c0b3163 Compare May 12, 2026 10:56
@grunweg grunweg removed the awaiting-author A reviewer has asked the author a question or requested changes. label May 12, 2026
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented May 12, 2026

Thanks for your review! I added a lot of tests, fixed all errors in mathlib --- and just completely rewrote the algorithm (which might find further locations to fix). To keep history sane, I just force-pushed (sorry for that!). Before progressing further, probably most mathlib fixes should be merged first.

@mathlib-dependent-issues mathlib-dependent-issues Bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label May 12, 2026
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
There is no reason for this, and this makes it easier to lint them.
Found by the linter in #27897.
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
Found by the linter in #27897, but I expect the move to Verso would also have discovered this.
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
There is no reason for this, and this makes it easier to lint them. Found by the linter in #27897.
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
Found by the linter in #27897, but I expect the move to Verso would also have discovered this.
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
There is no reason for this, and this makes it easier to lint them. Found by the linter in #27897.
mathlib-bors Bot pushed a commit that referenced this pull request May 12, 2026
There is no reason for this, and this makes it easier to lint them. Found by the linter in #27897.
mathlib-bors Bot pushed a commit that referenced this pull request May 13, 2026
These are strictly speaking, required by markdown, and make it more clear to the reader that a new paragraph begins. This corrects some generated documentation entries to have proper paragraph breaks.

Found by the linter in #27897.
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented May 13, 2026

For the record, the new algorithm has a new class of false positives: for doc-strings which are indented, it warns too much.

@grunweg grunweg added the awaiting-author A reviewer has asked the author a question or requested changes. label May 13, 2026
@mathlib-dependent-issues mathlib-dependent-issues Bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants