|
1 | 1 | use itertools::Itertools; |
2 | | -use oxc_ast::{ |
3 | | - AstKind, |
4 | | - ast::{ModuleDeclaration, Statement}, |
5 | | -}; |
| 2 | +use oxc_ast::ast::{ModuleDeclaration, Statement}; |
6 | 3 | use oxc_diagnostics::OxcDiagnostic; |
7 | 4 | use oxc_macros::declare_oxc_lint; |
8 | 5 | use oxc_span::{GetSpan, Span}; |
@@ -54,19 +51,15 @@ declare_oxc_lint!( |
54 | 51 | impl Rule for ExportsLast { |
55 | 52 | fn run_once(&self, ctx: &LintContext<'_>) { |
56 | 53 | // find last non export declaration index |
57 | | - let Some(root) = ctx.nodes().root_node() else { |
58 | | - return; |
59 | | - }; |
60 | | - if let AstKind::Program(program) = root.kind() { |
61 | | - let body = &program.body; |
62 | | - let find_res = |
63 | | - body.iter().rev().find_position(|statement| !is_exports_declaration(statement)); |
64 | | - if let Some((index, _)) = find_res { |
65 | | - let end = body.len() - index; |
66 | | - for statement in &body[0..end] { |
67 | | - if is_exports_declaration(statement) { |
68 | | - ctx.diagnostic(exports_last_diagnostic(statement.span())); |
69 | | - } |
| 54 | + let program = ctx.nodes().program().unwrap(); |
| 55 | + let body = &program.body; |
| 56 | + let find_res = |
| 57 | + body.iter().rev().find_position(|statement| !is_exports_declaration(statement)); |
| 58 | + if let Some((index, _)) = find_res { |
| 59 | + let end = body.len() - index; |
| 60 | + for statement in &body[0..end] { |
| 61 | + if is_exports_declaration(statement) { |
| 62 | + ctx.diagnostic(exports_last_diagnostic(statement.span())); |
70 | 63 | } |
71 | 64 | } |
72 | 65 | } |
|
0 commit comments