简体   繁体   English

ESLint不在PyCharm中针对HTML文件运行

[英]ESLint doesn't run for HTML files in PyCharm

I am working on a Django+JavaScript project using ESLint as an integrated linter in PyCharm. 我正在使用ESLint作为PyCharm中的集成linter进行Django + JavaScript项目。 It works well for *.js files but doesn't analyze any JavaScript in *.html files at all. 它适用于*.js文件,但根本不分析*.html文件中的任何JavaScript。 How do I enable ESLint for HTML files, too? 我如何也为HTML文件启用ESLint?

Here is what I have tried 这是我尝试过的

I added the eslint-plugin-html and followed its setup instructions here: https://www.npmjs.com/package/eslint-plugin-html 我在eslint-plugin-html添加了eslint-plugin-html并按照其设置说明进行操作: https : eslint-plugin-html

This includes adding "plugins": [ "html" ] into .eslintrc.js and adding --ext .html,.js into the "Extra ESLint options" input box in "Languages & Frameworks > JavaScript > Code Quality Tools > ESLint" at PyCharm Preferences. 这包括在.eslintrc.js添加"plugins": [ "html" ]并将--ext .html,.js添加到“语言和框架> JavaScript>代码质量工具> ESLint”中的“额外ESLint选项”输入框中在PyCharm偏好设置中。

Here is what my .eslintrc.js file looks like (rules are skipped). 这是我的.eslintrc.js文件的样子(规则已跳过)。 I commented out the ESLint vue plugin so far as it is said to have incompatibilities with eslint-plugin-html, which didn't help either. 到目前为止,我已对ESLint vue插件进行了评论,因为据说该插件与eslint-plugin-html不兼容,但两者也无济于事。

module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        //"plugin:vue/essential",
        "google"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018
    },
    "plugins": [
        "html",
        //"vue"
    ],
    "rules": {
        ...
    }
};

Here is the screenshot of my ESLint settings in PyCharm preferences: ESLint settings in PyCharm preferences 这是我在PyCharm首选项中的ESLint设置的屏幕截图:在PyCharm首选项中的ESLint设置

An important matter is that HTML files in my case were used as Django templates (which is the standard approach for the scenario I'm describing ie for Django projects). 重要的是,在我的案例中,HTML文件被用作Django模板(这是我描述的场景(即Django项目)的标准方法)。 As explained by lena in the comment above, linting Django templates is not currently supported. 正如lena在上面的评论中所解释的那样,当前不支持linting Django模板。 I've got the same confirmation from an official request to JetBrains (the company that owns PyCharm). 我对JetBrains(拥有PyCharm的公司)的正式要求也得到了同样的确认。

So the answer is - currently there is no way to enable ESLint for Django templates in PyCharm . 因此,答案是- 当前无法在PyCharm中为Django模板启用ESLint The workaround is to move the JS code to the other supported types of files to have the code linted (for example, .js or .vue files). 解决方法是将JS代码移动到其他受支持的文件类型,以使代码不易处理(例如.js或.vue文件)。

JetBrains has opened a new issue in their tracking system for adding the lacking support, so please vote there if this feature matters to you: ESLint: support linting JavaScript code in Django templates . JetBrains在其跟踪系统中打开了一个新问题,以添加缺少的支持,因此,如果此功能对您重要,请在此处投票: ESLint:在Django模板中支持lint JavaScript代码 Also, use this link to get most recent updates on whether this feature gets supported . 另外, 使用此链接可获得有关是否支持此功能的最新更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM