javascript - 如何配置 ESLint 以捕获未声明的局部变量
问题描述
在下面的代码中,我希望 ESLint 给我一个 undeclared variable 的编译错误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
推荐阅读
- java - Docker-compose ERR_NAME_NOT_RESOLVED (Java Spring + Angular)
- azure-devops - 如何使用 Azure Pipelines 仅在标签推送上而不是在分支上构建?
- c# - ObjectQuery - 它是什么,如何获得它?
- python - 使用 pandas 逐行检查两个数据框的数据
- c++ - 在类中定义数组的方法和字段
- r - 拆分具有重复拆分的数据框并命名新列表
- python-3.x - Python每隔n个字符拆分字符串
- html - 从 HTML 暗模式初始化的 NSAttributedString,如何设置默认前景色?
- javascript - SVGPanZoom 干扰动态 foreignObject 内容
- angular - 我无法在 localhost:8080 上运行我的 Angular 7 PWA