Struct rslint_core::groups::errors::NoSetterReturn [−][src]
pub struct NoSetterReturn {}
Expand description
Disallow setters to return values.
Setters cannot return values. To be more precise, a setter that returns a value is not treated as an error, but we cannot use the returned value at all. Thus, if you write a setter that will return something, it is most likely either completely unnecessary or a possible error.
Note that return
without a value is allowed because it is considered a control flow statement.
This rule checks setters in:
- Object literals
- Class declarations and class expressions
- Property descriptors in
Object.create
,Object.defineProperty
,Object.defineProperties
, andReflect.defineProperty
Incorrect code examples
let foo = {
set a(value) {
this.val = value;
// The setter always returns a value
return value;
}
};
class Foo {
set a(value) {
this.val = value;
// The setter always returns a value
return this.val;
}
}
const Bar = class {
static set a(value) {
if (value < 0) {
this.val = 0;
// The setter returns `0` if the value is negative
return 0;
}
this.val = value;
}
};
Object.defineProperty(foo, "bar", {
set(value) {
if (value < 0) {
// The setter returns `false` if the value is negative
return false;
}
this.val = value;
}
});
Correct code examples
let foo = {
set a(value) {
this.val = value;
}
};
class Foo {
set a(value) {
this.val = value;
}
}
const Bar = class {
static set a(value) {
if (value < 0) {
this.val = 0;
// Returning without a value is allowed
return;
}
this.val = value;
}
};
Object.defineProperty(foo, "bar", {
set(value) {
if (value < 0) {
// Throwing an error is also allowed
throw new Error("Negative value is not allowed.");
}
this.val = value;
}
});
Implementations
Trait Implementations
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
Returns the “default value” for a type. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
A list of tags present on this rule. Empty by default.
Whether this rule is recommended, this is a simple helper around Self::tags
.
Auto Trait Implementations
impl RefUnwindSafe for NoSetterReturn
impl Send for NoSetterReturn
impl Sync for NoSetterReturn
impl Unpin for NoSetterReturn
impl UnwindSafe for NoSetterReturn
Blanket Implementations
Mutably borrows from an owned value. Read more
Whether this implementor has acknowledged the 1.1.0 update to
unerase
’s documented implementation requirements. Read more