Skip to content

Latest commit

 

History

History
69 lines (44 loc) · 2.96 KB

no-classic-classes.md

File metadata and controls

69 lines (44 loc) · 2.96 KB

ember/no-classic-classes

💼 This rule is enabled in the ✅ recommended config.

Disallow "classic" classes in favor of native JS classes.

Ember now allows you to use native JS classes to extend the built-in classes provided by Ember. This pattern is preferred in favor of using the "classic" style of classes that Ember has provided since before JS classes were available to use.

Rule Details

This rule aims to ensure that you do not use a "classic" Ember class where a native class could be used instead. The one instance where .extend should still be used is for including a Mixin into your class, which does not have a native JS class alternative available.

Examples

Examples of incorrect code for this rule:

// Extending an Ember class using the "classic" class pattern is not OK
import Component from '@ember/component';

export default Component.extend({});
// With option: additionalClassImports = ['my-custom-addon']
import CustomClass from 'my-custom-addon';

export default CustomClass.extend({});

Examples of correct code for this rule:

// Extending using a native JS class is OK
import Component from '@ember/component';

export default class MyComponent extends Component {}
// Including a Mixin is OK
import Component from '@ember/component';
import Evented from '@ember/object/evented';

export default class MyComponent extends Component.extend(Evented) {}

Configuration

Name Description Type
additionalClassImports Allows you to specify additional imports that should be flagged to disallow calling extend on. This allows you to handle the case where your app or addon is importing from a module that performs the extend. String[]

When Not To Use It

  • If you are not ready to transition completely to native JS classes, you should not enable this rule

Further Reading