use aria-query and move warnings to compiler_warnings file

pull/6241/head
tanhauhau 4 years ago
parent dee764b830
commit 6fd4aae6e7

@ -107,6 +107,10 @@ export default {
code: 'a11y-unknown-role', code: 'a11y-unknown-role',
message: `A11y: Unknown role '${role}'` + (suggestion ? ` (did you mean '${suggestion}'?)` : '') message: `A11y: Unknown role '${role}'` + (suggestion ? ` (did you mean '${suggestion}'?)` : '')
}), }),
a11y_no_abstract_role: (role: string | boolean) => ({
code: 'a11y-no-abstract-role',
message: `A11y: abstract role '${role}' is forbidden`
}),
a11y_no_redundant_roles: (role: string | boolean) => ({ a11y_no_redundant_roles: (role: string | boolean) => ({
code: 'a11y-no-redundant-roles', code: 'a11y-no-redundant-roles',
message: `A11y: Redundant role '${role}'` message: `A11y: Redundant role '${role}'`

@ -32,9 +32,7 @@ const aria_attribute_set = new Set(aria_attributes);
const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic graphics-document graphics-object graphics-symbol grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' '); const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic graphics-document graphics-object graphics-symbol grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' ');
const aria_role_set = new Set(aria_roles); const aria_role_set = new Set(aria_roles);
const aria_role_abstract_set = new Set(roles.keys().filter(role => roles.get(role).abstract));
const aria_roles_abstract = 'command composite input landmark range roletype section sectionhead select structure widget window'.split(' ');
const aria_roles_abstract_set = new Set(aria_roles_abstract);
const a11y_required_attributes = { const a11y_required_attributes = {
a: ['href'], a: ['href'],
@ -483,12 +481,8 @@ export default class Element extends Node {
const value = attribute.get_static_value(); const value = attribute.get_static_value();
if (value && aria_roles_abstract_set.has(value as string)) { if (value && aria_role_abstract_set.has(value as ARIARoleDefintionKey)) {
const message = `A11y: abstract role '${value}' is forbidden`; component.warn(attribute, compiler_warnings.a11y_no_abstract_role(value));
component.warn(attribute, {
code: 'a11y-no-abstract-role',
message
});
} else if (value && !aria_role_set.has(value as string)) { } else if (value && !aria_role_set.has(value as string)) {
// @ts-ignore // @ts-ignore
const match = fuzzymatch(value, aria_roles); const match = fuzzymatch(value, aria_roles);

Loading…
Cancel
Save