Skip to content

Commit 67825cd

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 67825cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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))

test/android_app/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
<resources>
33
<string name="app_name">android_app</string>
44
<string name="missing">missing</string>
5+
<string-array name="missing_array">
6+
<item>Test1</item>
7+
<item>Test2</item>
8+
</string-array>
59
</resources>

0 commit comments

Comments
 (0)