Skip to content
Merged
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
14 changes: 10 additions & 4 deletions src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import IO

import json

import tree_sitter_cfengine as tscfengine
from tree_sitter import Language, Parser, Node
from cfbs.pretty import pretty_file, pretty_check_file
Expand Down Expand Up @@ -46,10 +48,14 @@ def format_json_file(filename: str, check: bool) -> int:
print(f"JSON file '{filename}' needs reformatting")
return int(not success)

reformatted = pretty_file(filename)
if reformatted:
print(f"JSON file '{filename}' was reformatted")
return 0 # Successfully reformatted or no reformat needed
try:
reformatted = pretty_file(filename)
if reformatted:
print(f"JSON file '{filename}' was reformatted")
return 0 # Successfully reformatted or no reformat needed
except json.decoder.JSONDecodeError as e:
print(f"JSON file '{filename}' invalid ({str(e)})")
return 1


def text(node: Node) -> str:
Expand Down
Loading