Skip to content

Commit cbc0b3b

Browse files
committed
Support removal of arrays
Match patterns such as "string-array" that would previously only return "array", and subsequently fail in `remove_resource_value`
1 parent 73eef7f commit cbc0b3b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

android_clean_app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Issue:
2323
Stores a single issue reported by Android Lint
2424
"""
2525
pattern = re.compile('The resource `?([^`]+)`? appears to be unused')
26+
pattern_array = re.compile('<`?([^`]+)`? name="`?([^`]+)`?">')
2627

2728
def __init__(self, filepath, remove_file):
2829
self.filepath = filepath
@@ -40,7 +41,13 @@ def add_element(self, message):
4041
if res_all:
4142
res = res_all[0]
4243
bits = res.split('.')[-2:]
43-
self.elements.append((bits[0], bits[1]))
44+
if bits[0] != 'array':
45+
type = bits[0]
46+
else:
47+
# array is a generic type, which may take form string-array, integer-array, etc.
48+
# The only way to get type is to parse from errorLine1 which is less reliable than message.
49+
type = re.findall(Issue.pattern_array, errorLine1)[0][0]
50+
self.elements.append((type, bits[1]))
4451
else:
4552
print("The pattern '%s' seems to find nothing in the error message '%s'. We can't find the resource and can't remove it. The pattern might have changed, please check and report this in github issues." % (
4653
Issue.pattern, message))

0 commit comments

Comments
 (0)