Skip to content

[Merged by Bors] - feat: the doc-string linter#22095

Closed
adomani wants to merge 80 commits intomasterfrom
adomani/docstring_linter
Closed

[Merged by Bors] - feat: the doc-string linter#22095
adomani wants to merge 80 commits intomasterfrom
adomani/docstring_linter

Conversation

@adomani
Copy link
Copy Markdown
Contributor

@adomani adomani commented Feb 19, 2025

The docString linter checks that doc-strings begin with

  • /-- <Text> or
  • /--⏎<Text>

and that <Text> does not begin with a space or a line break. Similarly for the characters preceding -/ at the end of a doc-string.

Discussed in Zulip


Open in Gitpod

@adomani adomani marked this pull request as draft February 19, 2025 17:35
@adomani adomani added the WIP Work in progress label Feb 19, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 19, 2025

PR summary 5b889058df

Import changes exceeding 2%

% File
+5.26% Mathlib.Init
+2.78% Mathlib.Logic.Function.Defs
+5.00% Mathlib.Tactic.FunProp.Decl

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
There are 5984 files with changed transitive imports taking up over 249633 characters: this is too many to display!
You can run scripts/import_trans_difference.sh all locally to see the whole output.

Declarations diff

+ docStringLinter
+ foo

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


Increase in tech debt: (relative, absolute) = (2.00, 0.02)
Current number Change Type
100 2 adaptation notes

Current commit 5b889058df
Reference commit 062d4014b7

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-linter Linter label Feb 19, 2025
@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Feb 19, 2025
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Feb 19, 2025

If we do a better job at tracking where the exceptions are, the warning can be logged "at" the right positions in the string and highlight what they refer to.

Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Feb 19, 2025

You can take a look at

https://github.com/leanprover-community/mathlib4/pull/new/adomani/docstring_linter_range

for a start at getting the warning where the issue is. The ppRoundtrip linter also has a mechanism to try to underline where the issue are.

Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
if lines.any (·.startsWith " ")
-- For now, we skip cases where a line starts with "* " or "- " as these are probably markdown
-- code blocks. (We can later try to re-enable some linting there.)
&& !lines.any (fun l ↦ l.startsWith "* " || l.startsWith "- ") then
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.

How about including also ``` as an allowed start for exceptions?

Overall, I am still not sold on this check, as I find that it would require a more thorough parsing of markdown to really be effective.

Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

I just took a look: I think the implementation looks good, just minor comments.
I don't think the empty doc-strings need to block this from landing (as they are pre-existing). One could add an "empty doc-string linter" which complains about these specifically (the current error is not great), and also searches for e.g. doc-strings which are just TODO or TODO!. That can happen in a follow-up, though.

Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread MathlibTest/LintDocstring.lean
@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Feb 27, 2025

(Let me add: I think this is basically ready to be maintainer merged, with the question of these doc-strings being the biggest open item.)

@grunweg grunweg added the awaiting-author A reviewer has asked the author a question or requested changes. label Feb 27, 2025
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.

Michael, thank you so much for the review!

Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Feb 28, 2025

With respect to "empty" docstrings, I think that we can test whether a trimmed docstring contains no space and emit a warning then, with a more meaningful comment, such as "A doc-string that has at most one word is probably not a good docstring!" or something like this.

I would leave this for later, though.

@adomani adomani removed the awaiting-author A reviewer has asked the author a question or requested changes. label Feb 28, 2025
Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

Thanks; I like your changes. Just two more nits.
Note to maintainers: this PR adds three manual linter exceptions, to declarations with an essentially empty doc-string. These were pre-existing; I don't think this PR should be blocked on that.
maintainer delegate

Comment thread Mathlib/Tactic/Linter.lean Outdated
Comment thread Mathlib/Tactic/Linter/DocString.lean Outdated
@github-actions
Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by grunweg.

@github-actions github-actions bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Feb 28, 2025
@PatrickMassot
Copy link
Copy Markdown
Member

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 7, 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.

@ghost ghost added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Mar 7, 2025
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Mar 7, 2025

bors merge

@ghost ghost added the ready-to-merge This PR has been sent to bors. label Mar 7, 2025
mathlib-bors bot pushed a commit that referenced this pull request Mar 7, 2025
The `docString` linter checks that doc-strings begin with
* `/-- <Text>` or
* `/--⏎<Text>`

and that `<Text>` does not begin with a space or a line break.  Similarly for the characters preceding `-/` at the end of a doc-string.

Discussed in [Zulip](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Style.20.3Abicycle.3A.20.3A.20indenting.20second.20lines.20in.20doc-strings)
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 7, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: the doc-string linter [Merged by Bors] - feat: the doc-string linter Mar 7, 2025
@mathlib-bors mathlib-bors bot closed this Mar 7, 2025
@mathlib-bors mathlib-bors bot deleted the adomani/docstring_linter branch March 7, 2025 14:33
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.

5 participants