Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track function natspec comments #2251

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None:

# To be improved with a parsing of the documentation
self.has_documentation: bool = False
self._comments: Optional[str] = None

###################################################################################
###################################################################################
Expand Down Expand Up @@ -363,6 +364,20 @@ def id(self) -> Optional[str]:
def id(self, new_id: str):
self._id = new_id

@property
def comments(self) -> Optional[str]:
"""
Return the comments associated with the function.

Returns:
the comment as a string
"""
return self._comments

@comments.setter
def comments(self, comments: str):
self._comments = comments

@property
@abstractmethod
def file_scope(self) -> "FileScope":
Expand Down
17 changes: 17 additions & 0 deletions slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ def __init__(
if "documentation" in function_data:
function.has_documentation = True

# Old solc versions store the comment in attributes["documentation"]
# More recent ones store it in attributes["documentation"]["text"]
if (
"documentation" in function_data
and function_data["documentation"] is not None
and (
"text" in function_data["documentation"]
or isinstance(function_data["documentation"], str)
)
):
text = (
function_data["documentation"]
if isinstance(function_data["documentation"], str)
else function_data["documentation"]["text"]
)
self._function.comments = text

@property
def underlying_function(self) -> Function:
return self._function
Expand Down