Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89388a59 authored by Chih-hung Hsieh's avatar Chih-hung Hsieh Committed by Automerger Merge Worker
Browse files

Merge "Fix/suppress most pylint and gpylint warnings" am: 6ddd8560

Original change: https://android-review.googlesource.com/c/platform/build/+/1690128

Change-Id: I71253126af3522c2d4fdd3a94f3dcb03d13f4cb0
parents 4ce5d51b 6ddd8560
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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:])

+1 −0
Original line number Diff line number Diff line
@@ -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:']
+1 −0
Original line number Diff line number Diff line
@@ -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:']


+6 −3
Original line number Diff line number Diff line
@@ -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*',
+13 −12
Original line number Diff line number Diff line
@@ -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 = """\
  <script type="text/javascript">
  function expand(id) {
    var e = document.getElementById(id);
@@ -113,7 +115,7 @@ def html_big(param):
def dump_html_prologue(title, writer, warn_patterns, project_names):
  writer('<html>\n<head>')
  writer('<title>' + title + '</title>')
  writer(html_head_scripts)
  writer(HTML_HEAD_SCRIPTS)
  emit_stats_by_project(writer, warn_patterns, project_names)
  writer('</head>\n<body>')
  writer(html_big(title))
@@ -142,7 +144,7 @@ def create_warnings(warn_patterns, project_names):
    2D warnings array where warnings[p][s] is # of warnings in project name p of
    severity level s
  """
  # pylint:disable=g-complex-comprehension
  # pylint:disable=invalid-name
  warnings = {p: {s.value: 0 for s in Severity.levels} for p in project_names}
  for i in warn_patterns:
    s = i['severity'].value
@@ -153,7 +155,6 @@ def create_warnings(warn_patterns, project_names):

def get_total_by_project(warnings, project_names):
  """Returns dict, project as key and # warnings for that project as value."""
  # pylint:disable=g-complex-comprehension
  return {
      p: sum(warnings[p][s.value] for s in Severity.levels)
      for p in project_names
@@ -162,7 +163,6 @@ def get_total_by_project(warnings, project_names):

def get_total_by_severity(warnings, project_names):
  """Returns dict, severity as key and # warnings of that severity as value."""
  # pylint:disable=g-complex-comprehension
  return {
      s.value: sum(warnings[p][s.value] for p in project_names)
      for s in Severity.levels
@@ -235,7 +235,7 @@ def emit_row_counts_per_severity(total_by_severity, stats_header, stats_rows,
  writer('<script>')
  emit_const_string_array('StatsHeader', stats_header, writer)
  emit_const_object_array('StatsRows', stats_rows, writer)
  writer(draw_table_javascript)
  writer(DRAW_TABLE_JAVASCRIPT)
  writer('</script>')


@@ -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('<button class="button" onclick="expandCollapse(1);">'
         'Expand all warnings</button>\n'
         '<button class="button" onclick="expandCollapse(0);">'
@@ -412,7 +413,7 @@ def emit_warning_arrays(writer, warn_patterns):
  writer('];')


scripts_for_warning_groups = """
SCRIPTS_FOR_WARNING_GROUPS = """
  function compareMessages(x1, x2) { // of the same warning type
    return (WarningMessages[x1[2]] <= WarningMessages[x2[2]]) ? -1 : 1;
  }
@@ -620,7 +621,7 @@ def emit_js_data(writer, flags, warning_messages, warning_links,
    emit_const_html_string_array('WarningLinks', warning_links, writer)


draw_table_javascript = """
DRAW_TABLE_JAVASCRIPT = """
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
function drawTable() {
@@ -653,7 +654,7 @@ def dump_html(flags, output_stream, warning_messages, warning_links,
  writer('\n<script>')
  emit_js_data(writer, flags, warning_messages, warning_links, warning_records,
               warn_patterns, project_names)
  writer(scripts_for_warning_groups)
  writer(SCRIPTS_FOR_WARNING_GROUPS)
  writer('</script>')
  emit_buttons(writer)
  # Warning messages are grouped by severities or project names.
Loading