blob: d05c8e90fc9319ccbe733008bc51c242ceea29ea [file] [log] [blame]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -08001# python3
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08002# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns from other tools."""
17
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070018# No need of doc strings for trivial small functions.
19# pylint:disable=missing-function-docstring
20
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080021# pylint:disable=relative-beyond-top-level
Chih-Hung Hsieh3cce2bc2020-02-27 15:39:18 -080022from .cpp_warn_patterns import compile_patterns
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080023from .severity import Severity
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080024
25
26def warn(name, severity, description, pattern_list):
27 return {
28 'category': name,
29 'severity': severity,
30 'description': name + ': ' + description,
31 'patterns': pattern_list
32 }
33
34
35def aapt(description, pattern_list):
36 return warn('aapt', Severity.MEDIUM, description, pattern_list)
37
38
39def misc(description, pattern_list):
40 return warn('logtags', Severity.LOW, description, pattern_list)
41
42
43def asm(description, pattern_list):
44 return warn('asm', Severity.MEDIUM, description, pattern_list)
45
46
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080047def kotlin(description, pattern):
48 return warn('Kotlin', Severity.MEDIUM, description,
49 [r'.*\.kt:.*: warning: ' + pattern])
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -080050
51
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -080052def yacc(description, pattern_list):
53 return warn('yacc', Severity.MEDIUM, description, pattern_list)
54
55
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080056def rust(severity, description, pattern):
57 return warn('Rust', severity, description,
58 [r'.*\.rs:.*: warning: ' + pattern])
59
60
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080061warn_patterns = [
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070062 # pylint does not recognize g-inconsistent-quotes
63 # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080064 # aapt warnings
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080065 aapt('No comment for public symbol',
66 [r".*: warning: No comment for public symbol .+"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080067 aapt('No default translation',
68 [r".*: warning: string '.+' has no default translation in .*"]),
69 aapt('Missing default or required localization',
70 [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]),
71 aapt('String marked untranslatable, but translation exists',
72 [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]),
73 aapt('empty span in string',
74 [r".*: warning: empty '.+' span found in text '.+"]),
75 # misc warnings
76 misc('Duplicate logtag',
77 [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]),
78 misc('Typedef redefinition',
79 [r".*: warning: redefinition of typedef '.+' is a C11 feature"]),
80 misc('GNU old-style field designator',
81 [r".*: warning: use of GNU old-style field designator extension"]),
82 misc('Missing field initializers',
83 [r".*: warning: missing field '.+' initializer"]),
84 misc('Missing braces',
85 [r".*: warning: suggest braces around initialization of",
86 r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
87 r".*: warning: braces around scalar initializer"]),
88 misc('Comparison of integers of different signs',
89 [r".*: warning: comparison of integers of different signs.+sign-compare"]),
90 misc('Add braces to avoid dangling else',
91 [r".*: warning: add explicit braces to avoid dangling else"]),
92 misc('Initializer overrides prior initialization',
93 [r".*: warning: initializer overrides prior initialization of this subobject"]),
94 misc('Assigning value to self',
95 [r".*: warning: explicitly assigning value of .+ to itself"]),
96 misc('GNU extension, variable sized type not at end',
97 [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]),
98 misc('Comparison of constant is always false/true',
99 [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]),
100 misc('Hides overloaded virtual function',
101 [r".*: '.+' hides overloaded virtual function"]),
102 misc('Incompatible pointer types',
103 [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]),
104 # Assembler warnings
105 asm('ASM value size does not match register size',
106 [r".*: warning: value size does not match register size specified by the constraint and modifier"]),
107 asm('IT instruction is deprecated',
108 [r".*: warning: applying IT instruction .* is deprecated"]),
109 # NDK warnings
110 {'category': 'NDK', 'severity': Severity.HIGH,
111 'description': 'NDK: Generate guard with empty availability, obsoleted',
112 'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
113 # Protoc warnings
114 {'category': 'Protoc', 'severity': Severity.MEDIUM,
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800115 'description': 'Proto: Enum name collision after strip',
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800116 'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
117 {'category': 'Protoc', 'severity': Severity.MEDIUM,
118 'description': 'Proto: Import not used',
119 'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
120 # Kotlin warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800121 kotlin('never used parameter or variable', '.+ \'.*\' is never used'),
122 kotlin('multiple labels', '.+ more than one label .+ in this scope'),
123 kotlin('type mismatch', 'type mismatch: '),
124 kotlin('is always true', '.+ is always \'true\''),
125 kotlin('no effect', '.+ annotation has no effect for '),
126 kotlin('no cast needed', 'no cast needed'),
127 kotlin('accessor not generated', 'an accessor will not be generated '),
128 kotlin('initializer is redundant', '.* initializer is redundant$'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800129 kotlin('elvis operator always returns ...',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800130 'elvis operator (?:) always returns .+'),
131 kotlin('shadowed name', 'name shadowed: .+'),
132 kotlin('unchecked cast', 'unchecked cast: .* to .*$'),
133 kotlin('unreachable code', 'unreachable code'),
134 kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800135 kotlin('unnecessary safe call on a non-null receiver',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800136 'unnecessary safe call on a non-null receiver'),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800137 kotlin('Deprecated in Java',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800138 '\'.*\' is deprecated. Deprecated in Java'),
Chih-Hung Hsiehed748962020-02-04 12:12:11 -0800139 kotlin('Replacing Handler for Executor',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800140 '.+ Replacing Handler for Executor in '),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800141 kotlin('library has Kotlin runtime',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800142 '.+ has Kotlin runtime (bundled|library)'),
143 warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime',
144 ['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']),
145 kotlin('other warnings', '.+'), # catch all other Kotlin warnings
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800146 # Yacc warnings
147 yacc('deprecate directive',
148 [r".*\.yy?:.*: warning: deprecated directive: "]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700149 yacc('reduce/reduce conflicts',
150 [r".*\.yy?: warning: .+ reduce/reduce conflicts "]),
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800151 yacc('shift/reduce conflicts',
152 [r".*\.yy?: warning: .+ shift/reduce conflicts "]),
153 {'category': 'yacc', 'severity': Severity.SKIP,
154 'description': 'yacc: fix-its can be applied',
155 'patterns': [r".*\.yy?: warning: fix-its can be applied."]},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800156 # Rust warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800157 rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'),
158 rust(Severity.MEDIUM, '... are deprecated',
159 ('(.+ are deprecated$|' +
160 'use of deprecated item .* (use .* instead|is now preferred))')),
161 rust(Severity.MEDIUM, 'never used', '.* is never used:'),
162 rust(Severity.MEDIUM, 'unused import', 'unused import: '),
163 rust(Severity.MEDIUM, 'unnecessary attribute',
164 '.+ no longer requires an attribute'),
165 rust(Severity.MEDIUM, 'unnecessary parentheses',
166 'unnecessary parentheses around'),
167 # Catch all RenderScript warnings
168 {'category': 'RenderScript', 'severity': Severity.LOW,
169 'description': 'RenderScript warnings',
170 'patterns': [r'.*\.rscript:.*: warning: ']},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800171 # Broken/partial warning messages will be skipped.
172 {'category': 'Misc', 'severity': Severity.SKIP,
173 'description': 'skip, ,',
174 'patterns': [r".*: warning: ,?$"]},
175 {'category': 'C/C++', 'severity': Severity.SKIP,
176 'description': 'skip, In file included from ...',
177 'patterns': [r".*: warning: In file included from .+,"]},
178 # catch-all for warnings this script doesn't know about yet
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800179 {'category': 'C/C++', 'severity': Severity.UNMATCHED,
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800180 'description': 'Unclassified/unrecognized warnings',
181 'patterns': [r".*: warning: .+"]},
182]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800183
184
185compile_patterns(warn_patterns)