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

问题描述 投票:0回答:1

在以下代码中,我希望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> 
javascript eslint static-analysis
1个回答
0
投票

@@ ElAoutarHamza,我认为您的意思是没有undef而不是没有使用的var。这对我有用:

... 
<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
© www.soinside.com 2019 - 2024. All rights reserved.