简体   繁体   中英

JSHint and skipping lines with custom non-JS templating code

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?

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.

Eg

   // %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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM