Skip to content

Instantly share code, notes, and snippets.

@sarupbanskota
Last active June 9, 2020 21:28
Show Gist options
  • Save sarupbanskota/2394fc439e538239a073c39514a5aa55 to your computer and use it in GitHub Desktop.
Save sarupbanskota/2394fc439e538239a073c39514a5aa55 to your computer and use it in GitHub Desktop.
Ember + ESLint + Prettier + Ember Suave
  • new ember app & yarn install
  • ember install ember-cli-eslint@4
// ember-cli-build.js
let app = new EmberApp(defaults, {
  eslint: {
    testGenerator: 'qunit',
    group: true,
    rulesDir: 'eslint-rules',
    extensions: ['js'],
  }
});
// eslintrc.js
module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  extends: ['prettier'],
  env: {
    browser: true
  },
  plugins: [
    "prettier"
  ],
  rules: {
    "prettier/prettier": "error"
  }
};
  • yarn add lint-staged husky --dev
// package.json
{
  "scripts": {
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,json,css}": [
      "prettier --write",
      "git add"
    ]
  }
}
// .eslintrc.js
module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  extends: [
    'prettier'
  ],
  env: {
    browser: true
  },
  plugins: [
    "prettier"
  ],
  rules: {
    // Formatting
    'prettier/prettier': 'error',

    // ES6
    'arrow-parens': ['error', 'always'],
    'generator-star-spacing': ['error', {
      'before': false,
      'after': true
    }],
    'no-var': 'error',
    'object-shorthand': ['error', 'always'],
    'prefer-spread': 'error',
    'prefer-template': 'error',

    // Overrides for Ember
    'new-cap': ['error', {
      'capIsNewExceptions': ['A']
    }],

    'ember-suave/no-const-outside-module-scope': 'error',
    'ember-suave/no-direct-property-access': 'error',
    'ember-suave/prefer-destructuring': 'error',
    'ember-suave/require-access-in-comments': 'error',
    'ember-suave/require-const-for-ember-properties': 'error'
  }
};
@Matt-Jensen
Copy link

Matt-Jensen commented May 28, 2018

Looks like Ember Suave needs to be added as an Eslint extension in .eslintrc.js

module.exports = {
  extends: [
    // ..
    'plugin:ember-suave/recommended'
  ]
}

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