问题
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:
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?
来源:https://stackoverflow.com/questions/10271278/how-to-run-jslint-jshint-in-a-file-with-templates