Style(core): fix the incorrect front spaces to unite style.

Maxim Dounin mdounin at mdounin.ru
Wed May 20 13:48:48 UTC 2020


Hello!

On Wed, May 20, 2020 at 12:29:45PM +0800, Jim T wrote:

> Nginx is famous for code readability and neat code format. I use the tool(
> https://github.com/openresty/openresty-devel-utils) to try to unify the
> incorrect front spaces, Here is my attempt at core.
> 
> # HG changeset patch
> # User Jinhua Tan <312841925 at qq.com>
> # Date 1589948492 -28800
> #      Wed May 20 12:21:32 2020 +0800
> # Node ID 10678810de74edc4c02d5cd7303f0099eee9fac3
> # Parent  3c8082c3f98ab7fdec8a598b55609701452b5254
> Style(core): fix the incorrect front spaces to unite style.
> 
> diff -r 3c8082c3f98a -r 10678810de74 src/core/ngx_conf_file.c
> --- a/src/core/ngx_conf_file.c Wed May 13 22:02:47 2020 +0800
> +++ b/src/core/ngx_conf_file.c Wed May 20 12:21:32 2020 +0800
> @@ -544,8 +544,8 @@
>                      }
> 
>                      ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> -                                  "unexpected end of file, "
> -                                  "expecting \";\" or \"}\"");
> +                                       "unexpected end of file, "
> +                                       "expecting \";\" or \"}\"");
>                      return NGX_ERROR;
>                  }
> 
> @@ -1047,9 +1047,9 @@
> 
>      } else {
>          ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> -                     "invalid value \"%s\" in \"%s\" directive, "
> -                     "it must be \"on\" or \"off\"",
> -                     value[1].data, cmd->name.data);
> +                           "invalid value \"%s\" in \"%s\" directive, "
> +                           "it must be \"on\" or \"off\"",
> +                           value[1].data, cmd->name.data);
>          return NGX_CONF_ERROR;
>      }
> 
> diff -r 3c8082c3f98a -r 10678810de74 src/core/ngx_cycle.c
> --- a/src/core/ngx_cycle.c Wed May 13 22:02:47 2020 +0800
> +++ b/src/core/ngx_cycle.c Wed May 20 12:21:32 2020 +0800
> @@ -1308,9 +1308,9 @@
> 
>          if (tag != shm_zone[i].tag) {
>              ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> -                            "the shared memory zone \"%V\" is "
> -                            "already declared for a different use",
> -                            &shm_zone[i].shm.name);
> +                               "the shared memory zone \"%V\" is "
> +                               "already declared for a different use",
> +                               &shm_zone[i].shm.name);
>              return NULL;
>          }
> 

This particular chunk is a good example why simple mechanical 
whitespace changes are not to be applied.  Message here is aligned 
with the following "the size %uz of shared memory zone..." 
message, which cannot be aligned according to normal rules due to 
its length.

This is also demonstrates that code readability is not always 
about following rules.  Sometimes it's about breaking rules.

It should be also noted that pure style changes are usually to be 
avoided.  For example, FreeBSD's style(9) says it this way:

     Stylistic changes (including whitespace changes) are hard on the source
     repository and are to be avoided without good reason.

Thank you for your patch, but no.

[...]

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list