Giter Club home page Giter Club logo

eslint-plugin-ember's Introduction

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

  yarn add --dev eslint-plugin-ember

Or

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

2. Modify your .eslintrc.js:

Use with predefined settings:

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

Possible configurations:

  • plugin:ember/base - contains no rules settings, but the basic eslint configuration suitable for any ember project. You can use it to configure rules as you wish.
  • plugin:ember/recommended - extends base configuration with recommended rules' settings

Use plain plugin:

If you don't want to use predefined settings, you can use it as a plain plugin:

module.exports = {
  plugins: [
    'ember'
  ],
  extends: [
    'eslint:recommended'
  ],
  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/recommended config.

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

Best Practices

Rule ID Description
alias-model-in-controller Enforces aliasing model in controller
avoid-using-needs-in-controllers Avoids using needs in controllers
closure-actions Enforces usage of closure actions
named-functions-in-promises Enforces usage of named functions in promises
new-module-imports Use "New Module Imports" from Ember RFC #176
no-function-prototype-extensions Prevents usage of Ember's function prototype extensions
no-get Require ES5 getters instead of Ember's get / getProperties functions
no-global-jquery Prevents usage of global jQuery object
no-jquery Disallow any usage of jQuery
no-new-mixins Prevents creation of new mixins
no-observers Prevents usage of observers
✅🔧 no-old-shims Prevents usage of old shims for modules
no-on-calls-in-components Prevents usage of on to call lifecycle hooks in components
no-restricted-resolver-tests Prevents the use of patterns that use the restricted resolver in tests.
no-unnecessary-index-route Disallow unnecessary index route definition
🔧 no-unnecessary-route-path-option Disallow unnecessary route path option
🔧 no-unnecessary-service-injection-argument Disallow unnecessary argument when injecting service
no-volatile-computed-properties Disallows volatile computed properties
🔧 require-computed-macros Requires using computed property macros when possible
route-path-style Enforces usage of kebab-case (instead of snake_case or camelCase) in route paths
🔧 use-ember-get-and-set Enforces usage of Ember.get and Ember.set

Possible Errors

Rule ID Description
jquery-ember-run Prevents usage of jQuery without Ember Run Loop
no-arrow-function-computed-properties Disallows arrow functions in computed properties
no-attrs-in-components Disallow usage of this.attrs in components
no-attrs-snapshot Disallow use of attrs snapshot in didReceiveAttrs and didUpdateAttrs
no-capital-letters-in-routes Raise an error when there is a route with uppercased letters in router.js
no-deeply-nested-dependent-keys-with-each Disallows usage of deeply-nested computed property dependent keys with @each.
no-duplicate-dependent-keys Disallow repeating dependent keys
🔧 no-ember-super-in-es-classes Prevents use of this._super in ES class methods
no-ember-testing-in-module-scope Prevents use of Ember.testing in module scope
no-invalid-debug-function-arguments Catch usages of Ember's assert() / warn() / deprecate() functions that have the arguments passed in the wrong order.
no-side-effects Warns about unexpected side effects in computed properties
🔧 require-computed-property-dependencies Requires dependencies to be declared statically in computed properties
require-return-from-computed Warns about missing return statements in computed properties
require-super-in-init Enforces super calls in init hooks
routes-segments-snake-case Enforces usage of snake_cased dynamic segments in routes

Ember Object

Rule ID Description
avoid-leaking-state-in-ember-objects Avoids state leakage
classic-decorator-hooks Ensure correct hooks are used for both classic and non-classic classes
classic-decorator-no-classic-methods Prevent usage of classic APIs such as get/set in classes that aren't explicitly decorated with @classic
computed-property-getters Enforce the consistent use of getters in computed properties
no-proxies Disallows using array or object proxies

Ember Data

Rule ID Description
no-empty-attrs Prevents usage of empty attributes in ember data models
🔧 use-ember-data-rfc-395-imports Use "Ember Data Packages" from Ember RFC #395

Testing

Rule ID Description
no-test-and-then Disallow use of andThen test wait helper.
no-test-import-export Disallow importing of "-test.js" in a test file and exporting from a test file.

Stylistic Issues

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
use-brace-expansion Enforces usage of brace expansion

Deprecated

⚠️ We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.

Rule ID Replaced by
avoid-leaking-state-in-components avoid-leaking-state-in-ember-objects
local-modules new-module-imports
no-get-properties no-get

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).

eslint-plugin-ember's People

Contributors

rwjblue avatar turbo87 avatar bmish avatar dependabot[bot] avatar rafleszczynski avatar michalsnik avatar dcyriller avatar dependabot-preview[bot] avatar jbandura avatar scalvert avatar clcuevas avatar serabe avatar t-sauer avatar przemorevolve avatar step2yeung avatar caseywatts avatar sudowork avatar robbiethewagner avatar ro0gr avatar tmquinn avatar dependabot-support avatar rmachielse avatar amk221 avatar jrjohnson avatar nlfurniss avatar scottkidder avatar samselikoff avatar locks avatar cibernox avatar kerrick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.