Closed dumpkeys closed 5 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.
just reproduced this with Twig
"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&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
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
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
):
you probably have parserOptions.sourceType
set to 'module'
, so the behavior is expected: modules doesn't share scope, as stated in the README. You can set the sourceType to 'script'
to activate the scope sharing
you may have parserOptions.ecmaFeatures.globalReturn
set to true
(or using the 'node' environment). I just fixed something to handle this particular case (see 551b01d).
Anyway, if you want more help I'll really need your eslint configuration.
eslint@5.2.0 add "sourceType": "script" change nothing