How to run JSLint / JSHint in a file with template

2019-07-09 07:19发布

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.

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).

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";

I've seen this question specifically regarding JSHint, which looks like it could handle some cases, but it doesn't address inlining variables, like {{ my_variable }} above.

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

1条回答
Animai°情兽
2楼-- · 2019-07-09 07:28

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.

Probably duplicate of How to run JSHint on files with Django template markup in them?

查看更多
登录 后发表回答