【问题标题】:Atom ESLint ignore server side language codeAtom ESLint 忽略服务器端语言代码
【发布时间】:2016-12-26 00:27:58
【问题描述】:

我在 Mac 上使用带有 ESLint 的 Atom 编辑器。我需要对具有脚本标签的 html 文件进行 lint,因此我安装了 eslint-plugin-html 和 linter-eslint。但是,我的一些 html 文件中包含 django 代码,并且 ESLint 报告错误。 解析错误。意外的令牌 %。请告知 ESLint 如何忽略此类服务器端代码。这是我的 html 文件的样子

// some html here
<script>
    var foo = {
        {% for item in items %}
            {% if item == "foo" %}
            'foo': 'foo'
            // etc

【问题讨论】:

    标签: atom-editor eslint


    【解决方案1】:

    一些选项:

    A.禁用特定 lines, sections of code, or an entire file 的 linting

    B.禁用 specific file extensions 的 linting

    C.避免在 &lt;script&gt; 标签中使用 django 语法。

    一种方法是将数据放入 javascript 变量中,然后在 javascript 中对其进行操作。

    views.py

    def myview(request):
        some_django_data = json.dumps(geodata)
        ...
    

    template.html

    <script>
      var foo = JSON.parse('{{ some_django_data|safe }}')
    </script>
    <script scr="/path/to/myscript.js"></script>
    

    myscript.js

    foo.forEach(myFunc);
    

    【讨论】:

      猜你喜欢
      • 2018-07-31
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 2015-09-23
      • 2018-09-19
      • 2015-11-14
      相关资源
      最近更新 更多