1# python3 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 18# No need of doc strings for trivial small functions. 19# pylint:disable=missing-function-docstring 20 21# pylint:disable=relative-beyond-top-level 22from .cpp_warn_patterns import compile_patterns 23from .severity import Severity 24 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 47def kotlin(description, pattern): 48 return warn('Kotlin', Severity.MEDIUM, description, 49 [r'.*\.kt:.*: warning: ' + pattern]) 50 51 52def yacc(description, pattern_list): 53 return warn('yacc', Severity.MEDIUM, description, pattern_list) 54 55 56def rust(severity, description, pattern): 57 return warn('Rust', severity, description, 58 [r'.*\.rs:.*: warning: ' + pattern]) 59 60 61warn_patterns = [ 62 # pylint does not recognize g-inconsistent-quotes 63 # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes 64 # aapt warnings 65 aapt('No comment for public symbol', 66 [r".*: warning: No comment for public symbol .+"]), 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, 115 'description': 'Proto: Enum name collision after strip', 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 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$'), 129 kotlin('elvis operator always returns ...', 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 .+'), 135 kotlin('unnecessary safe call on a non-null receiver', 136 'unnecessary safe call on a non-null receiver'), 137 kotlin('Deprecated in Java', 138 '\'.*\' is deprecated. Deprecated in Java'), 139 kotlin('Replacing Handler for Executor', 140 '.+ Replacing Handler for Executor in '), 141 kotlin('library has Kotlin runtime', 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 146 # Yacc warnings 147 yacc('deprecate directive', 148 [r".*\.yy?:.*: warning: deprecated directive: "]), 149 yacc('reduce/reduce conflicts', 150 [r".*\.yy?: warning: .+ reduce/reduce conflicts "]), 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."]}, 156 # Rust warnings 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: ']}, 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 179 {'category': 'C/C++', 'severity': Severity.UNMATCHED, 180 'description': 'Unclassified/unrecognized warnings', 181 'patterns': [r".*: warning: .+"]}, 182] 183 184 185compile_patterns(warn_patterns) 186