JSHint and skipping lines with custom non-JS templating code

為{幸葍}努か 提交于 2020-01-06 15:32:15

问题


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

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 '/'.

And many more.

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


回答1:


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

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.

E.g.

   // %import and other custom commands here

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/



来源:https://stackoverflow.com/questions/21221960/jshint-and-skipping-lines-with-custom-non-js-templating-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!