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.

Is it possbile to eslint-disable a script(type=module)?

See original GitHub issue

When working with backend MVC projects, sometimes the code could be:

<!-- I want to disable eslint-plugin-html for this script block -->
<script type="module">
    window.myGlobal.var = {{.MyData}};  // here is invalid JS syntax, but it's rendered by backend template engine correctly.

<!--  eslint-plugin-html works well for this block, and it should be enabled -->
<script type="module">

What we need here is to make eslint-plugin-html skip a whole <script> block because code inside it is not valid JS syntax.

When using eslint-plugin-html, I can not find a proper way to disable the eslint for the script(type=module) block (I do not want ignore the whole file).

I know a trick that: <script><!-- /* eslint-disable */ --></script>, but it doesn’t work for script(type=module)

For traditional <script> we can use <script><!-- /* eslint-disable */ --></script>.

But for <script type=module>, this trick doesn’t work anymore because the module script doesn’t accept <!-- HTML comment.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

BenoitZugmeyercommented, Jul 18, 2022

Thank you for the suggestion, it has been implemented and released as part of v7.0.0.

silverwindcommented, Jul 11, 2022

I think the bug here is that invalid JS between eslint-disable and eslint-enable trips this module’s parser when it should ideally not try to parse anything between such tags:

  /* eslint-disable */
  /* eslint-enable */

The bug is reproducible with a regular .js file too, so I think espree is not correctly ignoring code between disable/enable sections as it expects the whole file/block to be valid JS, which generally is true for .js files but it’s certainly a problem with templated HTML.

What could work (if eslint-plugin-html decides to support it) would be support the disable/enable comment as HTML, outside the script block, so the invalid block is not passed to eslint in first place, e.g.

<!-- eslint-disable -->
<!-- eslint-enable -->
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possbile to eslint-disable a script(type=module)? · Discussion ...
I want to disable eslint for this script block --> <script type="module"> window.myGlobal.var = {{.MyData}}; // here is invalid JS syntax, but it's...
Read more >
Turning off eslint rule for a specific file - Stack Overflow
1) Disabling "All rules"​​ Two ways you can do this: Put /* eslint-disable-line */ at the end of the line(s), or /* eslint-disable-next-line...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
To disable rule warnings in a part of a file, use block comments in the following format: ... You can also disable or...
Read more >
How to disable ESLint for some lines, files or folders
But, sometimes it's necessary to disable it. In this tutorial, you'll learn how to turn off ESLint for certain directories and files.
Read more >
eslint-plugin-html - npm
Disabling ESLint​​ Disabled script tags are completely ignored: their content will not be parsed as JavaScript. You can use this to disable ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found