[][src]Struct rslint_core::groups::errors::GetterReturn

pub struct GetterReturn {
    pub allow_implicit: bool,
}

Disallow getter properties which do not always return a value.

Getters are special properties introduced in ES5 which call a function when a property is accessed. The value returned will be the value returned for the property access:

let obj = {
    // Using object literal syntax
    get foo() {
        return 5;
    }
}

// Using the defineProperty function
Object.defineProperty(obj, "foo", {
    get: function() {
        return 5;
    }
})

Getters are expected to return a value, it is a bad practice to use getters to run some function without a return. This rule makes sure that does not happen and enforces a getter always returns a value.

Incorrect code examples

// The getter does not always return a value, it would not return anything
// if bar is falsey
let obj = {
    get foo() {
        if (bar) {
            return foo;
        }
    }
}

Correct code examples

// The getter always returns a value
let obj = {
    get foo() {
        if (bar) {
            return foo;
        } else {
            return bar;
        }
    }
}

Fields

allow_implicit: bool

Whether to allow implicitly returning undefined with return;. true by default.

Implementations

impl GetterReturn[src]

pub fn new() -> Self[src]

Trait Implementations

impl Clone for GetterReturn[src]

impl CstRule for GetterReturn[src]

impl Debug for GetterReturn[src]

impl Default for GetterReturn[src]

impl<'de> Deserialize<'de> for GetterReturn[src]

impl Rule for GetterReturn[src]

impl Serialize for GetterReturn[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> Erasable for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.