Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 1 | # python3 |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 2 | # 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 Hsieh | 98b285d | 2021-04-28 14:49:32 -0700 | [diff] [blame] | 18 | # No need of doc strings for trivial small functions. |
| 19 | # pylint:disable=missing-function-docstring |
| 20 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 21 | # pylint:disable=relative-beyond-top-level |
Chih-Hung Hsieh | 3cce2bc | 2020-02-27 15:39:18 -0800 | [diff] [blame] | 22 | from .cpp_warn_patterns import compile_patterns |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 23 | from .severity import Severity |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def 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 | |
| 35 | def aapt(description, pattern_list): |
| 36 | return warn('aapt', Severity.MEDIUM, description, pattern_list) |
| 37 | |
| 38 | |
| 39 | def misc(description, pattern_list): |
| 40 | return warn('logtags', Severity.LOW, description, pattern_list) |
| 41 | |
| 42 | |
| 43 | def asm(description, pattern_list): |
| 44 | return warn('asm', Severity.MEDIUM, description, pattern_list) |
| 45 | |
| 46 | |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 47 | def kotlin(description, pattern): |
| 48 | return warn('Kotlin', Severity.MEDIUM, description, |
| 49 | [r'.*\.kt:.*: warning: ' + pattern]) |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 50 | |
| 51 | |
Chih-Hung Hsieh | 5392cdb | 2020-01-13 14:05:17 -0800 | [diff] [blame] | 52 | def yacc(description, pattern_list): |
| 53 | return warn('yacc', Severity.MEDIUM, description, pattern_list) |
| 54 | |
| 55 | |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 56 | def rust(severity, description, pattern): |
| 57 | return warn('Rust', severity, description, |
| 58 | [r'.*\.rs:.*: warning: ' + pattern]) |
| 59 | |
| 60 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 61 | warn_patterns = [ |
Chih-Hung Hsieh | 98b285d | 2021-04-28 14:49:32 -0700 | [diff] [blame] | 62 | # pylint does not recognize g-inconsistent-quotes |
| 63 | # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 64 | # aapt warnings |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 65 | aapt('No comment for public symbol', |
| 66 | [r".*: warning: No comment for public symbol .+"]), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 67 | 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 Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 115 | 'description': 'Proto: Enum name collision after strip', |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 116 | '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 Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 121 | 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 Hsieh | a7f5f3f | 2020-01-31 16:14:04 -0800 | [diff] [blame] | 129 | kotlin('elvis operator always returns ...', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 130 | '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 Hsieh | a7f5f3f | 2020-01-31 16:14:04 -0800 | [diff] [blame] | 135 | kotlin('unnecessary safe call on a non-null receiver', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 136 | 'unnecessary safe call on a non-null receiver'), |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 137 | kotlin('Deprecated in Java', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 138 | '\'.*\' is deprecated. Deprecated in Java'), |
Chih-Hung Hsieh | ed74896 | 2020-02-04 12:12:11 -0800 | [diff] [blame] | 139 | kotlin('Replacing Handler for Executor', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 140 | '.+ Replacing Handler for Executor in '), |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 141 | kotlin('library has Kotlin runtime', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 142 | '.+ 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 Hsieh | 5392cdb | 2020-01-13 14:05:17 -0800 | [diff] [blame] | 146 | # Yacc warnings |
| 147 | yacc('deprecate directive', |
| 148 | [r".*\.yy?:.*: warning: deprecated directive: "]), |
Chih-Hung Hsieh | e8f4a71 | 2020-09-18 21:51:06 -0700 | [diff] [blame] | 149 | yacc('reduce/reduce conflicts', |
| 150 | [r".*\.yy?: warning: .+ reduce/reduce conflicts "]), |
Chih-Hung Hsieh | 5392cdb | 2020-01-13 14:05:17 -0800 | [diff] [blame] | 151 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 156 | # Rust warnings |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 157 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 171 | # 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 Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 179 | {'category': 'C/C++', 'severity': Severity.UNMATCHED, |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 180 | 'description': 'Unclassified/unrecognized warnings', |
| 181 | 'patterns': [r".*: warning: .+"]}, |
| 182 | ] |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 183 | |
| 184 | |
| 185 | compile_patterns(warn_patterns) |