编辑:我没有意识到错误消息甚至不是来自ESLint,而是来自Visual Studio Code中的 [js] .我会删除这个问题,但它可能会帮助其他人误解ESLint的[js]输出.仍然很想知道这[js]
件事是什么样的过程.
我被告知要定义一个项目范围的.eslintrc.js文件,以确保团队的代码符合通用标准.
使用预设运行ESLint eslint:recommended
会给出以下错误消息
The property "parentNode" does not exist for the type "EventTarget".
Run Code Online (Sandbox Code Playgroud)
这是有问题的代码:
window.addEventListener('keydown', event => {
const currentTag = event.target.parentNode.tagName;
/* ... */
})
Run Code Online (Sandbox Code Playgroud)
我知道可能有event.target
s 不是 HTMLElement
s,但我应该如何编码 - 或配置ESLint - 所以这一行不再产生ESLint错误?只要ESLint报告任何错误,我们就计划让构建失败,因此必须解决这个问题.
导致类似错误的第二行代码:
document.activeElement.click();
Run Code Online (Sandbox Code Playgroud)
导致ESLint错误
The property "click" does not exist for the type "Element".
Run Code Online (Sandbox Code Playgroud)
第三个例子:
const rows = this.childNodes[1].querySelectorAll('tr');
Run Code Online (Sandbox Code Playgroud)
投
The property "querySelectorAll" does not exist for the type "Node & ChildNode". …
Run Code Online (Sandbox Code Playgroud) 例如,我在.html文件中的某处输入:
temp:some-id
Run Code Online (Sandbox Code Playgroud)
并期望我的代码片段创建魔法使用指定的"some-id"返回:
<script type="text/template" id="some-id"></script>
Run Code Online (Sandbox Code Playgroud)
所以我需要一种方法来触发一些文本并将一些参数传递给片段创建文件,因此当触发发生时,我可以将这些参数分配给.sublime-snippet内的一些tab-placeholder.有任何想法吗?
如果重要,请使用sublime text 2.
ecmascript-6 ×1
eslint ×1
eslintrc ×1
javascript ×1
sublimetext ×1
sublimetext2 ×1
sublimetext3 ×1