File tree Expand file tree Collapse file tree 3 files changed +54
-13
lines changed
src/compiler/compile/nodes
test/validator/samples/a11y-anchor-is-valid Expand file tree Collapse file tree 3 files changed +54
-13
lines changed Original file line number Diff line number Diff line change @@ -423,22 +423,29 @@ export default class Element extends Node {
423423
424424 // handle special cases
425425 if ( this . name === 'a' ) {
426- const attribute = attribute_map . get ( 'href' ) || attribute_map . get ( 'xlink:href' ) ;
427-
428- if ( attribute ) {
429- const value = attribute . get_static_value ( ) ;
430-
431- if ( value === '' || value === '#' || / ^ \W * j a v a s c r i p t : / i. test ( value ) ) {
432- component . warn ( attribute , {
426+ const href_attribute = attribute_map . get ( 'href' ) || attribute_map . get ( 'xlink:href' ) ;
427+ const id_attribute = attribute_map . get ( 'id' ) ;
428+ const name_attribute = attribute_map . get ( 'name' ) ;
429+
430+ if ( href_attribute ) {
431+ const href_value = href_attribute . get_static_value ( ) ;
432+
433+ if ( href_value === '' || href_value === '#' || / ^ \W * j a v a s c r i p t : / i. test ( href_value ) ) {
434+ component . warn ( href_attribute , {
433435 code : `a11y-invalid-attribute` ,
434- message : `A11y: '${ value } ' is not a valid ${ attribute . name } attribute`
436+ message : `A11y: '${ href_value } ' is not a valid ${ href_attribute . name } attribute`
435437 } ) ;
436438 }
437439 } else {
438- component . warn ( this , {
439- code : `a11y-missing-attribute` ,
440- message : `A11y: <a> element should have an href attribute`
441- } ) ;
440+ const id_attribute_valid = id_attribute && id_attribute . get_static_value ( ) !== '' ;
441+ const name_attribute_valid = name_attribute && name_attribute . get_static_value ( ) !== '' ;
442+
443+ if ( ! id_attribute_valid && ! name_attribute_valid ) {
444+ component . warn ( this , {
445+ code : `a11y-missing-attribute` ,
446+ message : `A11y: <a> element should have an href attribute`
447+ } ) ;
448+ }
442449 }
443450 }
444451
Original file line number Diff line number Diff line change 11<a >not actually a link</a >
22<a href =' ' >invalid</a >
33<a href =' #' >invalid</a >
4- <a href =" javascript:void(0)" >invalid</a >
4+ <a href =' javascript:void(0)' >invalid</a >
5+ <a name =' ' >invalid</a >
6+ <a id =' ' >invalid</a >
7+ <a name =' fragment' >valid</a >
8+ <a id =' fragment' >valid</a >
Original file line number Diff line number Diff line change 5858 "character" : 102
5959 },
6060 "pos" : 77
61+ },
62+ {
63+ "code" : " a11y-missing-attribute" ,
64+ "message" : " A11y: <a> element should have an href attribute" ,
65+ "start" : {
66+ "line" : 5 ,
67+ "column" : 0 ,
68+ "character" : 115
69+ },
70+ "end" : {
71+ "line" : 5 ,
72+ "column" : 22 ,
73+ "character" : 137
74+ },
75+ "pos" : 115
76+ },
77+ {
78+ "code" : " a11y-missing-attribute" ,
79+ "message" : " A11y: <a> element should have an href attribute" ,
80+ "start" : {
81+ "line" : 6 ,
82+ "column" : 0 ,
83+ "character" : 138
84+ },
85+ "end" : {
86+ "line" : 6 ,
87+ "column" : 20 ,
88+ "character" : 158
89+ },
90+ "pos" : 138
6191 }
6292]
You can’t perform that action at this time.
0 commit comments