From 4a385f45a2e86d324200c375a2673f7e009d44c1 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Wed, 6 Mar 2024 22:53:17 -0800 Subject: [PATCH] Add rule descriptions to SARIF output (#329) 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 --- precli/renderers/json.py | 6 ++++++ precli/rules/__init__.py | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/precli/renderers/json.py b/precli/renderers/json.py index 95e4e013..55078830 100644 --- a/precli/renderers/json.py +++ b/precli/renderers/json.py @@ -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 diff --git a/precli/rules/__init__.py b/precli/rules/__init__.py index 767156a8..12e17250 100644 --- a/precli/rules/__init__.py +++ b/precli/rules/__init__.py @@ -76,7 +76,7 @@ def name(self) -> str: return self._name @property - def short_descr(self) -> str: + def short_description(self) -> str: """ Short description of the rule. @@ -84,17 +84,17 @@ def short_descr(self) -> str: :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.