Skip to content

Commit

Permalink
Add rule descriptions to SARIF output (#329)
Browse files Browse the repository at this point in the history
Now that the docstrings are in markdown format, we can safely add them
as rule descriptions to the SARIF output so we get better contextual
information on a result.

Signed-off-by: Eric Brown <[email protected]>
  • Loading branch information
ericwb authored Mar 7, 2024
1 parent 2d373a9 commit 4a385f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions precli/renderers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def create_rule_array(self, run: Run):
id=rule.id,
name=rule.__class__.__name__,
help_uri=rule.help_url,
short_description=sarif_om.MultiformatMessageString(
text=rule.short_description
),
full_description=sarif_om.MultiformatMessageString(
text=rule.full_description
),
message_strings={
"default": sarif_om.MultiformatMessageString(
text=rule.message
Expand Down
8 changes: 4 additions & 4 deletions precli/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ def name(self) -> str:
return self._name

@property
def short_descr(self) -> str:
def short_description(self) -> str:
"""
Short description of the rule.
:return: rule short description
:rtype: str
"""
try:
start = self._full_descr.rindex("===\n") + 4
start = self._full_descr.index("\n\n") + 2
except ValueError:
start = 0
try:
end = self._full_descr.index("\n---")
end = self._full_descr.index("\n##")
except ValueError:
end = len(self._full_descr)
return self._full_descr[start:end]

@property
def full_descr(self) -> str:
def full_description(self) -> str:
"""
Full description of the rule.
Expand Down

0 comments on commit 4a385f4

Please sign in to comment.