如何配置 ESLint 以捕获未声明的局部变量

How to configure ESLint to catch undeclared local variables

在下面的代码中,我希望 ESLint 为未声明的变量 v1.

提供一个编译错误

有这样的选项吗?

<!DOCTYPE html> 
<html> 

<head> 
    <title>HTML Doctypes</title> 
    <script type="module">

    function f1() {
        v1=2//I want eslint to give me a 'compile-time' error for this line
    }
    if(performance.now == 12345){f1()}
    </script>
</head> 

<body> 
<p>HTML is easy to learn.</p> 
</body> 

</html> 

@ElAoutarHamza 我认为你的意思是 no-undef 而不是 no-unused-vars。这是对我有用的:

... 
<script type="module"> 
/*eslint no-var: "error"*/ 
/*eslint-env es6*/ 
/*eslint-env browser*/ 
/*eslint no-unused-vars: ["error", { "args": "all" }]*/ 
/*eslint no-undef: "error"*/
... 

这是输出:

sohrab@sohrab-HP-Notebook:~/proj/test$ eslint --ext .html testUseStrict.html
/home/sohrab/proj/test/testUseStrict.html 17:13 error 'v1' is not defined no-undef