blob: 8df5b87d700088b1d4419ff9b2b3cdfe3924ef08 [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 Hsieh949205a2020-01-10 10:33:40 -080018# pylint:disable=relative-beyond-top-level
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080019# pylint:disable=g-importing-member
Chih-Hung Hsieh3cce2bc2020-02-27 15:39:18 -080020from .cpp_warn_patterns import compile_patterns
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080021from .severity import Severity
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080022
23
24def warn(name, severity, description, pattern_list):
25 return {
26 'category': name,
27 'severity': severity,
28 'description': name + ': ' + description,
29 'patterns': pattern_list
30 }
31
32
33def aapt(description, pattern_list):
34 return warn('aapt', Severity.MEDIUM, description, pattern_list)
35
36
37def misc(description, pattern_list):
38 return warn('logtags', Severity.LOW, description, pattern_list)
39
40
41def asm(description, pattern_list):
42 return warn('asm', Severity.MEDIUM, description, pattern_list)
43
44
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080045def kotlin(description, pattern):
46 return warn('Kotlin', Severity.MEDIUM, description,
47 [r'.*\.kt:.*: warning: ' + pattern])
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -080048
49
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -080050def yacc(description, pattern_list):
51 return warn('yacc', Severity.MEDIUM, description, pattern_list)
52
53
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080054def rust(severity, description, pattern):
55 return warn('Rust', severity, description,
56 [r'.*\.rs:.*: warning: ' + pattern])
57
58
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080059warn_patterns = [
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080060 # pylint:disable=line-too-long,g-inconsistent-quotes
61 # aapt warnings
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080062 aapt('No comment for public symbol',
63 [r".*: warning: No comment for public symbol .+"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080064 aapt('No default translation',
65 [r".*: warning: string '.+' has no default translation in .*"]),
66 aapt('Missing default or required localization',
67 [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]),
68 aapt('String marked untranslatable, but translation exists',
69 [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]),
70 aapt('empty span in string',
71 [r".*: warning: empty '.+' span found in text '.+"]),
72 # misc warnings
73 misc('Duplicate logtag',
74 [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]),
75 misc('Typedef redefinition',
76 [r".*: warning: redefinition of typedef '.+' is a C11 feature"]),
77 misc('GNU old-style field designator',
78 [r".*: warning: use of GNU old-style field designator extension"]),
79 misc('Missing field initializers',
80 [r".*: warning: missing field '.+' initializer"]),
81 misc('Missing braces',
82 [r".*: warning: suggest braces around initialization of",
83 r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
84 r".*: warning: braces around scalar initializer"]),
85 misc('Comparison of integers of different signs',
86 [r".*: warning: comparison of integers of different signs.+sign-compare"]),
87 misc('Add braces to avoid dangling else',
88 [r".*: warning: add explicit braces to avoid dangling else"]),
89 misc('Initializer overrides prior initialization',
90 [r".*: warning: initializer overrides prior initialization of this subobject"]),
91 misc('Assigning value to self',
92 [r".*: warning: explicitly assigning value of .+ to itself"]),
93 misc('GNU extension, variable sized type not at end',
94 [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]),
95 misc('Comparison of constant is always false/true',
96 [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]),
97 misc('Hides overloaded virtual function',
98 [r".*: '.+' hides overloaded virtual function"]),
99 misc('Incompatible pointer types',
100 [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]),
101 # Assembler warnings
102 asm('ASM value size does not match register size',
103 [r".*: warning: value size does not match register size specified by the constraint and modifier"]),
104 asm('IT instruction is deprecated',
105 [r".*: warning: applying IT instruction .* is deprecated"]),
106 # NDK warnings
107 {'category': 'NDK', 'severity': Severity.HIGH,
108 'description': 'NDK: Generate guard with empty availability, obsoleted',
109 'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
110 # Protoc warnings
111 {'category': 'Protoc', 'severity': Severity.MEDIUM,
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800112 'description': 'Proto: Enum name collision after strip',
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800113 'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
114 {'category': 'Protoc', 'severity': Severity.MEDIUM,
115 'description': 'Proto: Import not used',
116 'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
117 # Kotlin warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800118 kotlin('never used parameter or variable', '.+ \'.*\' is never used'),
119 kotlin('multiple labels', '.+ more than one label .+ in this scope'),
120 kotlin('type mismatch', 'type mismatch: '),
121 kotlin('is always true', '.+ is always \'true\''),
122 kotlin('no effect', '.+ annotation has no effect for '),
123 kotlin('no cast needed', 'no cast needed'),
124 kotlin('accessor not generated', 'an accessor will not be generated '),
125 kotlin('initializer is redundant', '.* initializer is redundant$'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800126 kotlin('elvis operator always returns ...',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800127 'elvis operator (?:) always returns .+'),
128 kotlin('shadowed name', 'name shadowed: .+'),
129 kotlin('unchecked cast', 'unchecked cast: .* to .*$'),
130 kotlin('unreachable code', 'unreachable code'),
131 kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800132 kotlin('unnecessary safe call on a non-null receiver',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800133 'unnecessary safe call on a non-null receiver'),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800134 kotlin('Deprecated in Java',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800135 '\'.*\' is deprecated. Deprecated in Java'),
Chih-Hung Hsiehed748962020-02-04 12:12:11 -0800136 kotlin('Replacing Handler for Executor',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800137 '.+ Replacing Handler for Executor in '),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800138 kotlin('library has Kotlin runtime',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800139 '.+ has Kotlin runtime (bundled|library)'),
140 warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime',
141 ['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']),
142 kotlin('other warnings', '.+'), # catch all other Kotlin warnings
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800143 # Yacc warnings
144 yacc('deprecate directive',
145 [r".*\.yy?:.*: warning: deprecated directive: "]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700146 yacc('reduce/reduce conflicts',
147 [r".*\.yy?: warning: .+ reduce/reduce conflicts "]),
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800148 yacc('shift/reduce conflicts',
149 [r".*\.yy?: warning: .+ shift/reduce conflicts "]),
150 {'category': 'yacc', 'severity': Severity.SKIP,
151 'description': 'yacc: fix-its can be applied',
152 'patterns': [r".*\.yy?: warning: fix-its can be applied."]},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800153 # Rust warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800154 rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'),
155 rust(Severity.MEDIUM, '... are deprecated',
156 ('(.+ are deprecated$|' +
157 'use of deprecated item .* (use .* instead|is now preferred))')),
158 rust(Severity.MEDIUM, 'never used', '.* is never used:'),
159 rust(Severity.MEDIUM, 'unused import', 'unused import: '),
160 rust(Severity.MEDIUM, 'unnecessary attribute',
161 '.+ no longer requires an attribute'),
162 rust(Severity.MEDIUM, 'unnecessary parentheses',
163 'unnecessary parentheses around'),
164 # Catch all RenderScript warnings
165 {'category': 'RenderScript', 'severity': Severity.LOW,
166 'description': 'RenderScript warnings',
167 'patterns': [r'.*\.rscript:.*: warning: ']},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800168 # Broken/partial warning messages will be skipped.
169 {'category': 'Misc', 'severity': Severity.SKIP,
170 'description': 'skip, ,',
171 'patterns': [r".*: warning: ,?$"]},
172 {'category': 'C/C++', 'severity': Severity.SKIP,
173 'description': 'skip, In file included from ...',
174 'patterns': [r".*: warning: In file included from .+,"]},
175 # catch-all for warnings this script doesn't know about yet
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800176 {'category': 'C/C++', 'severity': Severity.UNMATCHED,
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800177 'description': 'Unclassified/unrecognized warnings',
178 'patterns': [r".*: warning: .+"]},
179]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800180
181
182compile_patterns(warn_patterns)