Skip to content

Latest commit

 

History

History
102 lines (83 loc) · 1.69 KB

computed-property-getters.md

File metadata and controls

102 lines (83 loc) · 1.69 KB

Rule name: computed-property-getters

Enforce the consistent use of getters in computed properties

Computed properties may be created with or without a get method. This rule ensures that the choice is consistent.

Options

This rule takes a single string option

String option:

  • "always-with-setter" (default) getters are required when computed property has a setter
  • "always" getters are required in computed properties
  • "never" getters are never allowed in computed properties

always-with-setter

/// BAD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', {
        get() {
            //...
        }
    })
});

// GOOD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', function() {
        //...
    })
});

// GOOD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', {
        set() {
            //...
        },
        get() {
            //...
        }
    })
});

always

/// GOOD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', {
        get() {
            //...
        }
    })
});

// BAD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', function() {
        //...
    })
});

never

/// GOOD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', function() {
        //...
    })
});

// BAD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', {
        get() {
            //...
        }
    })
});

// BAD
Ember.Object.extend({
    fullName: computed('firstName', 'lastName', {
        get() {
            //...
        },
        set() {
            //...
        }
    })
});