最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use ESLint to scan javascript included via the src attribute in a script tag? - Stack Overflow

programmeradmin1浏览0评论

I have three files in my project.

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <script src="./a.js"></script>
        <script src="./b.js"></script>
    </body>
</html>

a.js

function test() {
    console.log("test");
}

b.js

test();
test2();

I would like to run ESLint to look for errors. If I run npx eslint .\**\index.html I don't get any errors because it doesn't scan the code included by the src tag. If I run npx eslint .\**\* I get the following errors even though the test function is actually defined and used.

C:\Git\work\New folder\a.js
  1:10  error  'test' is defined but never used  no-unused-vars

C:\Git\work\New folder\b.js
  1:1  error  'test' is not defined   no-undef
  2:1  error  'test2' is not defined  no-undef

✖ 3 problems (3 errors, 0 warnings)

I have eslint-plugin-html installed and included in my eslint.config.mjs file. How can I configure it to scan the code from the src tags. Ideally I would run npx eslint .\**\index.html and get an error report that tells me test2 is not defined.

This is a test project for a much larger legacy project so rewriting the code to use modern imports or modules is not an option.

发布评论

评论列表(0)

  1. 暂无评论