From 91a65e9ee655d7919972cb50811b417c97be95a5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 3 Jul 2019 23:53:01 +0300 Subject: utils: checkstyle.py: Add Doxygen formatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a formatter for doxygen comments. In its initial implementation the formatter ensures that the first word of a \return statement starts with an uppercase letter. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'utils') diff --git a/utils/checkstyle.py b/utils/checkstyle.py index bc631d40..fab4b116 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -350,6 +350,34 @@ class CLangFormatter(Formatter): return ret.stdout.decode('utf-8') +class DoxygenFormatter(Formatter): + patterns = ('*.c', '*.cpp') + + return_regex = re.compile(' +\\* +\\\\return +[a-z]') + + @classmethod + def format(cls, filename, data): + lines = [] + in_doxygen = False + + for line in data.split('\n'): + if line.find('/**') != -1: + in_doxygen = True + + if not in_doxygen: + lines.append(line) + continue + + line = cls.return_regex.sub(lambda m: m.group(0)[:-1] + m.group(0)[-1].upper(), line) + + if line.find('*/') != -1: + in_doxygen = False + + lines.append(line) + + return '\n'.join(lines) + + class StripTrailingSpaceFormatter(Formatter): patterns = ('*.c', '*.cpp', '*.h', '*.py', 'meson.build') -- cgit v1.2.1