From 391d67da5ca937d844623600155b4e800d49c1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Sat, 26 Dec 2020 16:06:39 +0100 Subject: [PATCH] Editorconfig, don't test files not in Git --- c2cciutils/checks.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/c2cciutils/checks.py b/c2cciutils/checks.py index b389cee4c..2ec30c99c 100644 --- a/c2cciutils/checks.py +++ b/c2cciutils/checks.py @@ -115,22 +115,21 @@ def editorconfig(config, full_config, args): success = True for pattern, wanted_properties in config.get("properties", {}).items(): try: - file_ = next(glob.iglob("**/" + pattern, recursive=True)) - properties = get_properties(os.path.abspath(file_)) - - for key, value in wanted_properties.items(): - if value is not None and (key not in properties or properties[key] != value): - error( - "editorconfig", - "For pattern: {} the property '{}' is '{}' but should be '{}'.".format( - pattern, key, properties.get(key, ""), value - ), - ".editorconfig", - ) - success = False - except StopIteration: - # If the pattern is not founf the check is disable for this pattern - pass + for filename in subprocess.check_output(["git", "ls-files", pattern]).decode().split("\n"): + if os.path.isfile(filename): + properties = get_properties(os.path.abspath(filename)) + + for key, value in wanted_properties.items(): + if value is not None and (key not in properties or properties[key] != value): + error( + "editorconfig", + "For pattern: {} the property '{}' is '{}' but should be '{}'.".format( + pattern, key, properties.get(key, ""), value + ), + ".editorconfig", + ) + success = False + break except EditorConfigError: error( "editorconfig",