blob: c95528c5010b92aac6cc88f18c122c66ca5f6ba5 [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 .+"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080078 # Assembler warnings
79 asm('ASM value size does not match register size',
80 [r".*: warning: value size does not match register size specified by the constraint and modifier"]),
81 asm('IT instruction is deprecated',
82 [r".*: warning: applying IT instruction .* is deprecated"]),
Chih-Hung Hsiehe40e2bf2021-06-08 14:52:45 -070083 asm('section flags ignored',
84 [r".*: warning: section flags ignored on section redeclaration"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -070085 asm('setjmp/longjmp/vfork changed binding',
86 [r".*: warning: .*(setjmp|longjmp|vfork) changed binding to .*"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080087 # NDK warnings
88 {'category': 'NDK', 'severity': Severity.HIGH,
89 'description': 'NDK: Generate guard with empty availability, obsoleted',
90 'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
91 # Protoc warnings
92 {'category': 'Protoc', 'severity': Severity.MEDIUM,
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080093 'description': 'Proto: Enum name collision after strip',
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080094 'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
95 {'category': 'Protoc', 'severity': Severity.MEDIUM,
96 'description': 'Proto: Import not used',
97 'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
98 # Kotlin warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080099 kotlin('never used parameter or variable', '.+ \'.*\' is never used'),
100 kotlin('multiple labels', '.+ more than one label .+ in this scope'),
101 kotlin('type mismatch', 'type mismatch: '),
102 kotlin('is always true', '.+ is always \'true\''),
103 kotlin('no effect', '.+ annotation has no effect for '),
104 kotlin('no cast needed', 'no cast needed'),
105 kotlin('accessor not generated', 'an accessor will not be generated '),
106 kotlin('initializer is redundant', '.* initializer is redundant$'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800107 kotlin('elvis operator always returns ...',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800108 'elvis operator (?:) always returns .+'),
109 kotlin('shadowed name', 'name shadowed: .+'),
110 kotlin('unchecked cast', 'unchecked cast: .* to .*$'),
111 kotlin('unreachable code', 'unreachable code'),
112 kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'),
Chih-Hung Hsieha7f5f3f2020-01-31 16:14:04 -0800113 kotlin('unnecessary safe call on a non-null receiver',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800114 'unnecessary safe call on a non-null receiver'),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800115 kotlin('Deprecated in Java',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800116 '\'.*\' is deprecated. Deprecated in Java'),
Chih-Hung Hsiehed748962020-02-04 12:12:11 -0800117 kotlin('Replacing Handler for Executor',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800118 '.+ Replacing Handler for Executor in '),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800119 kotlin('library has Kotlin runtime',
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800120 '.+ has Kotlin runtime (bundled|library)'),
121 warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime',
122 ['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']),
123 kotlin('other warnings', '.+'), # catch all other Kotlin warnings
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800124 # Yacc warnings
125 yacc('deprecate directive',
126 [r".*\.yy?:.*: warning: deprecated directive: "]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700127 yacc('reduce/reduce conflicts',
128 [r".*\.yy?: warning: .+ reduce/reduce conflicts "]),
Chih-Hung Hsieh5392cdb2020-01-13 14:05:17 -0800129 yacc('shift/reduce conflicts',
130 [r".*\.yy?: warning: .+ shift/reduce conflicts "]),
131 {'category': 'yacc', 'severity': Severity.SKIP,
132 'description': 'yacc: fix-its can be applied',
133 'patterns': [r".*\.yy?: warning: fix-its can be applied."]},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800134 # Rust warnings
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800135 rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'),
136 rust(Severity.MEDIUM, '... are deprecated',
137 ('(.+ are deprecated$|' +
138 'use of deprecated item .* (use .* instead|is now preferred))')),
139 rust(Severity.MEDIUM, 'never used', '.* is never used:'),
140 rust(Severity.MEDIUM, 'unused import', 'unused import: '),
141 rust(Severity.MEDIUM, 'unnecessary attribute',
142 '.+ no longer requires an attribute'),
143 rust(Severity.MEDIUM, 'unnecessary parentheses',
144 'unnecessary parentheses around'),
145 # Catch all RenderScript warnings
146 {'category': 'RenderScript', 'severity': Severity.LOW,
147 'description': 'RenderScript warnings',
148 'patterns': [r'.*\.rscript:.*: warning: ']},
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700149 {'category': 'RenderScript', 'severity': Severity.HIGH,
150 'description': 'RenderScript is deprecated',
151 'patterns': [r'.*: warning: Renderscript is deprecated:.+']},
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800152 # Broken/partial warning messages will be skipped.
153 {'category': 'Misc', 'severity': Severity.SKIP,
154 'description': 'skip, ,',
155 'patterns': [r".*: warning: ,?$"]},
156 {'category': 'C/C++', 'severity': Severity.SKIP,
157 'description': 'skip, In file included from ...',
158 'patterns': [r".*: warning: In file included from .+,"]},
159 # catch-all for warnings this script doesn't know about yet
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800160 {'category': 'C/C++', 'severity': Severity.UNMATCHED,
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800161 'description': 'Unclassified/unrecognized warnings',
162 'patterns': [r".*: warning: .+"]},
163]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800164
165
166compile_patterns(warn_patterns)