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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ venv:
format: venv
uv tool run black . --target-version py310
prettier . --write
uv run cfengine format ./

lint: venv
uv tool run black --check . --fast
uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160
uv tool run pyflakes src/
uv tool run pyright src/
uv run cfengine lint --strict=no ./
uv run cfengine format --check

install:
pipx install --force --editable .
Expand Down
4 changes: 3 additions & 1 deletion src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ def _format_block_header(node: Node, fmt: Formatter) -> list[Node]:
while prev_sib and prev_sib.type == "comment" and _is_empty_comment(prev_sib):
prev_sib = prev_sib.prev_named_sibling
is_macro_wrapped = (
prev_sib and prev_sib.type == "macro" and text(prev_sib).startswith("@if")
prev_sib
and prev_sib.type == "macro"
and text(prev_sib).startswith(("@if", "@else"))
)
if not (prev_sib and prev_sib.type == "comment") and not is_macro_wrapped:
fmt.blank_line()
Expand Down
14 changes: 14 additions & 0 deletions tests/format/011_macros.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,17 @@ bundle agent bundle_e
@endif
};
}

@if minimum_version(3.24)
bundle agent test(a, b)
{
reports:
"$(a) and $(b)";
}
@else
bundle agent test(a)
{
reports:
"$(a)";
}
@endif
13 changes: 13 additions & 0 deletions tests/format/011_macros.input.cf
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,16 @@ slist => {
@endif
};
}
@if minimum_version(3.24)
bundle agent test(a, b)
{
reports:
"$(a) and $(b)";
}
@else
bundle agent test(a)
{
reports:
"$(a)";
}
@endif
6 changes: 2 additions & 4 deletions tests/lint/015_macro_multi_def_bundle.cf
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ bundle agent main
{
methods:
@if minimum_version(3.24)
"test1"
usebundle => test("hello", "world");
"test1" usebundle => test("hello", "world");
@else
"test2"
usebundle => test("hello");
"test2" usebundle => test("hello");
@endif
}
3 changes: 1 addition & 2 deletions tests/lint/017_implies_body.cf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ body copy_from mycopy(from, server)
bundle agent main
{
files:
"/tmp/test"
copy_from => mycopy("/src", "host1");
"/tmp/test" copy_from => mycopy("/src", "host1");
}
8 changes: 4 additions & 4 deletions tests/lint/018_nested_calls.cf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ bundle agent helper(arg)
bundle agent main
{
files:
"/tmp/test"
copy_from => mycopy(readfile("/etc/source", "100"));
"/tmp/test" copy_from => mycopy(readfile("/etc/source", "100"));

methods:
"test"
usebundle => helper(format("hello %s", "world"));
"test" usebundle => helper(format("hello %s", "world"));

vars:
"x" string => format("nested: %s", getuid("root"));
}
Loading