Skip to content
Permalink
Browse files

Don't remove comments when formatting

  • Loading branch information
aluttik committed Apr 30, 2019
1 parent 59186f5 commit ad643a0308d3dcc43d37e323c478a784747b4a67
Showing with 33 additions and 3 deletions.
  1. +7 −1 crossplane/formatter.py
  2. +26 −2 tests/test_format.py
@@ -5,7 +5,13 @@


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]
@@ -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';",
' }',
' }',
'}'
])

0 comments on commit ad643a0

Please sign in to comment.
You can’t perform that action at this time.