如何在具有模板的文件中运行JSLint / JSHint? [英] How to run JSLint / JSHint in a file with templates?

查看:155
本文介绍了如何在具有模板的文件中运行JSLint / JSHint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试介绍一些工具来提高代码质量。在之前公司使用的一个明显的解决方案是在检查代码之前运行 jslint

I'm trying to introduce some tools at work to improve code quality. An obvious solution that I'd used at a previous company was to run jslint before checking in code.

问题是我们正在使用Django来做我们的模板(尽管如此,我认为我们将会遇到与其他模板语言类似的问题)。

The problem is that we are using Django to do our templating (though, I assume we would have a similar problem with other templating languages).

如下所示,并且在忽略模板标签时正确地使用JSLint / JSHint?

How is it possible to take code like the below, and have it JSLint/JSHint properly while ignoring the template tags?

var a = { "test" : "test"};
{% comment %}
{% endcomment %}
{{ my_variable }}
window.x = "y";

我看过的这个问题,这个问题看起来像处理某些情况,但是没有解决这个问题内容变量,如 {{my_variable}} 以上。

有没有办法忽略某些行使用JSHint / JSLint还是以其他方式让linting正确执行?

Is there any way to ignore certain lines using JSHint/JSLint, or otherwise get the linting to execute correctly?

推荐答案

很像使用这些工具,外面的内容是普遍的。可能最容易用虚拟值运行模板,以及JSHint生成的文件。

Much like linting coffeescript with these tools, you're trying to lint content outside it's pervue. Probably easiest to run the template with dummy values, and JSHint that resulting file.

可能与如何在其中使用Django模板标记在文件上运行JSHint?

这篇关于如何在具有模板的文件中运行JSLint / JSHint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆