Atom ESLint忽略服务器端语言代码

时间:2016-08-18 23:22:36

标签: atom-editor eslint

我在Mac上使用Atom Editor和ESLint。我需要lint包含脚本标签的html文件,所以我安装了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

1 个答案:

答案 0 :(得分:1)

一些选项:

一个。禁用特定lines, sections of code, or an entire file

的linting

B中。禁用specific file extensions

的linting

℃。避免在<script>标记内使用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);