Skip to content

Commit 75eb5d0

Browse files
feature: specify the color property (e.g. textColor, tintColor) that is causing the named_colors warning. (#65)
Added the specific color property that is causing the warning in the error message. ``` Use of custom textColors is not allowed. Use a named color instead. [rule: named_colors] Use of custom tintColors is not allowed. Use a named color instead. [rule: named_colors] Use of custom backgroundColors is not allowed. Use a named color instead. [rule: named_colors] "foo" is not one of the allowed backgroundColors: `bar`,`baz`. [rule: named_colors] ``` This way when the developer uses the `object_id` to find the problematic object, they don't need to look at the xml to know which color property (e.g backgroundColor, textColor, tintColor) to modify.
1 parent 8427efc commit 75eb5d0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

xiblint/rules/named_colors.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,30 @@ def check(self, context): # type: (XibContext) -> None
4242
):
4343
continue
4444

45+
color = element.get('key') if element.get('key') else 'color'
46+
4547
# If `systemColor` or `catalog` is present, it's a named system color
4648
if (
4749
element.get('systemColor') is not None or
4850
element.get('cocoaTouchSystemColor') is not None or
4951
element.get('catalog') is not None
5052
):
5153
if not allow_system_colors:
52-
context.error(element, "Use of named system colors is not allowed. Use a named color instead.")
54+
context.error(element,
55+
"Use of named system {}s is not allowed. Use a named color instead."
56+
.format(color))
5357
continue
5458

5559
# Require a name
5660
color_name = element.get('name')
5761
if color_name is None:
58-
context.error(element, "Use of custom colors is not allowed. Use a named color instead.")
62+
context.error(element,
63+
"Use of custom {}s is not allowed. Use a named color instead."
64+
.format(color))
5965
continue
6066

6167
# If allowed_colors is set, verify that color_name is included
6268
options_string = '`, `'.join(map(str, allowed_colors))
6369
if allowed_colors and color_name not in allowed_colors:
64-
context.error(element, '"{}" is not one of the allowed colors: `{}`.'
65-
.format(color_name, options_string))
70+
context.error(element, '"{}" is not one of the allowed {}s: `{}`.'
71+
.format(color_name, color, options_string))

0 commit comments

Comments
 (0)