Issue 60589
Summary [clang-format] IncludeCategories: Placing of main file is broken for specific orders
Labels new issue
Assignees
Reporter Febbe
     - As soon, any regex is placed at **position/`Priority: 0` with `SortPriority:    0`**, the main include will be moved to the first group/priority matching it, if it is not the first include in this group.  If it is the first include, it stays in block / at priority 0, if not it is moved to group/priority matching it.
 - If the group shares the same Priority(0) but the SortPriority is greater to zero, the main file stays in its group, when it is at position 1 and is not resorted. 
 - If the group shares the same Priority(0) but the SortPriority is less to zero, there is no way to prevent resorting. A new group is created, all other headers will be placed in here, the new group is ordered by its `SortPriority`, not `Priority !`, so it may be placed at the top instead of 0.
 - the main file stays in its group, when it is at position 1 and is not resorted. 
 - As soon as any regex, which matches also the main-include is ordered before (Priority < 0), the main-include is not treated anymore as main include and is added to that group matching it. That will prevent it from staying at priority 0.

Expectation: the main include should __always__ stay in group() 0 / sorted with priority 0, since it is currently not controllable, where to match it. All other includes, ordered into group/ with priority 0 should be ordered with the main include, depending on the `SortPriority` parameter. It is the `.clang-format`'s file maintainers job to sort the main-include at the top if that's still desired.
This is also that what the documentation states.


Example code to mess around with:
```
IncludeCategories:
  - Regex: '^<[Q][^/.]*>$'
    Priority:        -1
    CaseSensitive:   true
 - Regex:           '^<[a-z_]*>$'
    Priority:        -1
 CaseSensitive:   true
  - Regex:           '^<[^/]*\.h>$'
 Priority:        -1
  - Regex:           '^<.*\.h>$'
    Priority: -1
  - Regex:           '^<.*>$'
    Priority:        -1
  - Regex:           '^"[^/]*\.h"$'
    Priority:        0
 SortPriority:    -1
  - Regex:           '^".*\.h"$'
    Priority: 1
    SortPriority:    1
  - Regex:           '^".*"$'
 Priority:        10

```

Related: #58284
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to