Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/cfengine_cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
format_policy_fin_fout,
)
from cfengine_cli.utils import UserError
from cfbs.utils import find
from cfbs.commands import build_command
from cf_remote.commands import deploy as deploy_command

Expand Down Expand Up @@ -54,8 +53,6 @@ def _format_filename(filename: str, line_length: int, check: bool) -> int:
"""Format a single file.

Raises PolicySyntaxError for .cf files with syntax errors."""
if filename.startswith("./."):
return 0
if filename.endswith(".json"):
return format_json_file(filename, check)
if filename.endswith(".cf"):
Expand All @@ -65,10 +62,17 @@ def _format_filename(filename: str, line_length: int, check: bool) -> int:

def _format_dirname(directory: str, line_length: int, check: bool) -> int:
ret = 0
for filename in find(directory, extension=".json"):
ret |= _format_filename(filename, line_length, check)
for filename in find(directory, extension=".cf"):
ret |= _format_filename(filename, line_length, check)
for root, dirs, files in os.walk(directory):
# Don't recurse into hidden folders
dirs[:] = [d for d in dirs if not d.startswith(".")]
for name in sorted(files):
if name.startswith("."):
continue # Hidden files are ignored by default
if name.endswith(".x.cf"):
continue # Policy files with intentional mistakes
filepath = os.path.join(root, name)
if name.endswith(".json") or name.endswith(".cf"):
ret |= _format_filename(filepath, line_length, check)
return ret


Expand Down
2 changes: 2 additions & 0 deletions src/cfengine_cli/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ def _find_filenames_in_arg_folder(arg: str) -> list[str]:
for root, dirs, files in os.walk(arg, followlinks=True):
# Remove hidden files:
files = [f for f in files if not f[0] == "."]
# Skip .x.cf files (policy files with intentional errors):
files = [f for f in files if not f.endswith(".x.cf")]
for name in files:
if name.endswith(LINT_EXTENSIONS):
results.append(os.path.join(root, name))
Expand Down
Loading