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
19 changes: 11 additions & 8 deletions src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,17 @@ def _needs_blank_line_before(child: Node, indent: int, line_length: int) -> bool
return True
if parent and parent.type in {"bundle_section", "class_guarded_promises"}:
return prev.type in {"promise", "half_promise"} | CLASS_GUARD_TYPES
if parent and parent.type in {"body_block_body", "promise_block_body"}:
next_sib = _skip_comments(child.next_named_sibling, "next")
if next_sib is None:
return False
# Leading comment for a class-guarded section preceded by
# content above it.
if next_sib.type in CLASS_GUARD_TYPES:
return prev.type in CLASS_GUARD_TYPES | {"attribute"}
if parent and parent.type in {
"body_block_body",
"promise_block_body",
"class_guarded_body_attributes",
}:
# A comment is separated by a blank line from a preceding
# attribute or a preceding class-guarded block, so it reads as
# a leading comment for what follows (or a trailing comment for
# the block). This mirrors how a comment after a promise is
# separated in bundles.
return prev.type == "attribute" or prev.type in CLASS_GUARD_TYPES
return False

return False
Expand Down
7 changes: 7 additions & 0 deletions tests/format/004_comments.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ body package_method apt
package_list_command => "/usr/bin/dpkg -l";
package_list_name_regex => "ii\s+([^\s]+).*";
package_list_version_regex => "ii\s+[^\s]+\s+([^\s]+).*";

# package_list_arch_regex => "none";
package_installed_regex => ".*";

# all reported are installed:
# package_name_convention => "$(name)_$(version)_$(arch)";
package_name_convention => "$(name)";

# Use these only if not using a separate version/arch string:
# package_version_regex => "";
# package_name_regex => "";
# package_arch_regex => "";
package_add_command => "/usr/bin/apt-get --yes install";
package_delete_command => "/usr/bin/apt-get --yes remove";
package_update_command => "/usr/bin/apt-get --yes dist-upgrade";

# package_verify_command => "/bin/rpm -V";
}

Expand All @@ -107,13 +111,15 @@ body package_method ca
body package_method ac
{
package_changes => "bulk";

# bar
}

body package_method cac
{
# foo
package_changes => "bulk";

# bar
}

Expand All @@ -129,6 +135,7 @@ body package_method cgcac
linux::
# bar
package_changes => "bulk";

# baz
}

Expand Down
1 change: 1 addition & 0 deletions tests/format/011_promises.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ body common control
any::
ignore_missing_bundles => "$(def.control_common_ignore_missing_bundles)";
ignore_missing_inputs => "$(def.control_common_ignore_missing_inputs)";

# The number of minutes after which last-seen entries are purged from cf_lastseen.lmdb
lastseenexpireafter => "$(def.control_common_lastseenexpireafter)";

Expand Down
Loading