eslint-plugin-html icon indicating copy to clipboard operation
eslint-plugin-html copied to clipboard

How to add support within {% javascript %} tag in .liquid files

Open alvinkonda opened this issue 9 months ago • 5 comments

Currently, the plugin is working fine in .liquid files if my jS code is within the normal <script> tag but I want to add support if I use the recommended way from Shopify to add JS codes, within the {% javascript %} some JS code {% endjavascript %} tag

Any solution?

I have the following in my eslint.config.mjs file:

  {
    files: ["**/*.liquid"],
    plugins: { html },
    settings: {
      "html/html-extensions": [".liquid"],
    },
  },

alvinkonda avatar Mar 18 '25 13:03 alvinkonda

export default [ { files: ["**/*.liquid"], plugins: { html: require('eslint-plugin-html'), }, settings: { "html/html-extensions": [".liquid"], "html/javascript-tag-names": ["javascript"], // {% javascript %} define tags }, rules: { // İhtiyaca göre kurallar ekleyebilirsiniz }, }, ];

and update npx eslint **/*.liquid

hakan4773 avatar Mar 18 '25 14:03 hakan4773

Thanks for your reply.

That didn't work but for the moment I'm wrapping my code with a // <script> comment and that seems to work, but the biggest advantage for me would be to enable Intellisense. Not sure how to archive that.

alvinkonda avatar Mar 18 '25 17:03 alvinkonda

Please don't follow @hakan4773 advices, as it is LLM generated bulshit.

Unfortunately at this time the plugin does not support templates. See the README for a dirty workaround.

BenoitZugmeyer avatar Mar 18 '25 17:03 BenoitZugmeyer

Please excuse me if I misdirected you.

hakan4773 avatar Mar 18 '25 18:03 hakan4773

@BenoitZugmeyer Thanks for the reply. Well Eslint is working within those tags fine using the // <script> workaround like this in case someone else needs it.

{% javascript %}
// <script>
some Js code
// </script>
{% endjavascript %}

but my next step would be to have vsCode Intellisense there also. I will see if i can get a solution for it.

alvinkonda avatar Mar 18 '25 19:03 alvinkonda