Giter Club home page Giter Club logo

vscode-nginx-formatter's Introduction

Nginx Formatter

Simply formats your NGINX Configurations

Usage

  1. Open a Document
  2. Make sure the File Association is set to NGINX
  3. Press Strg + Alt + F or select 'Format Document' from the command selection
  4. Your NGINX Configuration should be formatted properly

Usage Gif

Used Libaries

vscode-nginx-formatter's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar mergify[bot] avatar raynigon avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

weifding yoshi325

vscode-nginx-formatter's Issues

Formatting introduces huge alignment spaces, introduces root spaces

Example:

Pre-Format

worker_processes 5;
worker_rlimit_nofile 8192;

events {
    worker_connections 4096;
}

http {
    client_max_body_size 10m;

    server {
        listen 8443 default_server ssl http2 reuseport;

        ssl_certificate /certs/certificate.crt;
        ssl_certificate_key /certs/privateKey.key;

        server_name _;

        keepalive_timeout 620s;

        location / {
            root /data/;
            index index.html;
        }
    }
}

Post Format

 worker_processes      5;
 worker_rlimit_nofile  8192;

events {
	worker_connections    4096;
}

http {
	client_max_body_size  10m;

	server {
		listen               8443 default_server ssl http2 reuseport;

		ssl_certificate      /certs/certificate.crt;
		ssl_certificate_key  /certs/privateKey.key;

		server_name          _;

		keepalive_timeout    620s;

		location / {
			root                /data/;
			index               index.html;
		}
	}
}

nginx.conf

Tokens added/removed for `events {}`

I've observed the following bug. I'm not sure if it's a vscode-nginx-formatter issue or nginxbeautifier issue, but I'm guessing it's a vscode-nginx-formatter issue because the next text seems dependent on where the cursor is placed.

Repro

  1. Create an nginx config with the following content
    events {}
  2. beautify the config.

Expected

The config contains the same tokens with perhaps a different whitespace between them.

Observed

There are a different number of tokens depending on whether the cursor is placed.

regexp formatting bug

when i format this:

location ~ ^/\d{3}/ {
    try_files $uri /index.html;
}

the result is error:

location ~ ^/\d;

thanks!

and,the version is 0.0.4

Syntax Highlighting Errors

The purpose of using a formatter is to bring clarity, but this extension brings max confusion!

the following sample code will produce the result shown in the picture:

# regex formatting in both, map and location are full of bugs, I give 2 examples but the list can be loooong!
location ~* (?:#.*#|\.(?:bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|^~.*)$ {
    deny all;
}

map $http_name $http_value {
    ~*^(www\.)?domain\.com:.* 1;
    default 0;
}

map $http_name $http_value {
    7d789ac019786442253db411b8e77632 1;  # value not recognized as a number
    ee2f1840417818a254ae94256b0eb8f3 22;  # key not recognized as hex number
    3kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 33; # key wrongfully recognized as number
    default 44;
}

server {
    location / {
        # wrong format for names as directives despite the fact that they are not in the first position
        include includes/location/dummy/map/dummy/geo/dummy/server/dummy/if/dummy/break/so.on
        # directives not recognized
        rewrite ^/api/(.*)$ /$1 break;
    }
}

Untitled

Formatting lead to an invalid configuration file

Hey there,

I'm using nginx in a docker container with the official image.

My nginx.conf contains environment variables definitions that gets interpolated when nginx starts

server {

    listen         80;
    listen         [::]:80;

    server_name    www.${DOMAIN_NAME};
    return         301 $scheme://${DOMAIN_NAME}$request_uri;

}

I i use the formatter, it gets formatted to

server {

    listen 80;
    listen [::]:80;

    server_name www.$ {
        DOMAIN_NAM
    }
    ;
    return 301 $scheme://$ {
        DOMAIN_NAM
    }
    $request_uri;

}

Didn't have a chance to look at the code for now, so no idea what's going on ๐Ÿค”

Quotes formatting breaks valid config

Here's an example of valid nginx.conf.

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log off;
    log_format json_combined escape=json
      '{'
        '"timeLocal":"$time_local",'
        '"remoteAddr":"$remote_addr",'
        '"forwarderFor":"$http_x_forwarded_for",'
        '"remoteUser":"$remote_user",'
        '"request":"$request",'
        '"status": "$status",'
        '"bytesSent":"$bytes_sent",'
        '"requestTime":"$request_time",'
        '"httpReferrer":"$http_referer",'
        '"gzipRatio":"$gzip_ratio",'
        '"httpUserAgent":"$http_user_agent"'
      '}';
    tcp_nopush on;
    tcp_nodelay on;
}

Formatter breaks it this way:

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log off;
  log_format json_combined escape=json
  ' {
    '
    '"timeLocal":"$time_local",'
    '"remoteAddr":"$remote_addr",'
    '"forwarderFor":"$http_x_forwarded_for",'
    '"remoteUser":"$remote_user",'
    '"request":"$request",'
    '"status": "$status",'
    '"bytesSent":"$bytes_sent",'
    '"requestTime":"$request_time",'
    '"httpReferrer":"$http_referer",'
    '"gzipRatio":"$gzip_ratio",'
    '"httpUserAgent":"$http_user_agent"'

  }
  ';
  tcp_nopush on;
  tcp_nodelay on;
}

Probably it was caused by some new changes, cause ~ 1 year ago it was working fine with such file.

Looks like nginxbeautifier bug.

Nginx-formatter cannot work properly with nginx.conf hint at the same time

VSCODE Version: 1.49.1
nginx-formatter Version: v0.0.10
nginx.conf hint Version: v0.1.0
I installed nginx-formatter and nginx.conf prompt together in vscode, and opened the nginx.conf file. There are NGINX and NGINX Conf in language mode. It can be formatted in NGINX mode, but the syntax cannot be highlighted. In NGINX Conf mode, the related functions prompted by nginx.conf can be used normally, but the file format cannot be executed. Please solve this problem.

waterfall like formatting of curly brackets

this is what I get running this formatter:

server {
  if ($host = www.foo.bar) {
    return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = xxx.foo.bar) {
      return 301 https://$host$request_uri;
      } # managed by Certbot


      if ($host = foo.bar) {
        return 301 https://$host$request_uri;
        } # managed by Certbot


        server_name foo.bar www.foo.bar xxx.foo.bar;
        listen 80;
        return 404; # managed by Certbot
      }

this is what I would expect instead:

 server {
  if ($host = www.foo.bar) {
    return 301 https://$host$request_uri;
  } # managed by Certbot


  if ($host = xxx.foo.bar) {
    return 301 https://$host$request_uri;
  } # managed by Certbot


  if ($host = foo.bar) {
    return 301 https://$host$request_uri;
  } # managed by Certbot


  server_name foo.bar www.foo.bar xxx.foo.bar;
  listen 80;
  return 404; # managed by Certbot
}

Is this intendet?

Syntax highlighting is not ok

Hi,
I'd like to have a nginx formatter but without loosing a great syntax highlighting.
I use hangxingliu.vscode-nginx-conf-hint for syntax highlighting and it's perfect, but it cannot work with your formatter...

Is it possible to for you to use this one instead of william-voyek.vscode-nginx which is not a great syntax highlighting ?

And also hangxingliu.vscode-nginx-conf-hint provides hints as you type.

Thank you

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.