Atom ESLint 忽略服务器端语言代码
Atom ESLint ignore server side language code
我在 Mac 上使用带有 ESLint 的 Atom 编辑器。我需要检查具有脚本标签的 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
部分选项:
一个。为特定 lines, sections of code, or an entire file
禁用 linting
禁用 linting
C。避免在 <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);
我在 Mac 上使用带有 ESLint 的 Atom 编辑器。我需要检查具有脚本标签的 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
部分选项:
一个。为特定 lines, sections of code, or an entire file
禁用 linting 禁用 lintingC。避免在 <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);