Skip to content

Commit d38f0af

Browse files
authored
Merge pull request #60 from olehermanse/small
Added prettier to GH Actions and shell test for cfengine format --check
2 parents fae3057 + 8b6007a commit d38f0af

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

.github/workflows/lint.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ jobs:
2626
run: |
2727
python -m pip install --upgrade pip
2828
python -m pip install uv
29+
sudo apt-get install npm
30+
npm install --global prettier
2931
- name: Setup
3032
run: |
3133
uv venv
3234
uv sync
3335
- name: Check formatting with black
3436
run: |
3537
uv tool run black --check .
38+
- name: Check formatting with prettier
39+
run: |
40+
prettier . --check
3641
- name: Run flake8
3742
run: |
3843
uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160

.github/workflows/update-syntax-description.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
run: |
3232
python -m pip install --upgrade pip
3333
python -m pip install cf-remote
34+
sudo apt-get install npm
35+
npm install --global prettier
3436
- name: Install cfengine
3537
run: |
3638
cf-remote --version master download --edition community ubuntu24 amd64 hub
@@ -41,7 +43,7 @@ jobs:
4143
(
4244
sudo cf-promises --syntax-description json
4345
) > new.json
44-
echo "" >> new.json
46+
prettier new.json --write
4547
- name: Set Git user
4648
run: |
4749
git config user.name 'github-actions[bot]'

src/cfengine_cli/syntax-description.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,13 +3258,7 @@
32583258
"status": "normal"
32593259
},
32603260
"common": {
3261-
"promiseTypes": [
3262-
"classes",
3263-
"defaults",
3264-
"meta",
3265-
"reports",
3266-
"vars"
3267-
],
3261+
"promiseTypes": ["classes", "defaults", "meta", "reports", "vars"],
32683262
"status": "normal"
32693263
},
32703264
"edit_line": {

tests/shell/004-format-check.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
# Setup: create a temp directory for test files
7+
tmpdir=$(mktemp -d)
8+
trap "rm -rf $tmpdir" EXIT
9+
10+
write_formatted() {
11+
printf 'bundle agent main\n{\n vars:\n "v" string => "hello";\n}\n' > "$1"
12+
}
13+
14+
write_unformatted() {
15+
printf 'bundle agent main { vars: "v" string => "hello"; }\n' > "$1"
16+
}
17+
18+
# Case 1: format without --check on already-formatted file -> exit 0
19+
write_formatted "$tmpdir/good.cf"
20+
cfengine format "$tmpdir/good.cf"
21+
22+
# Case 2: format without --check on unformatted file -> exit 0 (reformats it)
23+
write_unformatted "$tmpdir/bad.cf"
24+
cfengine format "$tmpdir/bad.cf"
25+
# Verify it was actually reformatted to the correct output
26+
write_formatted "$tmpdir/expected.cf"
27+
diff "$tmpdir/expected.cf" "$tmpdir/bad.cf"
28+
29+
# Case 3: --check on already-formatted file -> exit 0
30+
write_formatted "$tmpdir/good2.cf"
31+
cfengine format --check "$tmpdir/good2.cf"
32+
33+
# Case 4: --check on unformatted file -> exit 1
34+
write_unformatted "$tmpdir/bad2.cf"
35+
cp "$tmpdir/bad2.cf" "$tmpdir/bad2_orig.cf"
36+
if cfengine format --check "$tmpdir/bad2.cf"; then
37+
echo "FAIL: expected exit code 1 for --check on unformatted file"
38+
exit 1
39+
fi
40+
# Verify the file was NOT modified
41+
diff "$tmpdir/bad2_orig.cf" "$tmpdir/bad2.cf"

0 commit comments

Comments
 (0)