Giter Club home page Giter Club logo

nginx-config-formatter's People

Contributors

rickiel avatar slomkowski avatar stoffus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-config-formatter's Issues

errounous semicolon after single-line location block

Reported in NixOS/nixpkgs#57979 (comment):

The following configuration:

location /example { allow 192.168.0.0/16; deny all; }

results in

  location /example {
    allow 192.168.0.0/16;
    deny all;
  }
  ;

the trailing ; will produce an error message in nginx like this:

апр 08 14:55:45 web.elven.pw systemd[1]: Starting Nginx Web Server...
апр 08 14:55:45 web.elven.pw pnzhwc1q1is8vbdkg34ksicqq9jh5chc-unit-script-nginx-pre-start[2430]: nginx: [emerg] unexpected ";" in /nix/store/glvppaxv9gqg9vj179ph9rmj8yg41d72-nginx.conf:151

The nginx version is 1.14.2.

No need special treatment for variable `${aaa}`

No need special treatment for variable ${} , because any expression with "{" should be enclosed in single or double quotes.

So, we just need to substitute { and } in single or double quotes.

Use as Library

Any issues with this being refactored to work as a library? I'm working on a project which uses this but at the moment which uses nginxfmt.py but I'd ideally like to reference this as a pip package instead, or at the very least a git package link.

deploy online with a GUI

nginxbeautifier.com seems to be offline. would be great if there was an online version of this for easy use without installing local packages.

unmatched single-quote in comments breaking parsing

given:

location /nginx_status {
# Don't break 
    stub_status on;
  access_log off;
  allow 127.0.0.1;
    deny all;
}

we expect:

location /nginx_status {
    # Don't break
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
}

but instead we get:

location /nginx_status {
    # Don't break
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
    }

and all subsequent lines are aligned to the indentation of the comment with ' in it. Looks like it's trying to parse the comment as an nginx string and then never escaping the comment alignment? Probably related to #11.

May be add 4 space after proxy_set_header for improve readability?

May be add 4 space after proxy_set_header for improve readability?
Before

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;

After

    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-Host $host;
    proxy_set_header    X-Forwarded-Server $host;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Real-IP $remote_addr;

Multiline values formatting

This (it comes from sample nginx magento snippet)

gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;

is converted to

gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/xml+rss
image/svg+xml;

Could it format such multiline values the padded way?

Normalization inside comments

Normalization inside comments is required, if possible, after position alignment.

Input data:

http {
    #log_format  main  "......."
    #                  "....";
#                      '....';
     #             "....";
  #                    '....';
}

Output result

http {
    #log_format  main  "......."
    #                  "....";
    #                      '....'; < unalignment
    #             "...."; < unalignment
    #                    '....'; < unalignment
}

parsing regex in server_name

server_name "~^(?<tag>[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12})\.a\.b\.com$";

will be splitted into multiple line

Breaks add_header alt-svc

add_header alt-svc 'h3=":443"; ma=86400, h3-29=":443"; ma=86400' always;

will be break into 3 lines and like this:

add_header alt-svc 'h3=":443";
ma=86400, h3-29=":443";
ma=86400' always;

Though it passes the nginx conf test but SSL will break.

Add option to print formatted contents to stdout

Hi, this is a feature request for an option to print the formatted contents to stdout without saving them to a file. This would allow to use this program with formatting tools that work with stdin/stdout such as vim-autoformat. The stdin can already be handled by passing /dev/stdin as the filename. Should be relatively simple to implement, if you want, I could whip up a pull request.

invalid variable name with $

server {
    listen 80 default_server;
    server_name localhost;
    location / {
        proxy_set_header X-User-Authorization "Internal ${cookie_access_token}";
    }
}

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

server {
    listen 80 default_server;
    server_name localhost;
    location / {
        proxy_set_header X-User-Authorization "Internal $ {
            cookie_access_token
        }
        ";
    }
}

nginx: [emerg] invalid variable name in /etc/nginx/nginx.conf:63
nginx: configuration file /etc/nginx/nginx.conf test failed

add_header

Input data:

http {
    server {
        listen 80;
        # add_header Strict-Transport-Security "max-age=3600; includeSubDomains";
        add_header Strict-Transport-Security "max-age=3600; includeSubDomains";
    }
}

Output result

http {
    server {
        listen 80;
        # add_header Strict-Transport-Security "max-age=3600; includeSubDomains";
        add_header Strict-Transport-Security "max-age=3600;
        includeSubDomains";
    }
}

Other NGINX config formatter (AWK): https://github.com/lovette/nginx-tools/tree/master/nginx-minify-conf

log_format

Multiline log_format does not correction the alignment

Input data:

http {
    log_format  main  '.......'
                     '....';
}

Output result

http {
    log_format  main  '.......'
    '....';
}

Comment EOL

I think the transfer of the review to a new position should occur on the line above or not occur quite

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.