[libcamera-devel] clang-format: Enable sorted includes
diff mbox series

Message ID 20210222094608.1541623-1-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] clang-format: Enable sorted includes
Related show

Commit Message

Kieran Bingham Feb. 22, 2021, 9:46 a.m. UTC
We aim to ensure that our includes are alphabetically sorted.  Whilst
checkstyle.py also handles this, enable the clang-format explicitly to
define the code-style requirement, and allow clang-format to also
correct un-sorted header includes.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
I can't see why this isn't enabled, unless clang-format is sorting in a
manner which is incompatible with the implementation in our
checkstyle.py ?

Some initial testing shows that clang-format only sorts per block,
separated by newlines, which seems to match our implementation.


 .clang-format | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Feb. 22, 2021, 9:56 a.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Mon, Feb 22, 2021 at 09:46:08AM +0000, Kieran Bingham wrote:
> We aim to ensure that our includes are alphabetically sorted.  Whilst
> checkstyle.py also handles this, enable the clang-format explicitly to
> define the code-style requirement, and allow clang-format to also
> correct un-sorted header includes.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> ---
> I can't see why this isn't enabled, unless clang-format is sorting in a
> manner which is incompatible with the implementation in our
> checkstyle.py ?
> 
> Some initial testing shows that clang-format only sorts per block,
> separated by newlines, which seems to match our implementation.

I was considering enabling this along with corresponding include
regexes, but I suppose it can go on its own too, if you guarantee it
works properly :-)

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

With appropriate regexes we could possibly drop the include formatter
from checkstyle.py.

>  .clang-format | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/.clang-format b/.clang-format
> index bef07cd84338..f5d9ba940eeb 100644
> --- a/.clang-format
> +++ b/.clang-format
> @@ -97,7 +97,7 @@ PenaltyReturnTypeOnItsOwnLine: 60
>  
>  PointerAlignment: Right
>  ReflowComments: false
> -SortIncludes: false
> +SortIncludes: true
>  #SortUsingDeclarations: false # Unknown to clang-format-4.0
>  SpaceAfterCStyleCast: false
>  SpaceAfterTemplateKeyword: false
Kieran Bingham March 8, 2021, 11:44 a.m. UTC | #2
On 22/02/2021 09:56, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Mon, Feb 22, 2021 at 09:46:08AM +0000, Kieran Bingham wrote:
>> We aim to ensure that our includes are alphabetically sorted.  Whilst
>> checkstyle.py also handles this, enable the clang-format explicitly to
>> define the code-style requirement, and allow clang-format to also
>> correct un-sorted header includes.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>
>> ---
>> I can't see why this isn't enabled, unless clang-format is sorting in a
>> manner which is incompatible with the implementation in our
>> checkstyle.py ?
>>
>> Some initial testing shows that clang-format only sorts per block,
>> separated by newlines, which seems to match our implementation.
> 
> I was considering enabling this along with corresponding include
> regexes, but I suppose it can go on its own too, if you guarantee it
> works properly :-)
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> With appropriate regexes we could possibly drop the include formatter
> from checkstyle.py.

These look interesting but I haven't spent the time to figure out how
they really work yet.

An interesting thing to tackle in the future though, we just need to add
it to some todo list ... ;-)

--
Kieran


> 
>>  .clang-format | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/.clang-format b/.clang-format
>> index bef07cd84338..f5d9ba940eeb 100644
>> --- a/.clang-format
>> +++ b/.clang-format
>> @@ -97,7 +97,7 @@ PenaltyReturnTypeOnItsOwnLine: 60
>>  
>>  PointerAlignment: Right
>>  ReflowComments: false
>> -SortIncludes: false
>> +SortIncludes: true
>>  #SortUsingDeclarations: false # Unknown to clang-format-4.0
>>  SpaceAfterCStyleCast: false
>>  SpaceAfterTemplateKeyword: false
>

Patch
diff mbox series

diff --git a/.clang-format b/.clang-format
index bef07cd84338..f5d9ba940eeb 100644
--- a/.clang-format
+++ b/.clang-format
@@ -97,7 +97,7 @@  PenaltyReturnTypeOnItsOwnLine: 60
 
 PointerAlignment: Right
 ReflowComments: false
-SortIncludes: false
+SortIncludes: true
 #SortUsingDeclarations: false # Unknown to clang-format-4.0
 SpaceAfterCStyleCast: false
 SpaceAfterTemplateKeyword: false