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

pub struct GetterReturn {
    pub allow_implicit: bool,
}
Expand description

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Check an individual node in the syntax tree. You can use the match_ast macro to make matching a node to an ast node easier. The reason this uses nodes and not a visitor is because nodes are more flexible, converting them to an AST node has zero cost and you can easily traverse surrounding nodes. Defaults to doing nothing. Read more

Check an individual token in the syntax tree. Defaults to doing nothing. Read more

Check the root of the tree one time. This method is guaranteed to only be called once. The root’s kind will be either SCRIPT or MODULE. Defaults to doing nothing. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

A unique, kebab-case name for the rule.

The name of the group this rule belongs to.

Optional docs for the rule, an empty string by default

A list of tags present on this rule. Empty by default.

Whether this rule is recommended, this is a simple helper around Self::tags.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Unerase this erased pointer. Read more

Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more

Turn this erasable pointer into an erased pointer. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.