2020-01-10 19:33:40 +01:00
|
|
|
# python3
|
2019-12-10 04:32:03 +01:00
|
|
|
# Copyright (C) 2019 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""Warning patterns from other tools."""
|
|
|
|
|
2021-04-28 23:49:32 +02:00
|
|
|
# No need of doc strings for trivial small functions.
|
|
|
|
# pylint:disable=missing-function-docstring
|
|
|
|
|
2020-01-10 19:33:40 +01:00
|
|
|
# pylint:disable=relative-beyond-top-level
|
2020-02-28 00:39:18 +01:00
|
|
|
from .cpp_warn_patterns import compile_patterns
|
2020-01-10 19:33:40 +01:00
|
|
|
from .severity import Severity
|
2019-12-10 04:32:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def warn(name, severity, description, pattern_list):
|
|
|
|
return {
|
|
|
|
'category': name,
|
|
|
|
'severity': severity,
|
|
|
|
'description': name + ': ' + description,
|
|
|
|
'patterns': pattern_list
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def aapt(description, pattern_list):
|
|
|
|
return warn('aapt', Severity.MEDIUM, description, pattern_list)
|
|
|
|
|
|
|
|
|
|
|
|
def misc(description, pattern_list):
|
|
|
|
return warn('logtags', Severity.LOW, description, pattern_list)
|
|
|
|
|
|
|
|
|
|
|
|
def asm(description, pattern_list):
|
|
|
|
return warn('asm', Severity.MEDIUM, description, pattern_list)
|
|
|
|
|
|
|
|
|
2020-02-26 23:34:21 +01:00
|
|
|
def kotlin(description, pattern):
|
|
|
|
return warn('Kotlin', Severity.MEDIUM, description,
|
|
|
|
[r'.*\.kt:.*: warning: ' + pattern])
|
2020-01-06 21:02:27 +01:00
|
|
|
|
|
|
|
|
2020-01-13 23:05:17 +01:00
|
|
|
def yacc(description, pattern_list):
|
|
|
|
return warn('yacc', Severity.MEDIUM, description, pattern_list)
|
|
|
|
|
|
|
|
|
2020-02-26 23:34:21 +01:00
|
|
|
def rust(severity, description, pattern):
|
|
|
|
return warn('Rust', severity, description,
|
|
|
|
[r'.*\.rs:.*: warning: ' + pattern])
|
|
|
|
|
|
|
|
|
2020-01-10 19:33:40 +01:00
|
|
|
warn_patterns = [
|
2021-04-28 23:49:32 +02:00
|
|
|
# pylint does not recognize g-inconsistent-quotes
|
|
|
|
# pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
|
2019-12-10 04:32:03 +01:00
|
|
|
# aapt warnings
|
2020-01-10 19:33:40 +01:00
|
|
|
aapt('No comment for public symbol',
|
|
|
|
[r".*: warning: No comment for public symbol .+"]),
|
2019-12-10 04:32:03 +01:00
|
|
|
aapt('No default translation',
|
|
|
|
[r".*: warning: string '.+' has no default translation in .*"]),
|
|
|
|
aapt('Missing default or required localization',
|
|
|
|
[r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]),
|
|
|
|
aapt('String marked untranslatable, but translation exists',
|
|
|
|
[r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]),
|
|
|
|
aapt('empty span in string',
|
|
|
|
[r".*: warning: empty '.+' span found in text '.+"]),
|
|
|
|
# misc warnings
|
|
|
|
misc('Duplicate logtag',
|
|
|
|
[r".*: warning: tag \".+\" \(.+\) duplicated in .+"]),
|
|
|
|
# Assembler warnings
|
|
|
|
asm('ASM value size does not match register size',
|
|
|
|
[r".*: warning: value size does not match register size specified by the constraint and modifier"]),
|
|
|
|
asm('IT instruction is deprecated',
|
|
|
|
[r".*: warning: applying IT instruction .* is deprecated"]),
|
2021-06-08 23:52:45 +02:00
|
|
|
asm('section flags ignored',
|
|
|
|
[r".*: warning: section flags ignored on section redeclaration"]),
|
2021-06-02 01:03:22 +02:00
|
|
|
asm('setjmp/longjmp/vfork changed binding',
|
|
|
|
[r".*: warning: .*(setjmp|longjmp|vfork) changed binding to .*"]),
|
2019-12-10 04:32:03 +01:00
|
|
|
# NDK warnings
|
|
|
|
{'category': 'NDK', 'severity': Severity.HIGH,
|
|
|
|
'description': 'NDK: Generate guard with empty availability, obsoleted',
|
|
|
|
'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
|
|
|
|
# Protoc warnings
|
|
|
|
{'category': 'Protoc', 'severity': Severity.MEDIUM,
|
2020-01-10 19:33:40 +01:00
|
|
|
'description': 'Proto: Enum name collision after strip',
|
2019-12-10 04:32:03 +01:00
|
|
|
'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
|
|
|
|
{'category': 'Protoc', 'severity': Severity.MEDIUM,
|
|
|
|
'description': 'Proto: Import not used',
|
|
|
|
'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
|
|
|
|
# Kotlin warnings
|
2020-02-26 23:34:21 +01:00
|
|
|
kotlin('never used parameter or variable', '.+ \'.*\' is never used'),
|
|
|
|
kotlin('multiple labels', '.+ more than one label .+ in this scope'),
|
|
|
|
kotlin('type mismatch', 'type mismatch: '),
|
|
|
|
kotlin('is always true', '.+ is always \'true\''),
|
|
|
|
kotlin('no effect', '.+ annotation has no effect for '),
|
|
|
|
kotlin('no cast needed', 'no cast needed'),
|
|
|
|
kotlin('accessor not generated', 'an accessor will not be generated '),
|
|
|
|
kotlin('initializer is redundant', '.* initializer is redundant$'),
|
2020-02-01 01:14:04 +01:00
|
|
|
kotlin('elvis operator always returns ...',
|
2020-02-26 23:34:21 +01:00
|
|
|
'elvis operator (?:) always returns .+'),
|
|
|
|
kotlin('shadowed name', 'name shadowed: .+'),
|
|
|
|
kotlin('unchecked cast', 'unchecked cast: .* to .*$'),
|
|
|
|
kotlin('unreachable code', 'unreachable code'),
|
|
|
|
kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'),
|
2020-02-01 01:14:04 +01:00
|
|
|
kotlin('unnecessary safe call on a non-null receiver',
|
2020-02-26 23:34:21 +01:00
|
|
|
'unnecessary safe call on a non-null receiver'),
|
2020-01-06 21:02:27 +01:00
|
|
|
kotlin('Deprecated in Java',
|
2020-02-26 23:34:21 +01:00
|
|
|
'\'.*\' is deprecated. Deprecated in Java'),
|
2020-02-04 21:12:11 +01:00
|
|
|
kotlin('Replacing Handler for Executor',
|
2020-02-26 23:34:21 +01:00
|
|
|
'.+ Replacing Handler for Executor in '),
|
2020-01-06 21:02:27 +01:00
|
|
|
kotlin('library has Kotlin runtime',
|
2020-02-26 23:34:21 +01:00
|
|
|
'.+ has Kotlin runtime (bundled|library)'),
|
|
|
|
warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime',
|
|
|
|
['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']),
|
|
|
|
kotlin('other warnings', '.+'), # catch all other Kotlin warnings
|
2020-01-13 23:05:17 +01:00
|
|
|
# Yacc warnings
|
|
|
|
yacc('deprecate directive',
|
|
|
|
[r".*\.yy?:.*: warning: deprecated directive: "]),
|
2020-09-19 06:51:06 +02:00
|
|
|
yacc('reduce/reduce conflicts',
|
|
|
|
[r".*\.yy?: warning: .+ reduce/reduce conflicts "]),
|
2020-01-13 23:05:17 +01:00
|
|
|
yacc('shift/reduce conflicts',
|
|
|
|
[r".*\.yy?: warning: .+ shift/reduce conflicts "]),
|
|
|
|
{'category': 'yacc', 'severity': Severity.SKIP,
|
|
|
|
'description': 'yacc: fix-its can be applied',
|
|
|
|
'patterns': [r".*\.yy?: warning: fix-its can be applied."]},
|
2019-12-10 04:32:03 +01:00
|
|
|
# Rust warnings
|
2020-02-26 23:34:21 +01:00
|
|
|
rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'),
|
|
|
|
rust(Severity.MEDIUM, '... are deprecated',
|
|
|
|
('(.+ are deprecated$|' +
|
|
|
|
'use of deprecated item .* (use .* instead|is now preferred))')),
|
|
|
|
rust(Severity.MEDIUM, 'never used', '.* is never used:'),
|
|
|
|
rust(Severity.MEDIUM, 'unused import', 'unused import: '),
|
|
|
|
rust(Severity.MEDIUM, 'unnecessary attribute',
|
|
|
|
'.+ no longer requires an attribute'),
|
|
|
|
rust(Severity.MEDIUM, 'unnecessary parentheses',
|
|
|
|
'unnecessary parentheses around'),
|
|
|
|
# Catch all RenderScript warnings
|
|
|
|
{'category': 'RenderScript', 'severity': Severity.LOW,
|
|
|
|
'description': 'RenderScript warnings',
|
|
|
|
'patterns': [r'.*\.rscript:.*: warning: ']},
|
2021-06-02 01:03:22 +02:00
|
|
|
{'category': 'RenderScript', 'severity': Severity.HIGH,
|
|
|
|
'description': 'RenderScript is deprecated',
|
|
|
|
'patterns': [r'.*: warning: Renderscript is deprecated:.+']},
|
2019-12-10 04:32:03 +01:00
|
|
|
# Broken/partial warning messages will be skipped.
|
|
|
|
{'category': 'Misc', 'severity': Severity.SKIP,
|
|
|
|
'description': 'skip, ,',
|
|
|
|
'patterns': [r".*: warning: ,?$"]},
|
|
|
|
{'category': 'C/C++', 'severity': Severity.SKIP,
|
|
|
|
'description': 'skip, In file included from ...',
|
|
|
|
'patterns': [r".*: warning: In file included from .+,"]},
|
|
|
|
# catch-all for warnings this script doesn't know about yet
|
2020-01-10 19:33:40 +01:00
|
|
|
{'category': 'C/C++', 'severity': Severity.UNMATCHED,
|
2019-12-10 04:32:03 +01:00
|
|
|
'description': 'Unclassified/unrecognized warnings',
|
|
|
|
'patterns': [r".*: warning: .+"]},
|
|
|
|
]
|
2020-01-10 19:33:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
compile_patterns(warn_patterns)
|