Is it possbile to eslint-disable a script(type=module)?
See original GitHub issueWhen 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.
</script>
<!-- eslint-plugin-html works well for this block, and it should be enabled -->
<script type="module">
console.log(window.myGlobal.var);
</script>
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:
- Created a year ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the suggestion, it has been implemented and released as part of v7.0.0.
I think the bug here is that invalid JS between
eslint-disable
andeslint-enable
trips this module’s parser when it should ideally not try to parse anything between such tags:The bug is reproducible with a regular
.js
file too, so I thinkespree
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.