Jankapunkt
Jankapunkt

Reputation: 8423

Meteor eslint config for package development with globale namespace export

When developing Meteor packages, I can choose to export a package content using

api.export('VariableName');
api.addFiles('main.js');

The corresponding variable in the package has to be declared "globally" to match this definition (in main.js):

VariableName = { /* something... */ }

However, this causes eslint to throw no-undef on each line this variable is used:

1:1   error  'VariableName' is not defined  no-undef
....
141:1   error  'VariableName' is not defined  no-undef

Switching no-undef to off is no option, since it is one of the greatest tools of eslint to uncover unused variables.

How can I suppress this error without switching the rule to off and without putting an exception on each line before the variable?


Edit:

By addint the global rule /* global VariableName */ I will receive a read-only error:

Read-only global 'VariableName' should not be modified  no-global-assign

I forgot to mention, that the package imports an external npm package, modifies some of it's functionality to be compatible with Meteor's environment and exports it then again.

So the code is actually:

VariableName = require('packageName');

Upvotes: 1

Views: 116

Answers (1)

Sean
Sean

Reputation: 2729

You can specify that some variables are globals which will disable this error specifically for these variables but not any others.

Link to documentation

An example would be placing the following code at the top of the file you are having this error in:

/* global VariableName:true */

Upvotes: 1

Related Questions