question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-script-url: add option to allow `javascript:void(0)`

See original GitHub issue

What rule do you want to change?

no-script-url

Does this change cause the rule to produce more or fewer warnings?

Fewer, if option is enabled

How will the change be implemented? (New option, new default behavior, etc.)?

New option: allowVoidZero

Please provide some example code that this change will affect:

// valid with the option enabled
<form action="javascript:void(0)" onSubmit={() => doSomething()}>
</form>

// still invalid with the option enabled
<a href="javascript:alert('hello')">eval link</a>

What does the rule currently do for this code?

Currently, javascript:void(0) strings are flagged as invalid code because it is indeed technically a form of eval.

What will the rule do after it’s changed?

With the option enabled, the javascript:void(0) string (but no other javascript:-prefixed string) would be treated as an idiomatic “no-op” that it is, commonly used for things like forms and links.

Of note: for links people often use #, but it still requires to do event.preventDefault() to avoid address bar change. For forms, # definitely requires event.preventDefault() because otherwise form contents are appended directly to the URL. No-op URLs help skip that boilerplate a bit and are fairly resilient.

Happy to work on a PR if this makes sense to the maintainers! Thanks, by the way, for your hard work on the project.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Oct 13, 2018

It looks like we weren’t able to obtain consensus around this issue from the ESLint team. I’m going to close this issue. This doesn’t mean the issue wasn’t a good idea: it’s just something the team cannot commit to implementing at this time. Thanks for contributing regardless, we appreciate it!

0reactions
xiaotiandadacommented, Jan 15, 2019

orz

Read more comments on GitHub >

github_iconTop Results From Across the Web

<form action="Javascript:void(0)" > - no-script-url error - Stack ...
I was having just this problem and then saw this pattern in the official Redux docs and it made a lot of sense...
Read more >
I get a javascript:void(0); when I am on some sites, how do I ...
javascript : void(0); is used as a placeholder URL to indicate that an onclick event is tied to the link to do the...
Read more >
What Does javascript:void(0); Mean? - freeCodeCamp
When a function is void, it means that the function returns nothing. This is similar to functions in JavaScript which return undefined ...
Read more >
How to Avoid the Javascript: Void(0) Error in Vault?
Option 1: Enabling Javascript · Click on the icon in the top right corner (similar to Chrome's). · Click Add-ons. · Click on...
Read more >
What does javascript void 0 mean | Edureka Community
Here is an explanation: void operator. You would want to accomplish this using a link's href because, by default, a javascript: URL will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found