Skip to content

Code inside INDENT-OFF / ON has whitespace modified #1338

@PaulEllexus

Description

@PaulEllexus

Within our organisation we are moving to uncrustify and we have been using INDENT-OFF / INDENT-ON comments to ignore entire C header files that are not under our control in our code base (i.e. third party API headers) rather than maintaining a list of file exceptions in our pre-commit hooks.

When running uncrustify against these files multiple whitespace changes are seen.

There are two problems

  1. Trailing whitespace is always removed (this happens with an empty config file)
  2. If nl_max is set it is applied within the ignored code block

Tested with Uncrustify-0.65_f 3503c92

Example that demonstrates the issue:

configuration file

nl_max=2

Input

/* *INDENT-OFF* */
#include <stdio.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{
    /* The following line has a trailing space */
    printf("Hello World!\n"); 

    return EXIT_SUCCESS;
}

/* *INDENT-ON* */

Expected output - unchanged

Observed output

/* *INDENT-OFF* */
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    /* The following line has a trailing space */
    printf("Hello World!\n");

    return EXIT_SUCCESS;
}

/* *INDENT-ON* */

Difference

diff -u example.c example.c.uncrustify 
--- example.c	2017-09-07 14:47:27.971867687 +0100
+++ example.c.uncrustify	2017-09-07 14:56:03.506449892 +0100
@@ -2,14 +2,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-
 int main(int argc, char *argv[])
 {
     /* The following line has a trailing space */
-    printf("Hello World!\n"); 
+    printf("Hello World!\n");
 
     return EXIT_SUCCESS;
 }
 
 /* *INDENT-ON* */

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions