From 98b285dafb90b7136dadc55c534888e7155205b1 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 28 Apr 2021 14:49:32 -0700 Subject: [PATCH] Fix/suppress most pylint and gpylint warnings * Add missing function doc strings. Suppress this warning on trivial functions in *_warn_patterns.py. * Remove unused g-importing-memeber, g-complex-comprehension. * Suppress pylint warning on unrecognized g-* options. * Suppress too-few-public-methods warnings on simple classes. * Suppress too-many-arguments and missing-function-docstring in html_writer.py, which will be refactored later. * Fix bad naming, long lines and line breaks, and bad quotes. Test: compare output for build.log Change-Id: Icdb34f014a10ec1e642c2cfe8003fc3ae245b507 --- tools/warn.py | 1 + tools/warn/android_project_list.py | 1 + tools/warn/chrome_project_list.py | 1 + tools/warn/cpp_warn_patterns.py | 9 ++++-- tools/warn/html_writer.py | 25 ++++++++-------- tools/warn/java_warn_patterns.py | 7 +++-- tools/warn/make_warn_patterns.py | 4 +-- tools/warn/other_warn_patterns.py | 7 +++-- tools/warn/severity.py | 5 ++-- tools/warn/tidy_warn_patterns.py | 8 +++-- tools/warn/warn.py | 5 +++- tools/warn/warn_common.py | 47 ++++++++++++++++++------------ 12 files changed, 75 insertions(+), 45 deletions(-) diff --git a/tools/warn.py b/tools/warn.py index 5f796f528..97f54f9b4 100755 --- a/tools/warn.py +++ b/tools/warn.py @@ -27,6 +27,7 @@ import sys def main(): + """Old main() calls warn.warn.""" os.environ['PYTHONPATH'] = os.path.dirname(os.path.abspath(__file__)) subprocess.check_call(['/usr/bin/python3', '-m', 'warn.warn'] + sys.argv[1:]) diff --git a/tools/warn/android_project_list.py b/tools/warn/android_project_list.py index 82c0fbd63..8383dc0c3 100644 --- a/tools/warn/android_project_list.py +++ b/tools/warn/android_project_list.py @@ -17,6 +17,7 @@ def create_pattern(name, pattern=None): + """Return a tuple of name and warn patten.""" if pattern is not None: return [name, '(^|.*/)' + pattern + '/.*: warning:'] return [name, '(^|.*/)' + name + '/.*: warning:'] diff --git a/tools/warn/chrome_project_list.py b/tools/warn/chrome_project_list.py index 609652267..d8b2179c8 100644 --- a/tools/warn/chrome_project_list.py +++ b/tools/warn/chrome_project_list.py @@ -8,6 +8,7 @@ unification of the Chrome and Android warn.py. def create_pattern(pattern): + """Return a tuple of name and warn patten.""" return [pattern, '(^|.*/)' + pattern + '/.*: warning:'] diff --git a/tools/warn/cpp_warn_patterns.py b/tools/warn/cpp_warn_patterns.py index e8783bc47..2fa9916ec 100644 --- a/tools/warn/cpp_warn_patterns.py +++ b/tools/warn/cpp_warn_patterns.py @@ -15,10 +15,12 @@ """Warning patterns for C/C++ compiler, but not clang-tidy.""" +# No need of doc strings for trivial small functions. +# pylint:disable=missing-function-docstring + import re # pylint:disable=relative-beyond-top-level -# pylint:disable=g-importing-member from .severity import Severity @@ -56,7 +58,8 @@ def harmless(description, pattern_list): warn_patterns = [ - # pylint:disable=line-too-long,g-inconsistent-quotes + # pylint does not recognize g-inconsistent-quotes + # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes medium('Implicit function declaration', [r".*: warning: implicit declaration of function .+", r".*: warning: implicitly declaring library function"]), @@ -300,7 +303,7 @@ warn_patterns = [ medium('Missing noreturn', [r".*: warning: function '.*' could be declared with attribute 'noreturn'"]), medium('User warning', - [r".*: warning: #warning "".+"""]), + [r".*: warning: #warning \".+\""]), medium('Vexing parsing problem', [r".*: warning: empty parentheses interpreted as a function declaration"]), medium('Dereferencing void*', diff --git a/tools/warn/html_writer.py b/tools/warn/html_writer.py index be71b5506..bed25ed6f 100644 --- a/tools/warn/html_writer.py +++ b/tools/warn/html_writer.py @@ -15,6 +15,9 @@ """Emit warning messages to html or csv files.""" +# Many functions in this module have too many arguments to be refactored. +# pylint:disable=too-many-arguments,missing-function-docstring + # To emit html page of warning messages: # flags: --byproject, --url, --separator # Old stuff for static html components: @@ -57,11 +60,10 @@ import html import sys # pylint:disable=relative-beyond-top-level -# pylint:disable=g-importing-member from .severity import Severity -html_head_scripts = """\ +HTML_HEAD_SCRIPTS = """\ ') @@ -246,8 +246,8 @@ def emit_stats_by_project(writer, warn_patterns, project_names): total_by_project = get_total_by_project(warnings, project_names) total_by_severity = get_total_by_severity(warnings, project_names) stats_header = emit_table_header(total_by_severity) - total_all_projects, stats_rows = \ - emit_row_counts_per_project(warnings, total_by_project, total_by_severity, project_names) + total_all_projects, stats_rows = emit_row_counts_per_project( + warnings, total_by_project, total_by_severity, project_names) emit_row_counts_per_severity(total_by_severity, stats_header, stats_rows, total_all_projects, writer) @@ -287,6 +287,7 @@ def dump_stats(writer, warn_patterns): # id for each warning pattern # sort by project, severity, warn_id, warning_message def emit_buttons(writer): + """Write the button elements in HTML.""" writer('\n' '