From 7fe738e28f534b357e78dfa3850a7b9526897ec5 Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Sun, 9 Jul 2023 22:18:01 +0200 Subject: [PATCH] introduce flake8-no-implicit-concat linter --- capa/ida/plugin/form.py | 14 +++++++------- capa/main.py | 12 ++++++------ scripts/lint.py | 4 ++-- setup.py | 1 + 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index dea54faa..7abfb440 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -585,7 +585,7 @@ class CapaExplorerForm(idaapi.PluginForm): rules_message.setText("You must specify a directory containing capa rules before running analysis.") rules_message.setInformativeText( "Click 'Ok' to specify a local directory of rules or you can download and extract the official " - "rules from the URL listed in the details." + + "rules from the URL listed in the details." ) rules_message.setDetailedText(f"{CAPA_OFFICIAL_RULESET_URL}") rules_message.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) @@ -646,9 +646,9 @@ class CapaExplorerForm(idaapi.PluginForm): logger.error("Failed to load capa rules from %s (error: %s).", settings.user[CAPA_SETTINGS_RULE_PATH], e) logger.error( - "Make sure your file directory contains properly " - "formatted capa rules. You can download and extract the official rules from %s. " - "Or, for more details, see the rules documentation here: %s", + "Make sure your file directory contains properly " # noqa: G003 [logging statement uses +] + + "formatted capa rules. You can download and extract the official rules from %s. " + + "Or, for more details, see the rules documentation here: %s", CAPA_OFFICIAL_RULESET_URL, CAPA_RULESET_DOC_URL, ) @@ -948,9 +948,9 @@ class CapaExplorerForm(idaapi.PluginForm): "Reanalyze program", "", ida_kernwin.ASKBTN_YES, - f"This database contains capa results generated on " - f"{results.meta.timestamp.strftime('%Y-%m-%d at %H:%M:%S')}.\n" - f"Load existing data or analyze program again?", + "This database contains capa results generated on " + + results.meta.timestamp.strftime("%Y-%m-%d at %H:%M:%S") + + ".\nLoad existing data or analyze program again?", ) if btn_id == ida_kernwin.ASKBTN_CANCEL: diff --git a/capa/main.py b/capa/main.py index 37765c9a..20d5c609 100644 --- a/capa/main.py +++ b/capa/main.py @@ -555,7 +555,7 @@ def get_extractor( except ImportError: raise RuntimeError( "Cannot import binaryninja module. Please install the Binary Ninja Python API first: " - "https://docs.binary.ninja/dev/batch.html#install-the-api)." + + "https://docs.binary.ninja/dev/batch.html#install-the-api)." ) import capa.features.extractors.binja.extractor @@ -1069,9 +1069,9 @@ def handle_common_args(args): sigs_path = os.path.join(get_default_root(), "sigs") if not os.path.exists(sigs_path): logger.error( - "Using default signature path, but it doesn't exist. " - "Please install the signatures first: " - "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library." + "Using default signature path, but it doesn't exist. " # noqa: G003 [logging statement uses +] + + "Please install the signatures first: " + + "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library." ) raise IOError(f"signatures path {sigs_path} does not exist or cannot be accessed") else: @@ -1170,8 +1170,8 @@ def main(argv=None): except (IOError, capa.rules.InvalidRule, capa.rules.InvalidRuleSet) as e: logger.error("%s", str(e)) logger.error( - "Make sure your file directory contains properly formatted capa rules. You can download the standard " - "collection of capa rules from https://github.com/mandiant/capa-rules/releases." + "Make sure your file directory contains properly formatted capa rules. You can download the standard " # noqa: G003 [logging statement uses +] + + "collection of capa rules from https://github.com/mandiant/capa-rules/releases." ) logger.error( "Please ensure you're using the rules that correspond to your major version of capa (%s)", diff --git a/scripts/lint.py b/scripts/lint.py index 32c28995..43b9dee8 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -516,7 +516,7 @@ class FeatureNegativeNumber(Lint): recommendation = "specify the number's two's complement representation" recommendation_template = ( "capa treats number features as unsigned values; you may specify the number's two's complement " - 'representation; will not match on "{:d}"' + + 'representation; will not match on "{:d}"' ) def check_features(self, ctx: Context, features: List[Feature]): @@ -534,7 +534,7 @@ class FeatureNtdllNtoskrnlApi(Lint): level = Lint.WARN recommendation_template = ( "check if {:s} is exported by both ntdll and ntoskrnl; if true, consider removing {:s} " - "module requirement to improve detection" + + "module requirement to improve detection" ) def check_features(self, ctx: Context, features: List[Feature]): diff --git a/setup.py b/setup.py index 6b2997d6..ef9b3465 100644 --- a/setup.py +++ b/setup.py @@ -79,6 +79,7 @@ setuptools.setup( "flake8-encodings==0.5.0.post1", "flake8-comprehensions==3.13.0", "flake8-logging-format==0.9.0", + "flake8-no-implicit-concat==0.3.4", "ruff==0.0.275", "black==23.3.0", "isort==5.11.4",