[go: up one dir, main page]

Skip to content

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

License

Notifications You must be signed in to change notification settings

cdtinney/eslint-plugin-ember

Β 
Β 

Repository files navigation

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

πŸš€ Usage

1. Install plugin

  yarn add --dev eslint-plugin-ember

Or

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

2. Modify your .eslintrc.js:

// .eslintrc.js
module.exports = {
  plugins: [
    'ember'
  ],
  extends: [
    'eslint:recommended',
    'plugin:ember/recommended' // or other configuration
  ],
  rules: {
    // override rule settings here
    'ember/no-jquery': 'error'
  }
}

🧰 Configurations

Name Description
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.
βœ… recommended extends the base configuration by enabling the recommended rules.
πŸš— octane extends the recommended configuration by enabling octane rules. This ruleset is currently considered unstable and experimental ⚠️ as rules may be added and removed until the final ruleset is settled upon.

🍟 Rules

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

Each rule has emojis denoting what configuration it belongs to and/or a πŸ”§ if the rule is fixable via the --fix command line option.

Best Practices

Rule ID Description
alias-model-in-controller enforce aliasing model in controllers
βœ… avoid-using-needs-in-controllers disallow using needs in controllers
βœ… closure-actions enforce usage of closure actions
named-functions-in-promises enforce usage of named functions in promises
βœ… new-module-imports enforce using "New Module Imports" from Ember RFC #176
βœ… no-function-prototype-extensions disallow usage of Ember's function prototype extensions
πŸš— no-get-with-default disallow usage of the Ember's getWithDefault function
πŸš—πŸ”§ no-get require using ES5 getters instead of Ember's get / getProperties functions
βœ… no-global-jquery disallow usage of global jQuery object
πŸš— no-jquery disallow any usage of jQuery
βœ… no-new-mixins disallow the creation of new mixins
βœ… no-observers disallow usage of observers
βœ…πŸ”§ no-old-shims disallow usage of old shims for modules
βœ… no-on-calls-in-components disallow usage of on to call lifecycle hooks in components
βœ… no-restricted-resolver-tests disallow 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 usage of the route path option
πŸ”§ no-unnecessary-service-injection-argument disallow unnecessary argument when injecting services
βœ… no-volatile-computed-properties disallow volatile computed properties
πŸ”§ require-computed-macros require using computed property macros when possible
route-path-style enforce usage of kebab-case (instead of snake_case or camelCase) in route paths
πŸ”§ use-ember-get-and-set enforce usage of Ember.get and Ember.set

Ember Object

Rule ID Description
βœ… avoid-leaking-state-in-ember-objects disallow state leakage
πŸš— classic-decorator-hooks enforce using correct hooks for both classic and non-classic classes
πŸš— classic-decorator-no-classic-methods disallow 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 disallow using array or object proxies

Possible Errors

Rule ID Description
βœ… jquery-ember-run disallow usage of jQuery without an Ember run loop
βœ… no-arrow-function-computed-properties disallow 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 the didReceiveAttrs and didUpdateAttrs hooks
βœ… no-capital-letters-in-routes disallow routes with uppercased letters in router.js
βœ… no-deeply-nested-dependent-keys-with-each disallow usage of deeply-nested computed property dependent keys with @each
βœ… no-duplicate-dependent-keys disallow repeating computed property dependent keys
βœ…πŸ”§ no-ember-super-in-es-classes disallow use of this._super in ES class methods
βœ… no-ember-testing-in-module-scope disallow use of Ember.testing in module scope
βœ… no-incorrect-calls-with-inline-anonymous-functions disallow inline anonymous functions as arguments to debounce, once, and scheduleOnce
βœ… no-invalid-debug-function-arguments disallow usages of Ember's assert() / warn() / deprecate() functions that have the arguments passed in the wrong order.
βœ… no-side-effects disallow unexpected side effects in computed properties
πŸ”§ require-computed-property-dependencies require dependencies to be declared statically in computed properties
βœ… require-return-from-computed disallow missing return statements in computed properties
βœ… require-super-in-init require this._super to be called in init hooks
βœ… routes-segments-snake-case enforce usage of snake_cased dynamic segments in routes

Ember Octane

Rule ID Description
πŸš— no-actions-hash disallow the actions hash in components, controllers, and routes
πŸš— no-classic-classes disallow "classic" classes in favor of native JS classes
πŸš— no-classic-components enforce using Glimmer components
πŸš— no-computed-properties-in-native-classes disallow using computed properties in native classes
πŸš— require-tagless-components disallow using the wrapper element of a component

Ember Data

Rule ID Description
no-empty-attrs disallow usage of empty attributes in Ember Data models
πŸ”§ use-ember-data-rfc-395-imports enforce usage of @ember-data/ packages instead ember-data

Testing

Rule ID Description
no-pause-test disallow usage of the pauseTest helper in tests
no-test-and-then disallow usage of the andThen test wait helper
no-test-import-export disallow importing of "-test.js" in a test file and exporting from a test file
no-test-module-for disallow usage of moduleFor, moduleForComponent, etc

Stylistic Issues

Rule ID Description
πŸ”§ order-in-components enforce proper order of properties in components
πŸ”§ order-in-controllers enforce proper order of properties in controllers
πŸ”§ order-in-models enforce proper order of properties in models
πŸ”§ order-in-routes enforce proper order of properties in routes
βœ… use-brace-expansion enforce usage of brace expansion in computed property dependent keys

For the simplified list of rules, go here.

🍻 Contribution guide

In order to add a new rule, you should:

  • Create an issue on GitHub 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

If you have any suggestions, ideas, or problems feel free to create an 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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%