From e3a35199135dac3dd82a61f3eaf693d1a9a8d493 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 23 Aug 2021 16:58:26 -0700 Subject: [PATCH] semgrep: Replace pattern-where-python with metavariable-regex. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pattern-where-python is deprecated and doesn’t work in 0.62.0. This should be faster, too. Signed-off-by: Anders Kaseorg --- tools/semgrep.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/semgrep.yml b/tools/semgrep.yml index f3012948f1..d0dc16cc5d 100644 --- a/tools/semgrep.yml +++ b/tools/semgrep.yml @@ -45,11 +45,24 @@ rules: languages: [python] patterns: - pattern-either: - - pattern: logging.$Y(... .format(...)) - - pattern: logging.$Y(f"...") - - pattern: logger.$Y(... .format(...)) - - pattern: logger.$Y(f"...") - - pattern-where-python: "vars['$Y'] in ['debug', 'info', 'warning', 'error', 'critical', 'exception']" + - pattern: $LOGGER.debug($FORMATTED) + - pattern: $LOGGER.info($FORMATTED) + - pattern: $LOGGER.warning($FORMATTED) + - pattern: $LOGGER.error($FORMATTED) + - pattern: $LOGGER.critical($FORMATTED) + - pattern: $LOGGER.exception($FORMATTED) + - metavariable-pattern: + metavariable: $LOGGER + patterns: + - pattern-either: + - pattern: logging + - pattern: logger + - metavariable-pattern: + metavariable: $FORMATTED + patterns: + - pattern-either: + - pattern: ... .format(...) + - pattern: f"..." severity: ERROR message: "Pass format arguments to logging (https://docs.python.org/3/howto/logging.html#optimization)"