Last modified: 2014-07-21 10:30:32 UTC
For the three skip files my IDE gives "Cannot return from outside a function or method" It is possible to make the skip files valid javascript files to avoid noise in my or any IDE or is something wrong with my IDE and the js validation (eclipse)?
Krinkle has previously said that this is indeed valid (I never tried to find out, personally). See https://gerrit.wikimedia.org/r/#/c/139308/1//COMMIT_MSG and some other comments on that changeset.
Also note that this is the result of various different attempts and compromises. The dozens of other approaches all involved bloating the startup module output, repeating the same boilerplate in lots of files, or ending up with error pronse constructions, or files that aren't valid on their own. These files are valid javascript code (as verified by jshint). Returning from outside a function is indeed a syntax error if it were executed like that, but it's executed as a function, not as a standalone program. Some of the alternatives I considered: --- func function skip() { return true; } * Downside: Trips jshint's quality rule against having unused functions. We'd have to put /*jshint unused:false */ atop each file. -- block skip: { return true; } * This makes use of javascript supporting (goto/continue-like) label statements and unattached block statements to wrap code. * If executed standalone would be an illegal return statement. -- expression true; * This makes use of javascript supporting bare expression statements. * Downside: Trips jshint's quality rule against having code that does not assign or invoke anything. We'd have to put /*jshint expr:true */ atop each file. -- return return true; * If executed standalone would be an illegal return statement. -- For 'func' and 'block': * Extra boilerplate to repeat in each file. * Either bloats the startup module and requires the client to perform extra actions to invoke it (due to name collision otherwise), or, it could be stripped by the server and reduced to 'return true;' but in that case it needs to be very exact. And anything outside of it would be ignored or result in an error. I think if all files contain the same character-by-character prefix/suffix only to be stripped, and result in exceptions when not exactly the same, might as well not have it. The cleanest of these are 'block' and 'return'. They require no jshint overrides, is valid javascript passing jshint. Of those 'return' seemed the best.
eclipse validates the .js files with a global context and than the return makes a problem. I should try to install jshint as eclipse plug-in and disable the build-in javascript validation.