Parse function natspec and add a missing-natspec detector - #3083
Open
ChrisJr404 wants to merge 1 commit into
Open
Parse function natspec and add a missing-natspec detector#3083ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1916. Functions now keep their natspec text so a detector can flag public/external functions that have none.
Today
Functiononly carries ahas_documentationbool the parser flips on, and the comment next to it says "To be improved". This wires it up properly. The solc parser already sees thedocumentationnode solc emits per function, so I pull the actual text out of it (plain string on old solc,{"text": ...}on newer) and store it.has_documentationbecomes a property derived from whether that text is present, so the existing caller (the natspec-generation tool) keeps working. Same treatment on the vyper side:doc_stringnow stores the text instead of just setting a flag.The new
missing-natspecdetector (informational) walks derived contracts and reports public/external functions with no natspec. Constructors, fallback/receive, and internal/private functions are skipped to keep it quiet, and dependency code is ignored.For tests I added
test_function_commentsto the parsing unit tests, which compiles a contract with a documented and an undocumented function and checks both the extracted text and the derived bool. There's also the usual e2e detector regression: a contract mixing a documented external fn, undocumented external/public fns, an internal fn, a constructor and a receive, plus the generated snapshot (only the two undocumented public/external fns get reported). Ran the detector e2e and the code-comments unit tests locally, both pass, ruff clean.The issue also mentions events, errors and state variables. I kept this to functions so it stays a focused replacement of the existing stub. Happy to follow up on the rest if you'd like it in the same detector.