Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to setup eslint for Meteor project

How to setup eslint for Meteor project

Usage

  • install dependencies
  • setup .eslintrc to the root of your project
  • run eslint .

Dependencies

Install all needed dependencies

meteor npm install --save-dev eslint@^3.19.0 babel-eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-meteor eslint-plugin-react eslint-plugin-jsx-a11y eslint-import-resolver-meteor

List of dependencies

eslint@^3.19.0 // this is because eslint-config-airbnb doesn't support eslint 4.x.x yet
babel-eslint
eslint-config-airbnb
eslint-plugin-import
eslint-plugin-meteor
eslint-plugin-react
eslint-plugin-jsx-a11y
eslint-import-resolver-meteor

Config for .eslintrc

Save .eslintrc file in the root of your project folder:

{
  parser: 'babel-eslint',
  parserOptions: {
    allowImportExportEverywhere: true
  },
  env: {
    node: true,
    browser: true
  },
  plugins: [
    'meteor'
  ],
  extends: [
    'airbnb',
    'plugin:meteor/recommended'
  ],
  settings: {
    'import/resolver': 'meteor'
  },
  'globals': {
    'Assets': true, // currently not possible to import as an ES6 module
    'Package': true,
    'Cordova': true,
    'Npm': true
  },
  'rules': {
    'react/jsx-filename-extension': 0,
    'import/no-absolute-path': 0,
    'import/extensions': 0,
    'import/no-unresolved': ['error', {
      'ignore': ["^meteor/", "^/"]
    }],

    // disabled so that we're not expecting to find 'meteor' within
    // our dependencies.
    // XXX this *should* be taken care of by eslint-import-resolver-meteor, investigate.
    'import/no-extraneous-dependencies': 0,

    'no-underscore-dangle': [
      'error',
      {
        allow: [
          '_id',
          '_ensureIndex'
        ]
      }
    ],
    'comma-dangle': ['error', 'never'],
    'curly': ['error', 'multi-or-nest', 'consistent'],
    'no-param-reassign': ['error', {
      'props': false
    }],
    'space-before-function-paren': ['error', {
      'anonymous': 'always',
      'named': 'never',
      'asyncArrow': 'always'
    }],
    'object-shorthand': ['error', 'always', {
      'avoidQuotes': false
    }],
    'arrow-body-style': ['error', 'as-needed', {
      'requireReturnForObjectLiteral': true
    }],

    // for Meteor API's that rely on `this` context, e.g. Template.onCreated and publications
    'func-names': 0,
    'prefer-arrow-callback': 0,
    'meteor/no-session': 0
  }
}

Ignore certain files

Create .eslintignore file in the root folder of your project.

package.js  // Package, Cordova and Npm vars are set as global, so no need to ignore this file
package.json  // You might want to keep this though, because config prefers single quotes
node_modules/
bower_components/
.npm/
build/
.meteor/
packages/
.git/

NOTE!

This config contains settings from @meteorjs/eslint-config-meteor module. It's not marked as dependency because it didn't work right. My guess is that yarn/npm/eslint had an issue with that package name format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment