Using eslint in a brand new Meteor app - Tons of globals not defined

I just created a brand new Meteor project to setup eslint and see how it works - zero custom configurations or packages. Pretty much just running eslint on a ground zero Meteor app.

I’m using this: https://github.com/airbnb/javascript

npm install --save-dev eslint-config-airbnb eslint-plugin-react eslint

// in .eslintrc
{
  "extends": "airbnb",
  "rules": {
    // disable requiring trailing commas because it might be nice to revert to
    // being JSON at some point, and I don't want to make big changes now.
    "comma-dangle": 0
  }
}

I’m getting a lot of not defined errors for the Meteor classes and objects, such as:

if (Meteor.isClient) {
  // counter starts at 0
  Session.setDefault('counter', 0);

  Template.hello.helpers({
    counter: function () {
      return Session.get('counter');
    }
  });

  Template.hello.events({
    'click button': function () {
      // increment the counter when button is clicked
      Session.set('counter', Session.get('counter') + 1);
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

Any ideas on how to fix this issue? I would prefer to start using a linter to keep my code similar and tidy.

There’s a few ways. You can have a line at the start of each file that defines which globals you’re using e.g.

/* global Meteor, Session */

Or you can configure some default globals in your .eslintrchttp://eslint.org/docs/user-guide/configuring.html#specifying-environments

1 Like

What’s a good list of globals for eslint to use in a typical Meteor app?

Take a look at the Specifying Environments section of the eslint docs. You can specify a “meteor” environment that will take care of a bunch of Meteor global variables for you.

1 Like

Good stuff. I’ll post back with results.

.eslintrc.json

{
“env”: {
“meteor”: true
},
}