使用自定义非JS模板代码的JSHint和跳过行 [英] JSHint and skipping lines with custom non-JS templating code

查看:146
本文介绍了使用自定义非JS模板代码的JSHint和跳过行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将SublimeText3中的SublimeLinter3与SublimeLinter-jshint linter一起使用.我有由自定义CGI处理的服务器端JavaScript.它使用格式如下的import语句导入其他服务器端JS文件(:ssjs只是告诉解释器将其作为服务器端JavaScript进行处理):

I am using SublimeLinter3 in SublimeText3 with the SublimeLinter-jshint linter. I have server side JavaScript that is processed by a custom CGI. It imports other server side JS files with a import statement that is formatted as follows (the :ssjs just tells the interpreter to process the import as server side JavaScript):

%import /foo/bar.js:ssjs

不用说,这会导致JSHint出现各种问题,例如:

Needless to say, this is causing all sorts of problems with JSHint, such as:

Expected an identifier and instead saw '%'
Expected an assignment or function call and instead saw an expression.
Expected '{' and instead saw '/'.

还有更多

如何在衬棉时配置JSHint和/或SublimeLinter使其不处理那些行?

How can I configure JSHint and/or SublimeLinter to not process those lines when linting?

推荐答案

严格来说,无论您使用的是哪种自定义CGI都不符合JavaScript语法.

To be strict, whatever custom CGI you are using does not conform JavaScript syntax.

我建议您将自定义动态处理变成JavaScript注释,以免影响正常的JavaScript解析.这比编写自定义JavaScript解析器来满足自定义语法要容易得多.

What I suggest is that you make your custom dynamic processing into JavaScript comments, so that it doesn't affect the normal JavaScript parsing. This is much easier than writing your custom JavaScript parser to cater your custom syntax.

例如

   // %import and other custom commands here

最好的方法是,您根本不会将任何非JavaScript都放置到JS文件中.如果您需要导入等,则可以使用一些更通用的JavaScript解决方案.

The best approach is that you would not put any non-JavaScript to JS files at all. If you need importing and such there are some more generic JavaScript solutions for them.

http://browserify.org/

http://requirejs.org/

这篇关于使用自定义非JS模板代码的JSHint和跳过行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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