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
Linter: Make html-anchor-require-href Action View Helper aware (#1367)
Based on the infrastructure introduced in #1347 we can now start making
the linter rules aware of the Action View Tag Helpers.
The `html-anchor-require-href` linter rule is now also able to flag the
following:
```erb
<%= link_to "Home", "#" %>
```
"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,52 @@ 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.',
'Avoid `javascript:void(0)` in `href` on `<a>`. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead.',
46
+
hrefAttribute.location,
38
47
)
48
+
49
+
return
50
+
}
51
+
52
+
if(this.hasNilHrefValue(hrefAttribute)){
53
+
this.addOffense(
54
+
"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
+
constJAVASCRIPT_VOID_HREF_MESSAGE='Avoid `javascript:void(0)` in `href` on `<a>`. Links should navigate somewhere. If you need a clickable element without navigation, use a `<button>` instead.'
10
+
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