I use IntelliJ to write JS scripts that are executed in an environment where several context variables are set implicitly, e.g. embeddingPage
.
But IntelliJ does not know about the context so it marks these variables as unknown:
Unresolved variable or type embeddingPage
Additionally the script execution requires to return a config
object at the end that the IDE complains about:
'return' outside function definition
Is there a way to make the context known to the IDE without breaking the execution of the script?
CodePudding user response:
You can let the IDE know about your implicitly set variables by adding JSDoc annotations somewhere in your code. The @name tag seems to be the best choice as it is typically used in "virtual comments" for symbols that are not readily visible in the code, such as methods that are generated at runtime.
As for "'return' outside function definition" error, I can only suggest disabling the JavaScript and TypeScript | General | ECMAScript specification is not followed inspection or suppressing it for statement using // noinspection JSAnnotator