Skip to content

Commit

Permalink
Merge pull request #81 from camptocamp/editor-config
Browse files Browse the repository at this point in the history
Editorconfig, don't test files not in Git
  • Loading branch information
sbrunner authored Feb 8, 2021
2 parents d938f01 + 391d67d commit 65ec1ff
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions c2cciutils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 65ec1ff

Please sign in to comment.