[−][src]Struct rslint_core::groups::errors::NoSetterReturn
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
impl NoSetterReturn
[src]
Trait Implementations
impl Clone for NoSetterReturn
[src]
fn clone(&self) -> NoSetterReturn
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl CstRule for NoSetterReturn
[src]
fn check_node(&self, node: &SyntaxNode, ctx: &mut RuleCtx) -> Option<()>
[src]
fn check_token(&self, token: &SyntaxToken, ctx: &mut RuleCtx) -> Option<()>
[src]
fn check_root(&self, root: &SyntaxNode, ctx: &mut RuleCtx) -> Option<()>
[src]
impl Debug for NoSetterReturn
[src]
impl Default for NoSetterReturn
[src]
fn default() -> NoSetterReturn
[src]
impl<'de> Deserialize<'de> for NoSetterReturn
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Rule for NoSetterReturn
[src]
fn name(&self) -> &'static str
[src]
fn group(&self) -> &'static str
[src]
fn docs(&self) -> &'static str
[src]
impl Serialize for NoSetterReturn
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
fn __clone_box(&self, Private) -> *mut ()
[src]
impl<T> Erasable for T
unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>
const ACK_1_1_0: bool
fn erase(this: NonNull<Self>) -> NonNull<Erased>
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,