1
votes

I'm using Atom Editor with ESLint on Mac. I need to lint html files that have script tags so I installed eslint-plugin-html and linter-eslint. However, some of my html files have django code in them and ESLint reports an error. Parsing error. Unexpected token %. Please advise how can ESLint ignore such server side code. Here is what my html file looks like

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

1 Answers

1
votes

Some options:

A. Disable linting for specific lines, sections of code, or an entire file

B. Disable linting for specific file extensions

C. Avoid having django syntax within <script> tags.

One way to do this is get the data into a javascript variable then manipulate it in 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);