Giter Site home page Giter Site logo

Comments (6)

BenoitZugmeyer avatar BenoitZugmeyer commented on June 10, 2024 1

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

from eslint-plugin-html.

Standard8 avatar Standard8 commented on June 10, 2024

I think you should be able to do something like:

<script type="application/javascript" type="module">
/* eslint-disable */

// Your code

/* eslint-enable */
</script>

from eslint-plugin-html.

wxiaoguang avatar wxiaoguang commented on June 10, 2024

It doesn't work because the syntax inside the tag is invalid JavaScript code window.myGlobal.var = {{.MyData}}

Before the comment /* eslint-disable */ takes effect, the parser reports syntax error first.

from eslint-plugin-html.

BenoitZugmeyer avatar BenoitZugmeyer commented on June 10, 2024

Please refer to Linting templates

from eslint-plugin-html.

wxiaoguang avatar wxiaoguang commented on June 10, 2024

I have read it. But there are a lot of template engines, not only PHP.

And // <?= "\n mydata = " . json_encode($var) . ";" ?> is quite ugly, and sometimes it's not feasible in other template engines.

If the whole <script> tag could be disabled from linting, then the code can be simple and clear. Maybe something like:

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

Is it feasible?

from eslint-plugin-html.

silverwind avatar silverwind commented on June 10, 2024

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:

<script>
  /* eslint-disable */
  ]
  /* eslint-enable */
</script>

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 -->
<script>
]
</script>
<!-- eslint-enable -->

from eslint-plugin-html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.