BenoitZugmeyer / eslint-plugin-html

An ESLint plugin to extract and lint scripts from HTML files.
ISC License
430 stars 51 forks source link

Can't sharing the global scope between scripts in VSCode #100

Closed dumpkeys closed 5 years ago

dumpkeys commented 6 years ago

eslint@5.2.0 image add "sourceType": "script" change nothing

BenoitZugmeyer commented 6 years ago

I'm sorry but I can't reproduce. I tried this with the last version of vscode and its eslint extension and it works fine. Please send more information, like the eslint-plugin-html version, your .eslintrc or maybe a gist with a small project so I can reproduce.

Grawl commented 5 years ago

just reproduced this with Twig

image
"eslint": "^5.8.0",
"eslint-plugin-html": "^4.0.6",

VSCode 1.28.2

vscode-eslint 1.7.0

user settings:

    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "html",
        "twig"
    ]

Code sample:

<html class='no-site-js' lang='ru'>
    <head>
        <link href="https://fonts.googleapis.com/css?family=PT+Sans:400,700&amp;subset=cyrillic" rel="stylesheet">
        <script type='text/javascript'>
            const rootElement = document.getElementsByTagName('html')[0]
        </script>
        <script type='text/javascript'>
            window.rootElement = rootElement
            rootElement.classList.remove('no-site-js')
            rootElement.classList.add('site-js')
        </script>
        {% block head %}{% endblock %}
    </head>
</html>

Got this error in CLI too. This is not VSCode problem.

/path/to/project-name/base.twig
   5:10  error  'rootElement' is assigned a value but never used  no-unused-vars
   8:25  error  'rootElement' is not defined                      no-undef
   9:4   error  'rootElement' is not defined                      no-undef
  10:4   error  'rootElement' is not defined                      no-undef
Grawl commented 5 years ago

sample from readme causes this problem too

<script>
var foo = 1;
</script>

<script>
alert(foo);
</script>
/path/to/project-name/base.twig
  2:5  error  'foo' is assigned a value but never used  no-unused-vars
  6:7  error  'foo' is not defined                      no-undef
BenoitZugmeyer commented 5 years ago

Ok so I think I know what's going on. In your ESLint configuration (directly in your .eslintrc or in an external eslint config like eslint-config-standard):

Anyway, if you want more help I'll really need your eslint configuration.