From 370463ada73e5576d2f34b0a7b6400633c004d02 Mon Sep 17 00:00:00 2001 From: Yuguang Wang Date: Wed, 20 Mar 2024 17:46:06 +0800 Subject: [PATCH] plugins/semgrep: fix lint warnings --- py/plugins/semgrep.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/py/plugins/semgrep.py b/py/plugins/semgrep.py index 05aec11..7f165d4 100644 --- a/py/plugins/semgrep.py +++ b/py/plugins/semgrep.py @@ -15,6 +15,9 @@ # You should have received a copy of the GNU General Public License # along with csmock. If not, see . +""" +Semgrep client plugin +""" import os # disable metrics to be sent to semgrep cloud @@ -34,7 +37,10 @@ SEMGREP_SCAN_LOG = "/builddir/semgrep-scan.log" -class PluginProps: +class PluginProps: # pylint: disable=too-few-public-methods + """ + Props of the plugin + """ def __init__(self): self.description = ( "A fast, open-source, static analysis engine for finding bugs, " @@ -45,13 +51,16 @@ def __init__(self): class Plugin: + """ + Semgrep static analysis engine plugin + """ def __init__(self): self.enabled = False - def get_props(self): + def get_props(self): # pylint: disable=missing-function-docstring return PluginProps() - def enable(self): + def enable(self): # pylint: disable=missing-function-docstring self.enabled = True def init_parser(self, parser): @@ -80,13 +89,12 @@ def init_parser(self, parser): help="space-separated list of additional options passed to the 'semgrep scan' command", ) - def handle_args(self, parser, args, props): + def handle_args(self, parser, args, props): # pylint: disable=too-many-statements,missing-function-docstring if not self.enabled: return if not args.semgrep_rules_repo: parser.error("'--semgrep-rules-repo' is required to run semgrep scan") - return 1 # install semgrep cli and download semgrep rules def prepare_semgrep_runtime_hook(results, props): @@ -138,7 +146,7 @@ def prepare_semgrep_runtime_hook(results, props): props.pre_mock_hooks += [prepare_semgrep_runtime_hook] - def scan_hook(results, mock, props): + def scan_hook(results, mock, props): # pylint: disable=unused-argument semgrep_lib_dir = os.path.join(results.tmpdir, "semgrep_lib") semgrep_prefix = f"env PATH={semgrep_lib_dir}/bin:$PATH PYTHONPATH={semgrep_lib_dir}" # assuming semgrep rules are located under the 'rules' directory @@ -204,8 +212,8 @@ def filter_hook(results): # in its rules path. The following sed command strips suspicious path prefixes by removing # any sequence of non left-square-bracket characters preceding '{tmp_path}' cmd = ( - f"csgrep {src} --mode=json --strip-path-prefix {chroot_root_path}{SEMGREP_SCAN_DIR}/" - f" | sed 's|[^\[]*{tmp_path}||' > {dst}" + fr"csgrep {src} --mode=json --strip-path-prefix {chroot_root_path}{SEMGREP_SCAN_DIR}/ " + fr"| sed 's|[^\[]*{tmp_path}||' > {dst}" # pylint: disable=W1401 ) return results.exec_cmd(cmd, shell=True)