js: Avoid href="#" for buttons with a JavaScript click handler.

As seen in
https://chat.zulip.org/#narrow/stream/9-issues/topic/edit.20history.20bug/near/1320430,
clicking such a link takes you to the user's default view if the click
handler throws an exception before doing preventDefault().

There hrefs also have the negative effect of having your browser claim
that clicking the link will navigate you to the default view, which it
won't.

Comes with a linter rule to prevent future instances, since it seems
there are some recently added ones, though they are likely the result
of copy/paste.
This commit is contained in:
Tim Abbott
2022-02-08 17:38:12 -08:00
parent 03d3439784
commit 729c09074a
11 changed files with 32 additions and 27 deletions

View File

@@ -766,6 +766,11 @@ handlebars_rules = RuleList(
"pattern": r'"{{t "',
"description": "Invalid quoting for HTML element with translated string.",
},
{
"pattern": r'href="#"',
"description": 'Avoid href="#" for elements with a JavaScript click handler.',
"exclude": {"static/templates/navbar.hbs"},
},
],
)