Beispiel #1
0
def check(context):  # type: (xiblint.xibcontext.XibContext) -> None
    for button in context.tree.findall(".//button"):
        state_normal = button.find("./state[@key='normal']")
        if (state_normal is None or 'title' in state_normal.attrib
                or view_is_accessibility_element(button) is False
                or view_accessibility_label(button)
                or get_view_user_defined_attr(button, 'accessibilityFormat')):
            continue

        if 'image' in state_normal.attrib:
            context.error(
                button, "Button with image '{}' and no title; "
                "should either have an accessibility label or 'Accessibility Enabled' unchecked",
                state_normal.attrib['image'])

        if 'backgroundImage' in state_normal.attrib:
            context.error(
                button, "Button with background image '{}' and no title "
                "should either have an accessibility label or 'Accessibility Enabled' unchecked",
                state_normal.attrib['backgroundImage'])

    # For barButtonItem, we expect use of a LyftUI extension
    for bar_button_item in context.tree.findall(".//barButtonItem"):
        if ('image' in bar_button_item.attrib
                and 'title' not in bar_button_item.attrib
                and get_view_user_defined_attr(bar_button_item,
                                               'voiceoverLabel') is None):
            context.error(
                bar_button_item, "Bar button item with image {} and no title "
                "should have a user-defined `voiceoverLabel` attribute",
                bar_button_item.get('image'))
Beispiel #2
0
def check_view(context, view):
    accessibility_source_destination_ids = [
        outlet_connection.get('destination')
        for outlet_connection in view.findall(
            "./connections/outletCollection[@property='accessibilitySources']")
    ]

    accessibility_sources = [
        context.tree.find(".//*[@id='{}']".format(destination_id))
        for destination_id in accessibility_source_destination_ids
    ]
    accessibility_sources_count = len(accessibility_sources)

    #
    # Ensure accessibilityFormat iff accessibilitySources
    #
    accessibility_format = get_view_user_defined_attr(view,
                                                      'accessibilityFormat')
    if accessibility_format is None and accessibility_sources_count != 0:
        context.error(
            view,
            "View has {} accessibility source(s) but accessibilityFormat is unset.",
            accessibility_sources_count)
        return

    used_identifiers = set(get_accessibility_identifiers(accessibility_format))
    if used_identifiers:
        check_new_format(context, view, accessibility_format,
                         accessibility_sources, used_identifiers)
    else:
        check_old_format(context, view, accessibility_format,
                         accessibility_sources)
Beispiel #3
0
 def check(self, context):  # type: (XibContext) -> None
     for image_view in context.tree.findall(".//imageView"):
         if (
                 view_is_accessibility_element(image_view) is True and
                 not view_accessibility_label(image_view) and
                 not get_view_user_defined_attr(image_view, 'accessibilityFormat')
         ):
             context.error(image_view, "Image is accessible but has no accessibility label")
Beispiel #4
0
def check(context):  # type: (xiblint.xibcontext.XibContext) -> None
    for element in context.tree.findall(".//textField") + context.tree.findall(
            ".//textView"):
        placeholder = (element.get('placeholder') if element.tag == 'textField'
                       else get_view_user_defined_attr(element, 'placeholder'))
        if (placeholder is not None
                and element.find('./accessibility[@label]') is None
                and view_is_accessibility_element(element) is not False):
            context.error(
                element,
                "{} with placeholder text '{}' but no accessibility label",
                element.tag, element.get('placeholder'))
    def check(self, context):  # type: (XibContext) -> None
        for button in context.tree.findall(".//button"):
            state_normal = button.find("./state[@key='normal']")
            if (state_normal is None or 'title' in state_normal.attrib
                    or view_is_accessibility_element(button) is False
                    or view_accessibility_label(button) or
                    get_view_user_defined_attr(button, 'accessibilityFormat')):
                continue

            if 'image' in state_normal.attrib:
                context.error(
                    button, "Button with image '{}' and no title; "
                    "should either have an accessibility label or 'Accessibility Enabled' unchecked",
                    state_normal.attrib['image'])

            if 'backgroundImage' in state_normal.attrib:
                context.error(
                    button, "Button with background image '{}' and no title "
                    "should either have an accessibility label or 'Accessibility Enabled' unchecked",
                    state_normal.attrib['backgroundImage'])