JSHint and skipping lines with custom non-JS templ

2019-08-25 01:34发布

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条回答
做自己的国王
2楼-- · 2019-08-25 01:51

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/

查看更多
登录 后发表回答