[1/2] utils: checkstyle.py: Use r'' strings for regular expressions
diff mbox series

Message ID 20240416102004.10617-2-laurent.pinchart@ideasonboard.com
State Accepted
Commit fef732d4dc7fcb012c4339585d621d6c6bf384aa
Headers show
Series
  • utils: checkstyle.py: Extend Doxygen formatter
Related show

Commit Message

Laurent Pinchart April 16, 2024, 10:20 a.m. UTC
It's a good practice to use r'' strings for regular expressions in
Python, to avoid unexpected interaction with string escape sequences.
Use them globally. This allows simplifying escaping in one of the
regular expression strings.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/checkstyle.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Kieran Bingham April 16, 2024, 11:53 a.m. UTC | #1
Quoting Laurent Pinchart (2024-04-16 11:20:03)
> It's a good practice to use r'' strings for regular expressions in
> Python, to avoid unexpected interaction with string escape sequences.
> Use them globally. This allows simplifying escaping in one of the
> regular expression strings.
> 


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

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  utils/checkstyle.py | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 84f44a422577..2ab7e50fb0b6 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -569,7 +569,7 @@ class IncludeChecker(StyleChecker):
>                 'limits', 'locale', 'setjmp', 'signal', 'stdarg', 'stddef',
>                 'stdint', 'stdio', 'stdlib', 'string', 'time', 'uchar', 'wchar',
>                 'wctype')
> -    include_regex = re.compile('^#include <c([a-z]*)>')
> +    include_regex = re.compile(r'^#include <c([a-z]*)>')
>  
>      def __init__(self, content):
>          super().__init__()
> @@ -632,7 +632,7 @@ class MesonChecker(StyleChecker):
>  
>  class Pep8Checker(StyleChecker):
>      patterns = ('*.py',)
> -    results_regex = re.compile('stdin:([0-9]+):([0-9]+)(.*)')
> +    results_regex = re.compile(r'stdin:([0-9]+):([0-9]+)(.*)')
>  
>      def __init__(self, content):
>          super().__init__()
> @@ -665,7 +665,7 @@ class Pep8Checker(StyleChecker):
>  
>  class ShellChecker(StyleChecker):
>      patterns = ('*.sh',)
> -    results_line_regex = re.compile('In - line ([0-9]+):')
> +    results_line_regex = re.compile(r'In - line ([0-9]+):')
>  
>      def __init__(self, content):
>          super().__init__()
> @@ -753,7 +753,7 @@ class CLangFormatter(Formatter):
>  class DoxygenFormatter(Formatter):
>      patterns = ('*.c', '*.cpp')
>  
> -    return_regex = re.compile(' +\\* +\\\\return +[a-z]')
> +    return_regex = re.compile(r' +\* +\\return +[a-z]')
>  
>      @classmethod
>      def format(cls, filename, data):
> @@ -813,7 +813,7 @@ class DPointerFormatter(Formatter):
>  class IncludeOrderFormatter(Formatter):
>      patterns = ('*.cpp', '*.h')
>  
> -    include_regex = re.compile('^#include (["<])([^">]*)([">])')
> +    include_regex = re.compile(r'^#include (["<])([^">]*)([">])')
>  
>      @classmethod
>      def format(cls, filename, data):
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 84f44a422577..2ab7e50fb0b6 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -569,7 +569,7 @@  class IncludeChecker(StyleChecker):
                'limits', 'locale', 'setjmp', 'signal', 'stdarg', 'stddef',
                'stdint', 'stdio', 'stdlib', 'string', 'time', 'uchar', 'wchar',
                'wctype')
-    include_regex = re.compile('^#include <c([a-z]*)>')
+    include_regex = re.compile(r'^#include <c([a-z]*)>')
 
     def __init__(self, content):
         super().__init__()
@@ -632,7 +632,7 @@  class MesonChecker(StyleChecker):
 
 class Pep8Checker(StyleChecker):
     patterns = ('*.py',)
-    results_regex = re.compile('stdin:([0-9]+):([0-9]+)(.*)')
+    results_regex = re.compile(r'stdin:([0-9]+):([0-9]+)(.*)')
 
     def __init__(self, content):
         super().__init__()
@@ -665,7 +665,7 @@  class Pep8Checker(StyleChecker):
 
 class ShellChecker(StyleChecker):
     patterns = ('*.sh',)
-    results_line_regex = re.compile('In - line ([0-9]+):')
+    results_line_regex = re.compile(r'In - line ([0-9]+):')
 
     def __init__(self, content):
         super().__init__()
@@ -753,7 +753,7 @@  class CLangFormatter(Formatter):
 class DoxygenFormatter(Formatter):
     patterns = ('*.c', '*.cpp')
 
-    return_regex = re.compile(' +\\* +\\\\return +[a-z]')
+    return_regex = re.compile(r' +\* +\\return +[a-z]')
 
     @classmethod
     def format(cls, filename, data):
@@ -813,7 +813,7 @@  class DPointerFormatter(Formatter):
 class IncludeOrderFormatter(Formatter):
     patterns = ('*.cpp', '*.h')
 
-    include_regex = re.compile('^#include (["<])([^">]*)([">])')
+    include_regex = re.compile(r'^#include (["<])([^">]*)([">])')
 
     @classmethod
     def format(cls, filename, data):