Suppressing Specific JSUnresolvedVariable Warnings

How can I cleanly suppress the warnings on unresolved variable for Node environment variables?  I don't want to have to keep putting this all over my code, that's just code smell and a terrible way to go about that IMO:

// noinspection JSUnresolvedVariable 

So how can I tell Webstorm to ignore all Node environment variables?

 

Here's some of my code using them:

 

import app from './app';

require('dotenv').config();
const { env } = process;
// noinspection JSUnresolvedVariable
app.listen(env.PROD_SERVICE_PORT, err => {
// noinspection JSUnresolvedVariable
console.log(`Koa is listening on port ${env.PROD_SERVICE_PORT}`);
if (err) {
console.log('server startup error');
console.log(err);
}
});

root/.env


MYSQL_HOST = 'us-cdbr-iron-east'
MYSQL_PORT = 3306
MYSQL_USERNAME = 'b305bc'
MYSQL_PASSWORD = '5e58a4'
MYSQL_DATABASE = 'heroku_6f'

PROD_SERVICE_PORT = 8000

0
1 comment

You can try defining your env object using JSDoc in your file, like:

/**
* A variable in the global namespace called 'env'.
* @typedef {Object} env
* @property {number} PROD_SERVICE_PORT
* @property {string} MYSQL_HOST
* @property {number} MYSQL_PORT
*/


See https://youtrack.jetbrains.com/issue/WEB-17419#comment=27-1058451,
http://devnet.jetbrains.com/message/5504337#5504337 for other
possible workarounds.
1

Please sign in to leave a comment.