sudowork / eslint-plugin-ember

An ESlint plugin that provides set of rules for Ember Applications based on commonly known good practices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-ember

NPM version NPM downloads Build Status

An ESlint plugin that provides set of rules for Ember Applications based on commonly known good practices.

❗️ Requirements

  • ESLint is required to use this plugin.
  • Rules provided by this plugin should be runnable under latest stable, v4 LTS and v6 LTS Node.js versions.

🚀 Usage

1. Install plugin

  npm install --save-dev eslint-plugin-ember

2. Modify your .eslintrc.js:

Use with predefined settings:

// .eslintrc.js
module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:ember/recommended'
  ],
  rules: {
    // override rules' settings here
  }
}

Possible configurations:

Use plain plugin:

If you don't want to use predefined settings, you can use it as a plain plugin and choose which rules you'd like to use by yourself like this:

module.exports = {
  extends: [
    'eslint:recommended'
  ],
  plugins: [
    'ember'
  ],
  rules: {
    // add rules' settings here, eg.:
    'ember/local-modules': 2
  }
}

All rules from this plugin have to be prefixed with ember/

🍟 Rules

Rules are grouped by category to help you understand their purpose.

All rules below with a check mark are enabled by default while using plugin:ember/base or plugin:ember/recommended configs.

The --fix option on the command line automatically fixes problems reported by rules which have a wrench 🔧 below.

Controllers

Rule ID Description
alias-model-in-controller Enforces aliasing model in controller

Components

Rule ID Description
avoid-leaking-state-in-components Avoids state leakage
closure-actions Enforces usage of closure actions
no-attrs-snapshot Disallow use of attrs snapshot in didReceiveAttrs and didUpdateAttrs
no-on-calls-in-components Prevents usage of on calls in components

General

Rule ID Description
jquery-ember-run Prevents usage of jQuery without Ember Run Loop
local-modules Enforces usage of local modules
named-functions-in-promises Enforces usage of named functions in promises
new-module-imports Use "New Module Imports" from Ember RFC #176
no-attrs-in-components Disallow usage of this.attrs in components
no-duplicate-dependent-keys Disallow repeating dependent keys
no-function-prototype-extensions Prevents usage of Ember's function prototype extensions
no-global-jquery Prevents usage of global jQuery object
no-observers Prevents usage of observers
🔧 no-old-shims Prevents usage of old shims for modules
no-side-effects Warns about unexpected side effects in computed properties
require-super-in-init Enforces super calls in init hooks
use-brace-expansion Enforces usage of brace expansion
🔧 use-ember-get-and-set Enforces usage of Ember.get and Ember.set

Routing

Rule ID Description
no-capital-letters-in-routes Raise an error when there is a route with uppercased letters in router.js
routes-segments-snake-case Enforces usage of snake_cased dynamic segments in routes

Ember Data

Rule ID Description
no-empty-attrs Prevents usage of empty attributes in ember data models

Components & tests

Rule ID Description
no-jquery Disallow any usage of jQuery

Organizing

Rule ID Description
order-in-components Enforces proper order of properties in components
order-in-controllers Enforces proper order of properties in controllers
order-in-models Enforces proper order of properties in models
order-in-routes Enforces proper order of properties in routes

For the simplified list of rules, go here.

🍻 Contribution guide

In order to add a new rule, you should:

  • Create issue on GH with description of proposed rule
  • Generate a new rule using the official yeoman generator
  • Run yarn start
  • Write test scenarios & implement logic
  • Describe the rule in the generated docs file
  • Make sure all tests are passing
  • Run yarn run update in order to update readme and recommended configuration
  • Create PR and link created issue in description

Please be aware that we're using yarn in this repository, so if you plan to add some dependencies - make sure you commit yarn.lock file too.

If you have any suggestions, ideas or problems feel free to add new issue, but first please make sure your question does not repeat previous ones.

⭐️ Contributors

🙌 Credits

🔓 License

See the LICENSE file for license rights and limitations (MIT).

About

An ESlint plugin that provides set of rules for Ember Applications based on commonly known good practices.

License:MIT License


Languages

Language:JavaScript 100.0%