pub enum UseArrowFunction {}Expand description
Use arrow functions over function expressions.
An arrow function expression is a compact alternative to a regular function expression,
with an important distinction:
this is not bound to the arrow function. It inherits this from its parent scope.
This rule proposes turning all function expressions that are not generators (function*) and don’t use this into arrow functions.
§Examples
§Invalid
const z = function() {
return 0;
}
const delegatedFetch = async function(url) {
return await fetch(url);
}
§Valid
const f = function() {
return this.prop;
}
Named function expressions are ignored:
const z = function z() {
return 0;
}
Function expressions that declare the type of this are also ignored:
const z = function(this: A): number {
return 0;
}
Trait Implementations§
source§impl Rule for UseArrowFunction
impl Rule for UseArrowFunction
§type Query = ActualThisScope
type Query = ActualThisScope
The type of AstNode this rule is interested in
§type State = ()
type State = ()
A generic type that will be kept in memory between a call to
run and
subsequent executions of diagnostic or action, allows the rule to
hold some temporary state between the moment a signal is raised and
when a diagnostic or action needs to be built§type Signals = Option<<UseArrowFunction as Rule>::State>
type Signals = Option<<UseArrowFunction as Rule>::State>
An iterator type returned by
run to yield zero or more signals to the
analyzersource§fn run(ctx: &RuleContext<'_, Self>) -> Self::Signals
fn run(ctx: &RuleContext<'_, Self>) -> Self::Signals
This function is called once for each node matching
Query in the tree
being analyzed. If it returns Some the state object will be wrapped
in a generic AnalyzerSignal, and the consumer of the analyzer may call
diagnostic or action on itsource§fn diagnostic(
ctx: &RuleContext<'_, Self>,
_: &Self::State
) -> Option<RuleDiagnostic>
fn diagnostic( ctx: &RuleContext<'_, Self>, _: &Self::State ) -> Option<RuleDiagnostic>
Called by the consumer of the analyzer to try to generate a diagnostic
from a signal raised by
run Read moresource§fn action(
ctx: &RuleContext<'_, Self>,
_: &Self::State
) -> Option<RuleAction<JsLanguage>>
fn action( ctx: &RuleContext<'_, Self>, _: &Self::State ) -> Option<RuleAction<JsLanguage>>
Called by the consumer of the analyzer to try to generate a code action
from a signal raised by
run Read morefn phase() -> Phases
source§fn text_range(
ctx: &RuleContext<'_, Self>,
state: &Self::State
) -> Option<TextRange>
fn text_range( ctx: &RuleContext<'_, Self>, state: &Self::State ) -> Option<TextRange>
Used by the analyzer to associate a range of source text to a signal in
order to support suppression comments. Read more
source§fn suppressed_nodes(
ctx: &RuleContext<'_, Self>,
state: &Self::State,
suppressions: &mut RuleSuppressions<<Self::Query as Queryable>::Language>
)
fn suppressed_nodes( ctx: &RuleContext<'_, Self>, state: &Self::State, suppressions: &mut RuleSuppressions<<Self::Query as Queryable>::Language> )
Allows the rule to suppress a set of syntax nodes to prevent them from
matching the
Query. This is useful for rules that implement a code
action that recursively modifies multiple nodes at once, this hook
allows these rules to avoid matching on those nodes again. Read moresource§fn suppress(
ctx: &RuleContext<'_, Self>,
text_range: &TextRange,
apply_suppression_comment: fn(_: SuppressionCommentEmitterPayload<'_, <Self::Query as Queryable>::Language>)
) -> Option<SuppressAction<<Self::Query as Queryable>::Language>>where
Self: 'static,
fn suppress(
ctx: &RuleContext<'_, Self>,
text_range: &TextRange,
apply_suppression_comment: fn(_: SuppressionCommentEmitterPayload<'_, <Self::Query as Queryable>::Language>)
) -> Option<SuppressAction<<Self::Query as Queryable>::Language>>where
Self: 'static,
Create a code action that allows to suppress the rule. The function
returns the node to which the suppression comment is applied.
source§fn transform(
_ctx: &RuleContext<'_, Self>,
_state: &Self::State
) -> Option<BatchMutation<<Self::Query as Queryable>::Language>>
fn transform( _ctx: &RuleContext<'_, Self>, _state: &Self::State ) -> Option<BatchMutation<<Self::Query as Queryable>::Language>>
Returns a mutation to apply to the code
source§impl RuleMeta for UseArrowFunction
impl RuleMeta for UseArrowFunction
type Group = Complexity
const METADATA: RuleMetadata = _
Auto Trait Implementations§
impl Freeze for UseArrowFunction
impl RefUnwindSafe for UseArrowFunction
impl Send for UseArrowFunction
impl Sync for UseArrowFunction
impl Unpin for UseArrowFunction
impl UnwindSafe for UseArrowFunction
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more