Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_new_format(context, view, accessibility_format, accessibility_sources, used_identifiers):
sources_by_id = get_accessibility_sources_by_id(accessibility_sources)
source_identifiers = set(sources_by_id.keys())
missing_identifiers = used_identifiers - source_identifiers
extra_source_identifiers = source_identifiers - used_identifiers
for identifier in missing_identifiers:
context.error(view, "Missing accessibility source for identifier '{}' in accessibility format", identifier)
for identifier in extra_source_identifiers:
context.error(view, "Unused accessibility source with identifier '{}' in accessibility format", identifier)
unidentified_sources = set(accessibility_sources) - set(sources_by_id.values())
for source in unidentified_sources:
context.error(view, "Accessibility source '{}' missing accessibility identifier", get_object_id(source))
if '%@' in accessibility_format:
context.error(view, "New-style accessibility format contains '%@'")
def error(self, element, message, *args):
self.success = False
object_id = get_object_id(element)
moniker = self._get_moniker(element)
new_error = "{}{}{}".format(
"{}: ".format(object_id) if object_id else '',
"'{}': ".format(moniker) if moniker else '',
message.format(*args),
)
new_error_dict = {
"file": self.path,
"line": element.line,
"error": new_error,
"rule": self.rule_name,
}
self.errors.append(new_error_dict)