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
5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install uv
sudo apt-get install npm
npm install --global prettier
- name: Setup
run: |
uv venv
uv sync
- name: Check formatting with black
run: |
uv tool run black --check .
- name: Check formatting with prettier
run: |
prettier . --check
- name: Run flake8
run: |
uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/update-syntax-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install cf-remote
sudo apt-get install npm
npm install --global prettier
- name: Install cfengine
run: |
cf-remote --version master download --edition community ubuntu24 amd64 hub
Expand All @@ -41,7 +43,7 @@ jobs:
(
sudo cf-promises --syntax-description json
) > new.json
echo "" >> new.json
prettier new.json --write
- name: Set Git user
run: |
git config user.name 'github-actions[bot]'
Expand Down
8 changes: 1 addition & 7 deletions src/cfengine_cli/syntax-description.json
Original file line number Diff line number Diff line change
Expand Up @@ -3258,13 +3258,7 @@
"status": "normal"
},
"common": {
"promiseTypes": [
"classes",
"defaults",
"meta",
"reports",
"vars"
],
"promiseTypes": ["classes", "defaults", "meta", "reports", "vars"],
"status": "normal"
},
"edit_line": {
Expand Down
41 changes: 41 additions & 0 deletions tests/shell/004-format-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -e
set -x

# Setup: create a temp directory for test files
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT

write_formatted() {
printf 'bundle agent main\n{\n vars:\n "v" string => "hello";\n}\n' > "$1"
}

write_unformatted() {
printf 'bundle agent main { vars: "v" string => "hello"; }\n' > "$1"
}

# Case 1: format without --check on already-formatted file -> exit 0
write_formatted "$tmpdir/good.cf"
cfengine format "$tmpdir/good.cf"

# Case 2: format without --check on unformatted file -> exit 0 (reformats it)
write_unformatted "$tmpdir/bad.cf"
cfengine format "$tmpdir/bad.cf"
# Verify it was actually reformatted to the correct output
write_formatted "$tmpdir/expected.cf"
diff "$tmpdir/expected.cf" "$tmpdir/bad.cf"

# Case 3: --check on already-formatted file -> exit 0
write_formatted "$tmpdir/good2.cf"
cfengine format --check "$tmpdir/good2.cf"

# Case 4: --check on unformatted file -> exit 1
write_unformatted "$tmpdir/bad2.cf"
cp "$tmpdir/bad2.cf" "$tmpdir/bad2_orig.cf"
if cfengine format --check "$tmpdir/bad2.cf"; then
echo "FAIL: expected exit code 1 for --check on unformatted file"
exit 1
fi
# Verify the file was NOT modified
diff "$tmpdir/bad2_orig.cf" "$tmpdir/bad2.cf"
Loading