diff --git a/crossplane/formatter.py b/crossplane/formatter.py
index fef2749..80c3b21 100644
--- a/crossplane/formatter.py
+++ b/crossplane/formatter.py
@@ -5,7 +5,13 @@ from .parser import parse
 
 
 def format(filename, indent=4, tabs=False):
-    payload = parse(filename, single=True, check_ctx=False, check_args=False)
+    payload = parse(
+        filename,
+        comments=True,
+        single=True,
+        check_ctx=False,
+        check_args=False
+    )
 
     if payload['status'] != 'ok':
         e = payload['errors'][0]

feat: keep certain newlines and comments
Keeping comments is great as it allows users to understand complex changes quickly, while newlines in key positions help with readability.
diff --git a/tests/test_format.py b/tests/test_format.py
index 3c32bda..d116572 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -11,10 +11,12 @@ def test_format_messy_config():
     output = crossplane.format(config)
     assert output == '\n'.join([
         'user nobody;',
+        r'# hello\n\\n\\\n worlddd  \#\\#\\\# dfsf\n \\n \\\n ',
         'events {',
         '    worker_connections 2048;',
         '}',
-        'http {',
+        'http { #forteen',
+        '    # this is a comment',
         '    access_log off;',
         '    default_type text/plain;',
         '    error_log off;',
@@ -33,7 +35,7 @@ def test_format_messy_config():
         '        location /bar {',
         '        }',
         '        location /\{\;\}\ #\ ab {',
-        '        }',
+        '        } # hello',
         '        if ($request_method = P\{O\)\###\;ST) {',
         '        }',
         '        location /status.html {',
@@ -75,3 +77,25 @@ def test_format_args_not_analyzed():
         'http {',
         '}'
     ])
+
+
+def test_format_with_comments():
+    dirname = os.path.join(here, 'configs', 'with-comments')
+    config = os.path.join(dirname, 'nginx.conf')
+    output = crossplane.format(config)
+    assert output == '\n'.join([
+        'events {',
+        '    worker_connections 1024;',
+        '}',
+        '#comment',
+        'http {',
+        '    server {',
+        '        listen 127.0.0.1:8080; #listen',
+        '        server_name default_server;',
+        '        location / { ## this is brace',
+        '            # location /',
+        "            return 200 'foo bar baz';",
+        '        }',
+        '    }',
+        '}'
+    ])

pip install -e .
parse_log_pytest
pytest
pytest tox
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
-e git+https://github.com/nginxinc/crossplane.git@59186f5785c72062656f5e160f08002b3e2c9888#egg=crossplane
distlib==0.3.9
filelock==3.4.1
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
platformdirs==2.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
six==1.17.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tox==3.28.0
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
virtualenv==20.17.1
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: crossplane
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - distlib==0.3.9
      - filelock==3.4.1
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - platformdirs==2.4.0
      - six==1.17.0
      - tox==3.28.0
      - virtualenv==20.17.1
prefix: /opt/conda/envs/crossplane

tests/test_format.py::test_format_messy_config tests/test_format.py::test_format_with_comments
tests/test_format.py::test_format_not_main_file tests/test_format.py::test_format_args_not_analyzed
crossplane/formatter.py
crossplane/formatter.py