在以下代码中,我希望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,我认为您的意思是没有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