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

§

type Query = ActualThisScope

The type of AstNode this rule is interested in
§

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>

An iterator type returned by run to yield zero or more signals to the analyzer
§

type Options = ()

The options that belong to a rule
source§

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 it
source§

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 more
source§

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 more
source§

fn phase() -> Phases

source§

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> )

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 more
source§

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>>

Returns a mutation to apply to the code
source§

impl RuleMeta for UseArrowFunction

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more