You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Add an `href` attribute to `<a>` to ensure it is focusable and accessible. Links should go somewhere, you probably want to use a `<button>` instead.",
25
+
"Add an `href` attribute to `<a>` to ensure it is focusable and accessible. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead.",
26
26
node.tag_name!.location,
27
27
)
28
28
@@ -33,10 +33,43 @@ class AnchorRequireHrefVisitor extends BaseRuleVisitor {
33
33
34
34
if(hrefValue==="#"){
35
35
this.addOffense(
36
-
"Add an `href` attribute to `<a>` to ensure it is focusable and accessible. Links should go somewhere, you probably want to use a `<button>` instead.",
37
-
node.tag_name!.location,
36
+
'Avoid `href="#"` on `<a>`. `href="#"` does not navigate anywhere, scrolls the page to the top, and adds `#` to the URL. If you need a clickable element without navigation, use a `<button>` instead.',
37
+
hrefAttribute.location,
38
38
)
39
+
40
+
return
41
+
}
42
+
43
+
if(this.hasNilHrefValue(hrefAttribute)){
44
+
this.addOffense(
45
+
"Avoid passing `nil` as the URL for `link_to`. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead.",
constMESSAGE="Add an `href` attribute to `<a>` to ensure it is focusable and accessible. Links should go somewhere, you probably want to use a `<button>` instead."
7
+
constMISSING_HREF_MESSAGE="Add an `href` attribute to `<a>` to ensure it is focusable and accessible. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead."
8
+
constHASH_HREF_MESSAGE='Avoid `href="#"` on `<a>`. `href="#"` does not navigate anywhere, scrolls the page to the top, and adds `#` to the URL. If you need a clickable element without navigation, use a `<button>` instead.'
9
+
constNIL_HREF_MESSAGE="Avoid passing `nil` as the URL for `link_to`. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead."
0 commit comments