我有一个Javascript浏览器项目,该项目分为多个文件,并且无法在同一全局范围内让ESLint整理HTML文件的脚本标签,因此一个文件中的类和函数的声明和调用可以在另一个文件中识别。
这是我的项目结构:
这是foo.js的内容:
sayHello();
Run Code Online (Sandbox Code Playgroud)
和bar.js:
function sayHello() {
console.log('Hello');
}
Run Code Online (Sandbox Code Playgroud)
我已经将它们都链接到了HTML文件中:
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css">
<script src="libraries/bar.js" type="text/javascript"></script>
<script src="foo.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我以为解决此问题的方法是使用eslint-plugin-html软件包,但是尝试配置它没有运气。这些是我在项目本地安装的软件包:
Alexs-MacBook-Pro:Demo alexmcdermott$ npm list --depth=0
demo@1.0.0 /Users/alexmcdermott/GitHub/Demo
??? eslint@5.12.0
??? eslint-config-airbnb-base@13.1.0
??? eslint-plugin-html@5.0.0
??? eslint-plugin-import@2.14.0
Run Code Online (Sandbox Code Playgroud)
我正在使用VSCode编辑器,但在终端中也遇到了相同的问题:
Alexs-MacBook-Pro:Demo alexmcdermott$ npx eslint --ext .js,.html .
/Users/alexmcdermott/GitHub/Demo/foo.js
1:1 error 'sayHello' is not defined no-undef
/Users/alexmcdermott/GitHub/Demo/libraries/bar.js
1:10 error 'sayHello' is defined but never used no-unused-vars
2:3 warning Unexpected console statement no-console
? 3 problems (2 …Run Code Online (Sandbox Code Playgroud)