diff --git a/Cargo.lock b/Cargo.lock index 2bafc52f0..6a300b679 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "ansi_term" version = "0.12.1" @@ -115,6 +121,9 @@ name = "bumpalo" version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +dependencies = [ + "allocator-api2", +] [[package]] name = "cc" @@ -211,14 +220,15 @@ checksum = "41b319d1b62ffbd002e057f36bebd1f42b9f97927c9577461d855f3513c4289f" [[package]] name = "deno_ast" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c80b9ee18ff242fb4b2dbe052489557dd86c2d611b4e4e537a75e0524ab0400" +checksum = "84b28da6d573c30a63e4a6b66b91fa32773ed2cf4c0f26aa19b91f6c542b1a57" dependencies = [ "deno_media_type", "deno_terminal", "dprint-swc-ext", "once_cell", + "percent-encoding", "serde", "swc_atoms", "swc_common", @@ -274,9 +284,9 @@ dependencies = [ [[package]] name = "deno_terminal" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b847702ef57565e1417fad2291f65a3c8a5ecf2ba38d64e56f02828e7546d891" +checksum = "7e6337d4e7f375f8b986409a76fbeecfa4bd8a1343e63355729ae4befa058eaf" dependencies = [ "once_cell", "termcolor", @@ -297,10 +307,11 @@ dependencies = [ [[package]] name = "dprint-swc-ext" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebaedd46a16dd179b260a9fcb56be5780814afcb20f615eedde6acf971c9628e" +checksum = "8fcd02c378803dba687471a9f1f1b758c33e53f616333faaddbaeb8840d9b6dd" dependencies = [ + "allocator-api2", "bumpalo", "num-bigint", "rustc-hash", @@ -651,9 +662,9 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" @@ -1062,9 +1073,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.137.3" +version = "0.137.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd47dd9ccb73a1f5d8d7eff9518554b752b1733b56503af090e78859abb42dd" +checksum = "b9489f8f5c6c08e8291bd93eb354aa91903d4eba5eeb72e1b90adf43c8fe7a29" dependencies = [ "better_scoped_tls", "bitflags 2.3.3", @@ -1085,9 +1096,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.127.3" +version = "0.127.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd185161161dfc65ee0d6f3044c901b766c3abb4efcd0b35c9e76c833724896" +checksum = "b2de25ac5cc8c8375476985e854054f05d9e841886f3c290716a0eec32eedce3" dependencies = [ "indexmap 2.1.0", "num_cpus", diff --git a/Cargo.toml b/Cargo.toml index d0715f90f..7a83aa0e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ default = [] docs = [] [dependencies] -deno_ast = { version = "0.33.0", features = ["scopes", "transforms", "utils", "visit", "view"] } +deno_ast = { version = "0.34.0", features = ["scopes", "transforms", "utils", "visit", "view"] } log = "0.4.20" serde = { version = "1.0.195", features = ["derive"] } serde_json = "1.0.111" diff --git a/src/rules/adjacent_overload_signatures.rs b/src/rules/adjacent_overload_signatures.rs index 0aa92808b..7ea7cdd20 100644 --- a/src/rules/adjacent_overload_signatures.rs +++ b/src/rules/adjacent_overload_signatures.rs @@ -52,11 +52,11 @@ struct AdjacentOverloadSignaturesHandler; impl Handler for AdjacentOverloadSignaturesHandler { fn script(&mut self, script: &ast_view::Script, ctx: &mut Context) { - check(&script.body, ctx); + check(script.body, ctx); } fn module(&mut self, module: &ast_view::Module, ctx: &mut Context) { - check(&module.body, ctx); + check(module.body, ctx); } fn ts_module_block( @@ -64,11 +64,11 @@ impl Handler for AdjacentOverloadSignaturesHandler { ts_module_block: &ast_view::TsModuleBlock, ctx: &mut Context, ) { - check(&ts_module_block.body, ctx); + check(ts_module_block.body, ctx); } fn class(&mut self, class: &ast_view::Class, ctx: &mut Context) { - check(&class.body, ctx); + check(class.body, ctx); } fn ts_type_lit( @@ -76,7 +76,7 @@ impl Handler for AdjacentOverloadSignaturesHandler { ts_type_lit: &ast_view::TsTypeLit, ctx: &mut Context, ) { - check(&ts_type_lit.members, ctx); + check(ts_type_lit.members, ctx); } fn ts_interface_body( @@ -84,7 +84,7 @@ impl Handler for AdjacentOverloadSignaturesHandler { ts_interface_body: &ast_view::TsInterfaceBody, ctx: &mut Context, ) { - check(&ts_interface_body.body, ctx); + check(ts_interface_body.body, ctx); } } diff --git a/src/rules/camelcase.rs b/src/rules/camelcase.rs index e3a765594..e45184491 100644 --- a/src/rules/camelcase.rs +++ b/src/rules/camelcase.rs @@ -368,7 +368,7 @@ impl CamelcaseHandler { fn check_ts_type(&mut self, ty: &ast_view::TsType) { if let ast_view::TsType::TsTypeLit(type_lit) = ty { - for member in &type_lit.members { + for member in type_lit.members { self.check_ts_type_element(member); } } @@ -417,7 +417,7 @@ impl CamelcaseHandler { ast_view::Pat::Ident(ident) => { self.check_ident(ident, IdentToCheck::variable(ident.id.inner)); } - ast_view::Pat::Array(ast_view::ArrayPat { ref elems, .. }) => { + ast_view::Pat::Array(ast_view::ArrayPat { elems, .. }) => { for pat in elems.iter().flatten() { self.check_pat(pat); } @@ -425,8 +425,8 @@ impl CamelcaseHandler { ast_view::Pat::Rest(ast_view::RestPat { ref arg, .. }) => { self.check_pat(arg); } - ast_view::Pat::Object(ast_view::ObjectPat { ref props, .. }) => { - for prop in props { + ast_view::Pat::Object(ast_view::ObjectPat { props, .. }) => { + for prop in *props { match prop { ast_view::ObjectPatProp::KeyValue(ast_view::KeyValuePatProp { ref key, @@ -536,13 +536,13 @@ impl Handler for CamelcaseHandler { return; } - for decl in &var_decl.decls { + for decl in var_decl.decls { self.check_pat(&decl.name); if let Some(expr) = &decl.init { match expr { - ast_view::Expr::Object(ast_view::ObjectLit { ref props, .. }) => { - for prop in props { + ast_view::Expr::Object(ast_view::ObjectLit { props, .. }) => { + for prop in *props { if let ast_view::PropOrSpread::Prop(prop) = prop { match prop { ast_view::Prop::Shorthand(ident) => self.check_ident( @@ -684,7 +684,7 @@ impl Handler for CamelcaseHandler { IdentToCheck::interface(interface_decl.id.inner), ); - for ty_el in &interface_decl.body.body { + for ty_el in interface_decl.body.body { self.check_ts_type_element(ty_el); } } @@ -732,7 +732,7 @@ impl Handler for CamelcaseHandler { self .check_ident(&enum_decl.id, IdentToCheck::enum_name(enum_decl.id.inner)); - for variant in &enum_decl.members { + for variant in enum_decl.members { if let ast_view::TsEnumMemberId::Ident(id) = &variant.id { self.check_ident(id, IdentToCheck::enum_variant(id.inner)); } diff --git a/src/rules/constructor_super.rs b/src/rules/constructor_super.rs index f7036e187..d37c7023e 100644 --- a/src/rules/constructor_super.rs +++ b/src/rules/constructor_super.rs @@ -101,7 +101,7 @@ fn return_before_super<'a, 'view>( constructor: &'a ast_view::Constructor<'view>, ) -> Option<&'a ast_view::ReturnStmt<'view>> { if let Some(block_stmt) = &constructor.body { - for stmt in &block_stmt.stmts { + for stmt in block_stmt.stmts { if extract_super_range(stmt).is_some() { return None; } @@ -189,7 +189,7 @@ struct ConstructorSuperHandler; impl Handler for ConstructorSuperHandler { fn class(&mut self, class: &ast_view::Class, ctx: &mut Context) { - for member in &class.body { + for member in class.body { if let ast_view::ClassMember::Constructor(cons) = member { check_constructor(cons, class, ctx); } diff --git a/src/rules/explicit_module_boundary_types.rs b/src/rules/explicit_module_boundary_types.rs index dc4c30a67..f153d98dc 100644 --- a/src/rules/explicit_module_boundary_types.rs +++ b/src/rules/explicit_module_boundary_types.rs @@ -92,7 +92,7 @@ impl Handler for ExplicitModuleBoundaryTypesHandler { } fn check_class(class: &ast_view::Class, ctx: &mut Context) { - for member in &class.body { + for member in class.body { if let ast_view::ClassMember::Method(method) = member { let is_setter = method.inner.kind == ast_view::MethodKind::Setter; check_fn(method.function, ctx, is_setter); @@ -109,7 +109,7 @@ fn check_fn(function: &ast_view::Function, ctx: &mut Context, is_setter: bool) { ExplicitModuleBoundaryTypesHint::AddRetType, ); } - for param in &function.params { + for param in function.params { check_pat(¶m.pat, ctx); } } @@ -123,7 +123,7 @@ fn check_arrow(arrow: &ast_view::ArrowExpr, ctx: &mut Context) { ExplicitModuleBoundaryTypesHint::AddRetType, ); } - for pat in &arrow.params { + for pat in arrow.params { check_pat(pat, ctx); } } @@ -182,7 +182,7 @@ fn check_expr(expr: &ast_view::Expr, ctx: &mut Context) { } fn check_var_decl(var: &ast_view::VarDecl, ctx: &mut Context) { - for declarator in &var.decls { + for declarator in var.decls { if let Some(expr) = &declarator.init { check_expr(expr, ctx) } diff --git a/src/rules/no_case_declarations.rs b/src/rules/no_case_declarations.rs index 606d92960..f4eaf7ef5 100644 --- a/src/rules/no_case_declarations.rs +++ b/src/rules/no_case_declarations.rs @@ -40,7 +40,7 @@ struct NoCaseDeclarationsHandler; impl Handler for NoCaseDeclarationsHandler { fn switch_case(&mut self, switch_case: &SwitchCase, context: &mut Context) { - for stmt in &switch_case.cons { + for stmt in switch_case.cons { let is_lexical_decl = match stmt { Stmt::Decl(decl) => match &decl { Decl::Fn(_) => true, diff --git a/src/rules/no_control_regex.rs b/src/rules/no_control_regex.rs index f5edd61ba..97f42702b 100644 --- a/src/rules/no_control_regex.rs +++ b/src/rules/no_control_regex.rs @@ -140,7 +140,7 @@ impl Handler for NoControlRegexHandler { fn call_expr(&mut self, call_expr: &CallExpr, ctx: &mut Context) { if let Callee::Expr(Expr::Ident(ident)) = &call_expr.callee { - if let Some(regex) = extract_regex(ctx.scope(), ident, &call_expr.args) { + if let Some(regex) = extract_regex(ctx.scope(), ident, call_expr.args) { check_regex(regex.as_str(), call_expr.range(), ctx); } } diff --git a/src/rules/no_deprecated_deno_api.rs b/src/rules/no_deprecated_deno_api.rs index 6fc33facd..8ee6192af 100644 --- a/src/rules/no_deprecated_deno_api.rs +++ b/src/rules/no_deprecated_deno_api.rs @@ -51,11 +51,11 @@ fn extract_symbol<'a>( MemberProp::Computed(prop) => match &prop.expr { Expr::Lit(Lit::Str(s)) => Some(s.value()), Expr::Ident(ident) => Some(ident.sym()), - Expr::Tpl(Tpl { - ref exprs, - ref quasis, - .. - }) if exprs.is_empty() && quasis.len() == 1 => Some(quasis[0].raw()), + Expr::Tpl(Tpl { exprs, quasis, .. }) + if exprs.is_empty() && quasis.len() == 1 => + { + Some(quasis[0].raw()) + } _ => None, }, } diff --git a/src/rules/no_dupe_keys.rs b/src/rules/no_dupe_keys.rs index a275c374b..fafe65b95 100644 --- a/src/rules/no_dupe_keys.rs +++ b/src/rules/no_dupe_keys.rs @@ -169,7 +169,7 @@ impl Handler for NoDupeKeysHandler { let range = obj_lit.range(); let mut keys: HashMap = HashMap::new(); - for prop in &obj_lit.props { + for prop in obj_lit.props { if let PropOrSpread::Prop(prop) = prop { match prop { Prop::Shorthand(ident) => { diff --git a/src/rules/no_eval.rs b/src/rules/no_eval.rs index 56fd739b3..fca813bcc 100644 --- a/src/rules/no_eval.rs +++ b/src/rules/no_eval.rs @@ -61,7 +61,7 @@ impl NoEvalHandler { } // Multiple arguments callee: (0, eval)('var foo = 0;') Expr::Seq(seq) => { - for expr in &seq.exprs { + for expr in seq.exprs { if let Expr::Ident(ident) = expr { self.maybe_add_diagnostic(*ident, ident.range(), ctx) } diff --git a/src/rules/no_implicit_declare_namespace_export.rs b/src/rules/no_implicit_declare_namespace_export.rs index 80e96a829..eba2dc844 100644 --- a/src/rules/no_implicit_declare_namespace_export.rs +++ b/src/rules/no_implicit_declare_namespace_export.rs @@ -50,7 +50,7 @@ impl Handler for NoImplicitDeclareNamespaceExportHandler { module_decl.body { if !block.body.is_empty() { - let has_named_export = block.body.as_slice().iter().any(|item| { + let has_named_export = block.body.iter().any(|item| { matches!( item, ast_view::ModuleItem::ModuleDecl( @@ -60,7 +60,6 @@ impl Handler for NoImplicitDeclareNamespaceExportHandler { }); let has_non_exported_member = block .body - .as_slice() .iter() .any(|item| matches!(item, ast_view::ModuleItem::Stmt(_))); if !has_named_export && has_non_exported_member { diff --git a/src/rules/no_misused_new.rs b/src/rules/no_misused_new.rs index b15bbb7b8..047da9781 100644 --- a/src/rules/no_misused_new.rs +++ b/src/rules/no_misused_new.rs @@ -78,7 +78,7 @@ fn is_constructor_keyword(ident: &Ident) -> bool { impl Handler for NoMisusedNewHandler { fn ts_type_alias_decl(&mut self, t: &TsTypeAliasDecl, ctx: &mut Context) { if let TsType::TsTypeLit(lit) = t.type_ann { - for member in &lit.members { + for member in lit.members { if let TsMethodSignature(signature) = &member { if let Expr::Ident(ident) = signature.key { if is_constructor_keyword(ident) { @@ -96,7 +96,7 @@ impl Handler for NoMisusedNewHandler { } fn ts_interface_decl(&mut self, n: &TsInterfaceDecl, ctx: &mut Context) { - for member in &n.body.body { + for member in n.body.body { match &member { TsMethodSignature(signature) => { if let Expr::Ident(ident) = signature.key { @@ -129,7 +129,7 @@ impl Handler for NoMisusedNewHandler { } fn class_decl(&mut self, expr: &ClassDecl, ctx: &mut Context) { - for member in &expr.class.body { + for member in expr.class.body { if let ClassMember::Method(method) = member { let method_name = match &method.key { PropName::Ident(ident) => ident.sym().as_ref(), diff --git a/src/rules/no_regex_spaces.rs b/src/rules/no_regex_spaces.rs index de2853426..119ae2044 100644 --- a/src/rules/no_regex_spaces.rs +++ b/src/rules/no_regex_spaces.rs @@ -86,7 +86,7 @@ impl Handler for NoRegexSpacesHandler { fn call_expr(&mut self, call_expr: &CallExpr, ctx: &mut Context) { if let Callee::Expr(Expr::Ident(ident)) = &call_expr.callee { - if let Some(regex) = extract_regex(ctx.scope(), ident, &call_expr.args) { + if let Some(regex) = extract_regex(ctx.scope(), ident, call_expr.args) { check_regex(regex.as_str(), call_expr.range(), ctx); } } diff --git a/src/rules/no_shadow_restricted_names.rs b/src/rules/no_shadow_restricted_names.rs index 811063121..57f54633d 100644 --- a/src/rules/no_shadow_restricted_names.rs +++ b/src/rules/no_shadow_restricted_names.rs @@ -62,14 +62,14 @@ fn check_pat(pat: Pat, ctx: &mut Context) { check_shadowing(ident, ctx); } Pat::Array(array_pat) => { - for el in &array_pat.elems { + for el in array_pat.elems { if let Some(pat) = el.as_ref() { check_pat(*pat, ctx); } } } Pat::Object(object_pat) => { - for prop in &object_pat.props { + for prop in object_pat.props { match prop { ObjectPatProp::Assign(assign) => { check_shadowing(assign.key.id, ctx); @@ -104,7 +104,7 @@ fn report_shadowing(ident: &Ident, ctx: &mut Context) { impl Handler for NoShadowRestrictedNamesHandler { fn var_decl(&mut self, node: &VarDecl, ctx: &mut Context) { - for decl in &node.decls { + for decl in node.decls { if let Pat::Ident(ident) = &decl.name { // `undefined` variable declaration without init is have same meaning if decl.init.is_none() && *ident.id.sym() == *"undefined" { @@ -119,7 +119,7 @@ impl Handler for NoShadowRestrictedNamesHandler { fn fn_decl(&mut self, node: &FnDecl, ctx: &mut Context) { check_shadowing(node.ident, ctx); - for param in &node.function.params { + for param in node.function.params { check_pat(param.pat, ctx); } } @@ -129,13 +129,13 @@ impl Handler for NoShadowRestrictedNamesHandler { check_shadowing(ident, ctx) } - for param in &node.function.params { + for param in node.function.params { check_pat(param.pat, ctx); } } fn arrow_expr(&mut self, node: &ArrowExpr, ctx: &mut Context) { - for param in &node.params { + for param in node.params { check_pat(*param, ctx); } } diff --git a/src/rules/no_sync_fn_in_async_fn.rs b/src/rules/no_sync_fn_in_async_fn.rs index fe3025abd..53ecbe897 100644 --- a/src/rules/no_sync_fn_in_async_fn.rs +++ b/src/rules/no_sync_fn_in_async_fn.rs @@ -49,11 +49,11 @@ fn extract_symbol<'a>( MemberProp::Computed(prop) => match &prop.expr { Expr::Lit(Lit::Str(s)) => Some(s.value()), Expr::Ident(ident) => Some(ident.sym()), - Expr::Tpl(Tpl { - ref exprs, - ref quasis, - .. - }) if exprs.is_empty() && quasis.len() == 1 => Some(quasis[0].raw()), + Expr::Tpl(Tpl { exprs, quasis, .. }) + if exprs.is_empty() && quasis.len() == 1 => + { + Some(quasis[0].raw()) + } _ => None, }, } diff --git a/src/rules/no_this_alias.rs b/src/rules/no_this_alias.rs index eeccba313..7830db6d7 100644 --- a/src/rules/no_this_alias.rs +++ b/src/rules/no_this_alias.rs @@ -40,7 +40,7 @@ struct NoThisAliasHandler; impl Handler for NoThisAliasHandler { fn var_decl(&mut self, var_decl: &VarDecl, ctx: &mut Context) { - for decl in &var_decl.decls { + for decl in var_decl.decls { if_chain! { if let Some(init) = &decl.init; if matches!(&init, Expr::This(_)); diff --git a/src/rules/no_this_before_super.rs b/src/rules/no_this_before_super.rs index 2e65f2ffe..0a543f012 100644 --- a/src/rules/no_this_before_super.rs +++ b/src/rules/no_this_before_super.rs @@ -90,7 +90,7 @@ impl Handler for NoThisBeforeSuperHandler { } if let Some(body) = cons.body { - for stmt in &body.stmts { + for stmt in body.stmts { let mut checker = SuperCallChecker::new(stmt.range()); checker.traverse(*stmt, ctx); match checker.result() { @@ -185,7 +185,7 @@ impl Handler for SuperCallChecker { } // arguments are evaluated before the callee - for arg in &call_expr.args { + for arg in call_expr.args { self.traverse(arg.as_node(), ctx); } diff --git a/src/rules/no_window_prefix.rs b/src/rules/no_window_prefix.rs index c4f50ffb4..3e5a75b94 100644 --- a/src/rules/no_window_prefix.rs +++ b/src/rules/no_window_prefix.rs @@ -216,11 +216,11 @@ fn extract_symbol<'a>(expr: &'a ast_view::MemberExpr) -> Option<&'a str> { Expr::Lit(Lit::Str(s)) => Some(s.value()), // If it's computed, this MemberExpr looks like `foo[bar]` Expr::Ident(_) => None, - Expr::Tpl(Tpl { - ref exprs, - ref quasis, - .. - }) if exprs.is_empty() && quasis.len() == 1 => Some(quasis[0].raw()), + Expr::Tpl(Tpl { exprs, quasis, .. }) + if exprs.is_empty() && quasis.len() == 1 => + { + Some(quasis[0].raw()) + } _ => None, }, } diff --git a/src/rules/prefer_as_const.rs b/src/rules/prefer_as_const.rs index 972fe44e4..7d489efae 100644 --- a/src/rules/prefer_as_const.rs +++ b/src/rules/prefer_as_const.rs @@ -113,7 +113,7 @@ impl Handler for PreferAsConstHandler { } fn var_decl(&mut self, var_decl: &VarDecl, ctx: &mut Context) { - for decl in &var_decl.decls { + for decl in var_decl.decls { if let Some(init) = &decl.init { if let Pat::Array(ArrayPat { type_ann, .. }) | Pat::Object(ObjectPat { type_ann, .. }) diff --git a/src/rules/use_isnan.rs b/src/rules/use_isnan.rs index 44b6364cc..3404ca8da 100644 --- a/src/rules/use_isnan.rs +++ b/src/rules/use_isnan.rs @@ -100,7 +100,7 @@ impl Handler for UseIsNaNHandler { } } - for case in &switch_stmt.cases { + for case in switch_stmt.cases { if let Some(Expr::Ident(ident)) = &case.test { if is_nan_identifier(ident) { ctx.add_diagnostic(