[PATCH v3 3/9] tests/style: check for mixups of bool constants with int variables

Daniel P. Berrangé posted 9 patches 3 years, 7 months ago
[PATCH v3 3/9] tests/style: check for mixups of bool constants with int variables
Posted by Daniel P. Berrangé 3 years, 7 months ago
The 'true' and 'false' constants should only ever be used with the
'bool' type, never 'int'.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/style.yml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/style.yml b/tests/style.yml
index b4e7c6111f..704227d8e9 100644
--- a/tests/style.yml
+++ b/tests/style.yml
@@ -86,3 +86,8 @@
 #        A match added to the front of the regex. Useful when
 #        'terms' is a list of strings and a common prefix is
 #        desired
+
+int_assign_bool:
+  files: \.c$
+  prohibit: \<int\>.*= *(true|false)\b
+  message: use bool type for boolean values
-- 
2.36.1


Re: [PATCH v3 3/9] tests/style: check for mixups of bool constants with int variables
Posted by Philippe Mathieu-Daudé via 3 years, 7 months ago
On 7/7/22 18:37, Daniel P. Berrangé wrote:
> The 'true' and 'false' constants should only ever be used with the
> 'bool' type, never 'int'.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/style.yml | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/tests/style.yml b/tests/style.yml
> index b4e7c6111f..704227d8e9 100644
> --- a/tests/style.yml
> +++ b/tests/style.yml
> @@ -86,3 +86,8 @@
>   #        A match added to the front of the regex. Useful when
>   #        'terms' is a list of strings and a common prefix is
>   #        desired
> +
> +int_assign_bool:
> +  files: \.c$

Why not check .c.inc and .h (for static inlined func)?

Regardless:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +  prohibit: \<int\>.*= *(true|false)\b
> +  message: use bool type for boolean values

Re: [PATCH v3 3/9] tests/style: check for mixups of bool constants with int variables
Posted by Daniel P. Berrangé 3 years, 7 months ago
On Mon, Jul 11, 2022 at 06:24:22PM +0200, Philippe Mathieu-Daudé wrote:
> On 7/7/22 18:37, Daniel P. Berrangé wrote:
> > The 'true' and 'false' constants should only ever be used with the
> > 'bool' type, never 'int'.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   tests/style.yml | 5 +++++
> >   1 file changed, 5 insertions(+)
> > 
> > diff --git a/tests/style.yml b/tests/style.yml
> > index b4e7c6111f..704227d8e9 100644
> > --- a/tests/style.yml
> > +++ b/tests/style.yml
> > @@ -86,3 +86,8 @@
> >   #        A match added to the front of the regex. Useful when
> >   #        'terms' is a list of strings and a common prefix is
> >   #        desired
> > +
> > +int_assign_bool:
> > +  files: \.c$
> 
> Why not check .c.inc and .h (for static inlined func)?

Yes, we should.

> Regardless:
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> > +  prohibit: \<int\>.*= *(true|false)\b
> > +  message: use bool type for boolean values
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|