From 994c5e1e6bdc13cf8597457f68da60b51f648889 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 22 Apr 2026 16:11:28 +0200 Subject: [PATCH 1/2] Skipped .x.cf files by default in lint and format Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/commands.py | 2 ++ src/cfengine_cli/lint.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/cfengine_cli/commands.py b/src/cfengine_cli/commands.py index f7f45d8..16e367c 100644 --- a/src/cfengine_cli/commands.py +++ b/src/cfengine_cli/commands.py @@ -68,6 +68,8 @@ def _format_dirname(directory: str, line_length: int, check: bool) -> int: for filename in find(directory, extension=".json"): ret |= _format_filename(filename, line_length, check) for filename in find(directory, extension=".cf"): + if filename.endswith(".x.cf"): + continue ret |= _format_filename(filename, line_length, check) return ret diff --git a/src/cfengine_cli/lint.py b/src/cfengine_cli/lint.py index 9c3944c..8c33a79 100644 --- a/src/cfengine_cli/lint.py +++ b/src/cfengine_cli/lint.py @@ -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)) From 6c1b8bdfdf21c42635cc6112179da4f7b5d06c76 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 22 Apr 2026 16:38:21 +0200 Subject: [PATCH 2/2] cfengine format: Fixed skipping of hidden files Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/commands.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cfengine_cli/commands.py b/src/cfengine_cli/commands.py index 16e367c..48e071e 100644 --- a/src/cfengine_cli/commands.py +++ b/src/cfengine_cli/commands.py @@ -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 @@ -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"): @@ -65,12 +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"): - if filename.endswith(".x.cf"): - continue - 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