Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linter): implement eslint(array-callback-return) #221

Merged
merged 6 commits into from
Mar 29, 2023

Conversation

YangchenYe323
Copy link
Contributor

I tried implementing array-callback-return discussed in #218 based purely on AST.

I couldn't find an easy way to use the Visit trait for our task, i.e, given a Statement, find out whether it will return explicitly on all paths. The structure is like this (take IfStatement as an example):

fn visit_if_statement(s: &IfStatement) -> bool {
  let consequent = visit_statement(s.consequent)
  let alternate = visit_statement(s.alternate)
  consequent && alternate
}

The check for switch statement is even more complex with a lot of local computations.
Wonder if this can be translated to use the Visit trait and store the on-stack local states somewhere in the visitor.

crates/oxc_ast/src/ast/js.rs Outdated Show resolved Hide resolved
crates/oxc_linter/src/ast_util.rs Show resolved Hide resolved
crates/oxc_linter/src/rules/array_callback_return/mod.rs Outdated Show resolved Hide resolved
@Boshen
Copy link
Member

Boshen commented Mar 29, 2023

@magic-akari Do you want to review this as well? Some of this is beyond me 😁

@Boshen Boshen merged commit a2d0d2d into oxc-project:main Mar 29, 2023
@Boshen
Copy link
Member

Boshen commented Mar 29, 2023

Amazing work!

@Boshen Boshen added this to the 0.0.3 milestone Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants