Component Webservice Editor - JSHint Considerations
Created pdexter 2024-04-05
As of Component Webservice Editor v202404A, JSHint is being used to validate script when invoked by a Test Me button, and on preSave.
The following guidelines may help in dealing with possible "complaints" made by JSHint when editing a Component Webservice.
A Reassurance (Don't Panic)
The JSHint script validation only alerts the author/editor to probable syntax errors within the script while they are editing.
A previously working Component Webservice script will continue to work at runtime, even if when the script is opened, JSHint alerts to a hundred issues.
Declaring Globals
A large and indefinite number of global objects are used within component webservice scripts, so many that it is not practical to try to predeclare all of them in the JSHint syntax checking.
Globals can be declared near the top of your script as per the following example:
/* global q, DataService, mySuperObject */
The global objects "logger" and "userId" have already been predeclared in the coding of the Editor, so there is no need to declare those.
Underscore thousands delimiter
It is possible within javascript to use an underscore as a thousands delimiter for a numeric variable, eg
var pageSize = 10_000
While this is valid, JSHint currently (2024-04-05) does not recognise this form of variable declaration, so it will be necessary to remove the underscore (until a time when JSHint is upgraded to do so).
At present, a workaround has been made to sidestep instances of the code pageSize : 10_000
, as it was used widely and was the only example of such usage found in all webservice documents on gww-dev.formbird.com (2024-04-05). However, it is not feasible to sidestep all numeric declarations like this.
Miscellaneous
Undeclared variables
To date, it has been possible to use variable names, without first declaring them.
Eg
for (action of actionArray) { ... }
// "action" not declared
This will be alerted by JSHint and should be corrected
Eg, correct version:
for (var action in actionArray) { ... }