Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using alert, prompt or confirm in an inlined event handler gives warning #2648

Closed
EmilTholin opened this issue May 2, 2019 · 4 comments · Fixed by #2649
Closed

Using alert, prompt or confirm in an inlined event handler gives warning #2648

EmilTholin opened this issue May 2, 2019 · 4 comments · Fixed by #2649

Comments

@EmilTholin
Copy link
Member

EmilTholin commented May 2, 2019

Using alert, prompt or confirm in an inlined event handler gives a warning like 'alert' is not defined. Consider adding a <script> block with 'export let alert' to declare a prop. REPL

<script>
  let isConfirmed = false;
  let promptValue = '';
</script>

<button on:click="{() => alert('foo')}">Click me</button>
<div>
  <button on:click="{() => promptValue = prompt()}">Prompt me</button>
  {promptValue}
</div>
<div>
  <button on:click="{() => isConfirmed = confirm()}">Confirm</button>
  {isConfirmed}
</div>
@EmilTholin EmilTholin changed the title Using alert in an inlined event handler gives warning Using alert, prompt or confirm in an inlined event handler gives warning May 2, 2019
@mrkishi
Copy link
Member

mrkishi commented May 2, 2019

While this was required in v2, shouldn't this be removed from v3? While it does eventually catch actual errors, wouldn't this better fit linters? Assuming global knowledge seems a bit overzealous from the compiler.

@Conduitry
Copy link
Member

I'd have to do some thinking about how to support that with the way eslint-plugin-svelte3 is currently written. Right now, all of the linting messages that it presents outside of the script block are just passed-along warnings from the Svelte compiler. So, yes, I think there is an argument for this being the responsibility of the linter (at which point you could define your own globals, specify whether this would be a warning or an error, etc) but the official tooling for that isn't ready for that yet.

@mrkishi
Copy link
Member

mrkishi commented May 4, 2019

@Conduitry how does eslint-plugin-svelte3 deal with the script code? Could expressions in attributes eventually be handled the same? Or is this going to require some large changes?

I ask because while that doesn't happen, maybe we could get Svelte to emit the same warnings for the script blocks? It'd at least be consistent since both have access to the same globals.

@Conduitry
Copy link
Member

It does require some medium-size changes, but I made a lot of them already yesterday 😁 I'm going to need the PR for exposing svelte.walk to be released in a tagged version, and then I have to tidy some stuff up, and then I'll be ready for an initial version of experimental opt-in linting of expressions in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants