Skip to content

clang-format commit hook failed when using <filename>.h #10

@mlouielu

Description

@mlouielu

Root cause:

Using temp file will mess up clang-format IncludeCategories rules for .h

Description:

In clang-format, IncludeCategories will automatically set the filename.h to the highest priority, which mean it will put it at the first of the include block:

The main header for a source file automatically gets category 0. so that it is generally kept at the beginning of the #includes link

But, our hook using the temp file to compare with the source file, causing this rule not work, hence given a no-fix loop for this situation:

Report by the clang-format

$ clang-format this_is_the_actual_filename.c
#ifdef FOOBAR
#include "this_is_the_actual_filename.h"
#include "xxx.h"
#include "xxx.h"
#include "xxx.h"

 #include <xxx.h>
 #include <xxx.h>

Report by the hook

--- .merge_file_Zzz17X	2019-09-26 21:39:09.606926346 +0800
+++ /tmp/.merge_file_Zzz17X.I2ISWZ	2019-09-26 21:39:09.650259682 +0800
@@ -1,8 +1,8 @@
 #ifdef FOOBAR
-#include "this_is_the_actual_filename.h"
 #include "xxx.h"
 #include "xxx.h"
 #include "xxx.h"
+#include "this_is_the_actual_filename.h"
 
 #include <xxx.h>
 #include <xxx.h>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions