From 3184b4012dfc8bbbc7ac57f846985832e0e779e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 29 Nov 2024 14:22:24 +0000 Subject: [PATCH] refactor: Make tags strongly typed (#1367) * refactor: Make tags strongly typed * fmt --- examples/dlint/rules.rs | 9 +++--- src/lib.rs | 1 + src/rules.rs | 10 +++++-- src/rules/adjacent_overload_signatures.rs | 5 ++-- src/rules/ban_ts_comment.rs | 6 ++-- src/rules/ban_types.rs | 5 ++-- src/rules/ban_unknown_rule_code.rs | 9 ++++-- src/rules/ban_untagged_ignore.rs | 9 ++++-- src/rules/ban_unused_ignore.rs | 9 ++++-- src/rules/camelcase.rs | 3 +- src/rules/constructor_super.rs | 5 ++-- src/rules/for_direction.rs | 5 ++-- src/rules/fresh_handler_export.rs | 5 ++-- src/rules/fresh_server_event_handlers.rs | 5 ++-- src/rules/getter_return.rs | 5 ++-- src/rules/jsx_curly_braces.rs | 5 ++-- src/rules/jsx_no_children_prop.rs | 5 ++-- src/rules/jsx_no_duplicate_props.rs | 5 ++-- src/rules/jsx_props_no_spread_multi.rs | 5 ++-- .../jsx_void_dom_elements_no_children.rs | 5 ++-- src/rules/no_array_constructor.rs | 5 ++-- src/rules/no_async_promise_executor.rs | 5 ++-- src/rules/no_await_in_sync_fn.rs | 5 ++-- src/rules/no_boolean_literal_for_arguments.rs | 3 +- src/rules/no_case_declarations.rs | 5 ++-- src/rules/no_class_assign.rs | 5 ++-- src/rules/no_compare_neg_zero.rs | 5 ++-- src/rules/no_cond_assign.rs | 5 ++-- src/rules/no_console.rs | 3 +- src/rules/no_constant_condition.rs | 5 ++-- src/rules/no_control_regex.rs | 5 ++-- src/rules/no_danger.rs | 5 ++-- src/rules/no_debugger.rs | 5 ++-- src/rules/no_delete_var.rs | 5 ++-- src/rules/no_deprecated_deno_api.rs | 6 ++-- src/rules/no_dupe_args.rs | 5 ++-- src/rules/no_dupe_class_members.rs | 5 ++-- src/rules/no_dupe_else_if.rs | 5 ++-- src/rules/no_dupe_keys.rs | 5 ++-- src/rules/no_duplicate_case.rs | 5 ++-- src/rules/no_empty.rs | 5 ++-- src/rules/no_empty_character_class.rs | 5 ++-- src/rules/no_empty_enum.rs | 5 ++-- src/rules/no_empty_interface.rs | 5 ++-- src/rules/no_empty_pattern.rs | 5 ++-- src/rules/no_ex_assign.rs | 5 ++-- src/rules/no_explicit_any.rs | 5 ++-- src/rules/no_external_imports.rs | 3 +- src/rules/no_extra_boolean_cast.rs | 5 ++-- src/rules/no_extra_non_null_assertion.rs | 6 ++-- src/rules/no_fallthrough.rs | 5 ++-- src/rules/no_func_assign.rs | 5 ++-- src/rules/no_global_assign.rs | 5 ++-- .../no_implicit_declare_namespace_export.rs | 3 +- src/rules/no_import_assertions.rs | 5 ++-- src/rules/no_import_assign.rs | 5 ++-- src/rules/no_inner_declarations.rs | 5 ++-- src/rules/no_invalid_regexp.rs | 7 +++-- .../no_invalid_triple_slash_reference.rs | 5 ++-- src/rules/no_irregular_whitespace.rs | 5 ++-- src/rules/no_misused_new.rs | 5 ++-- src/rules/no_namespace.rs | 5 ++-- src/rules/no_new_symbol.rs | 5 ++-- src/rules/no_node_globals.rs | 6 ++-- src/rules/no_obj_calls.rs | 5 ++-- src/rules/no_octal.rs | 5 ++-- src/rules/no_process_global.rs | 6 ++-- src/rules/no_prototype_builtins.rs | 5 ++-- src/rules/no_redeclare.rs | 5 ++-- src/rules/no_regex_spaces.rs | 5 ++-- src/rules/no_self_assign.rs | 5 ++-- src/rules/no_setter_return.rs | 5 ++-- src/rules/no_shadow_restricted_names.rs | 5 ++-- src/rules/no_sync_fn_in_async_fn.rs | 3 +- src/rules/no_this_alias.rs | 5 ++-- src/rules/no_this_before_super.rs | 5 ++-- src/rules/no_unreachable.rs | 6 ++-- src/rules/no_unsafe_finally.rs | 5 ++-- src/rules/no_unsafe_negation.rs | 5 ++-- src/rules/no_unused_labels.rs | 5 ++-- src/rules/no_unused_vars.rs | 5 ++-- src/rules/no_var.rs | 5 ++-- src/rules/no_window.rs | 6 ++-- src/rules/no_window_prefix.rs | 6 ++-- src/rules/no_with.rs | 5 ++-- src/rules/prefer_as_const.rs | 5 ++-- src/rules/prefer_const.rs | 5 ++-- src/rules/prefer_namespace_keyword.rs | 5 ++-- src/rules/prefer_primordials.rs | 3 +- src/rules/require_await.rs | 5 ++-- src/rules/require_yield.rs | 5 ++-- src/rules/use_isnan.rs | 7 +++-- src/rules/valid_typeof.rs | 9 ++++-- src/rules/verbatim_module_syntax.rs | 5 ++-- src/tags.rs | 28 +++++++++++++++++++ 95 files changed, 330 insertions(+), 187 deletions(-) create mode 100644 src/tags.rs diff --git a/examples/dlint/rules.rs b/examples/dlint/rules.rs index 1b1d9a851..e7387c61d 100644 --- a/examples/dlint/rules.rs +++ b/examples/dlint/rules.rs @@ -2,13 +2,14 @@ use crate::color::colorize_markdown; use deno_lint::rules::get_all_rules; +use deno_lint::tags; use serde::Serialize; -#[derive(Clone, Copy, Serialize)] +#[derive(Clone, Serialize)] pub struct Rule { code: &'static str, docs: &'static str, - tags: &'static [&'static str], + tags: Vec<&'static str>, } pub fn get_all_rules_metadata() -> Vec { @@ -17,7 +18,7 @@ pub fn get_all_rules_metadata() -> Vec { .map(|rule| Rule { code: rule.code(), docs: rule.docs(), - tags: rule.tags(), + tags: rule.tags().iter().map(|tag| tag.display()).collect(), }) .collect() } @@ -89,7 +90,7 @@ impl RuleFormatter for PrettyFormatter { list.push("Available rules (trailing ✔️ mark indicates it is included in the recommended rule set):".to_string()); list.extend(rules.iter().map(|r| { let mut s = format!(" - {}", r.code); - if r.tags.contains(&"recommended") { + if r.tags.contains(&tags::RECOMMENDED.display()) { s += " ✔️"; } s diff --git a/src/lib.rs b/src/lib.rs index ad2e550c8..aa3e87010 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ pub mod linter; mod performance_mark; pub mod rules; pub mod swc_util; +pub mod tags; pub use deno_ast::view::Program; pub use deno_ast::view::ProgramRef; diff --git a/src/rules.rs b/src/rules.rs index 51e3268fd..6a152a6b1 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,6 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use crate::context::Context; +use crate::tags; +use crate::tags::Tags; use crate::Program; use crate::ProgramRef; use std::cmp::Ordering; @@ -132,7 +134,7 @@ pub trait LintRule: std::fmt::Debug + Send + Sync { fn code(&self) -> &'static str; /// Returns the tags this rule belongs to, e.g. `recommended` - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } @@ -168,7 +170,7 @@ pub fn recommended_rules( ) -> Vec> { all_rules .into_iter() - .filter(|r| r.tags().contains(&"recommended")) + .filter(|r| r.tags().contains(&tags::RECOMMENDED)) .collect() } @@ -367,6 +369,8 @@ fn get_all_rules_raw() -> Vec> { mod tests { use std::sync::Arc; + use crate::tags; + use super::*; #[test] @@ -474,7 +478,7 @@ mod tests { let rules = Arc::clone(&rules); spawn(move || { for rule in rules.iter() { - assert!(rule.tags().contains(&"recommended")); + assert!(rule.tags().contains(&tags::RECOMMENDED)); } }) }) diff --git a/src/rules/adjacent_overload_signatures.rs b/src/rules/adjacent_overload_signatures.rs index 7ea7cdd20..0d7c6fb0a 100644 --- a/src/rules/adjacent_overload_signatures.rs +++ b/src/rules/adjacent_overload_signatures.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{view as ast_view, SourceRanged}; use derive_more::Display; @@ -26,8 +27,8 @@ enum AdjacentOverloadSignaturesHint { } impl LintRule for AdjacentOverloadSignatures { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/ban_ts_comment.rs b/src/rules/ban_ts_comment.rs index 1e1006462..47f3b401e 100644 --- a/src/rules/ban_ts_comment.rs +++ b/src/rules/ban_ts_comment.rs @@ -1,6 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::swc::common::comments::Comment; use deno_ast::swc::common::comments::CommentKind; @@ -68,8 +70,8 @@ impl BanTsComment { } impl LintRule for BanTsComment { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/ban_types.rs b/src/rules/ban_types.rs index 69a623dc1..b94532191 100644 --- a/src/rules/ban_types.rs +++ b/src/rules/ban_types.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::TsEntityName; use deno_ast::{view as ast_view, SourceRanged}; @@ -74,8 +75,8 @@ impl TryFrom<&str> for BannedType { } impl LintRule for BanTypes { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/ban_unknown_rule_code.rs b/src/rules/ban_unknown_rule_code.rs index 43bd92562..caefcf231 100644 --- a/src/rules/ban_unknown_rule_code.rs +++ b/src/rules/ban_unknown_rule_code.rs @@ -1,7 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; -use crate::Program; +use crate::{ + tags::{self, Tags}, + Program, +}; /// This is a dummy struct just for having the docs. /// The actual implementation resides in [`Context`]. @@ -11,8 +14,8 @@ pub struct BanUnknownRuleCode; pub(crate) const CODE: &str = "ban-unknown-rule-code"; impl LintRule for BanUnknownRuleCode { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/ban_untagged_ignore.rs b/src/rules/ban_untagged_ignore.rs index 61f880d9f..1ee90b3b0 100644 --- a/src/rules/ban_untagged_ignore.rs +++ b/src/rules/ban_untagged_ignore.rs @@ -1,7 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; -use crate::Program; +use crate::{ + tags::{self, Tags}, + Program, +}; use deno_ast::SourceRange; #[derive(Debug)] @@ -10,8 +13,8 @@ pub struct BanUntaggedIgnore; const CODE: &str = "ban-untagged-ignore"; impl LintRule for BanUntaggedIgnore { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/ban_unused_ignore.rs b/src/rules/ban_unused_ignore.rs index c2ba98ed3..ab15af0bd 100644 --- a/src/rules/ban_unused_ignore.rs +++ b/src/rules/ban_unused_ignore.rs @@ -1,7 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; -use crate::Program; +use crate::{ + tags::{self, Tags}, + Program, +}; /// This is a dummy struct just for having the docs. /// The actual implementation resides in [`Context`]. @@ -9,8 +12,8 @@ use crate::Program; pub struct BanUnusedIgnore; impl LintRule for BanUnusedIgnore { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/camelcase.rs b/src/rules/camelcase.rs index e45184491..8db208222 100644 --- a/src/rules/camelcase.rs +++ b/src/rules/camelcase.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::StringRepr; +use crate::tags::Tags; use deno_ast::view::{Node, NodeKind, NodeTrait}; use deno_ast::{view as ast_view, SourceRange, SourceRanged}; @@ -16,7 +17,7 @@ pub struct Camelcase; const CODE: &str = "camelcase"; impl LintRule for Camelcase { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/constructor_super.rs b/src/rules/constructor_super.rs index d37c7023e..274af4c5f 100644 --- a/src/rules/constructor_super.rs +++ b/src/rules/constructor_super.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{view as ast_view, SourceRange, SourceRanged}; use if_chain::if_chain; @@ -14,8 +15,8 @@ const CODE: &str = "constructor-super"; // This rule currently differs from the ESlint implementation // as there is currently no way of handling code paths in dlint impl LintRule for ConstructorSuper { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/for_direction.rs b/src/rules/for_direction.rs index 8c06d572d..f125d79b1 100644 --- a/src/rules/for_direction.rs +++ b/src/rules/for_direction.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::ast::AssignOp; use deno_ast::swc::ast::BinaryOp; @@ -15,8 +16,8 @@ use deno_ast::{view as ast_view, SourceRanged}; pub struct ForDirection; impl LintRule for ForDirection { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/fresh_handler_export.rs b/src/rules/fresh_handler_export.rs index 1259cee33..31250eb5c 100644 --- a/src/rules/fresh_handler_export.rs +++ b/src/rules/fresh_handler_export.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use deno_ast::view::{Decl, Pat, Program}; use deno_ast::SourceRanged; @@ -15,8 +16,8 @@ const MESSAGE: &str = const HINT: &str = "Did you mean \"handler\"?"; impl LintRule for FreshHandlerExport { - fn tags(&self) -> &'static [&'static str] { - &["fresh"] + fn tags(&self) -> Tags { + &[tags::FRESH] } fn code(&self) -> &'static str { diff --git a/src/rules/fresh_server_event_handlers.rs b/src/rules/fresh_server_event_handlers.rs index 7490a5678..44c51ef03 100644 --- a/src/rules/fresh_server_event_handlers.rs +++ b/src/rules/fresh_server_event_handlers.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use deno_ast::view::{ Expr, JSXAttrName, JSXAttrValue, JSXElementName, JSXExpr, Program, @@ -18,8 +19,8 @@ const HINT: &str = "Remove this property or turn the enclosing component into an island"; impl LintRule for FreshServerEventHandlers { - fn tags(&self) -> &'static [&'static str] { - &["fresh"] + fn tags(&self) -> Tags { + &[tags::FRESH] } fn code(&self) -> &'static str { diff --git a/src/rules/getter_return.rs b/src/rules/getter_return.rs index a59f48d86..5f3c4e518 100644 --- a/src/rules/getter_return.rs +++ b/src/rules/getter_return.rs @@ -3,6 +3,7 @@ use super::program_ref; use super::{Context, LintRule}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ @@ -39,8 +40,8 @@ enum GetterReturnHint { } impl LintRule for GetterReturn { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/jsx_curly_braces.rs b/src/rules/jsx_curly_braces.rs index 5d247164a..b6c0ccf0d 100644 --- a/src/rules/jsx_curly_braces.rs +++ b/src/rules/jsx_curly_braces.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::diagnostic::{LintFix, LintFixChange}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ Expr, JSXAttr, JSXAttrValue, JSXElement, JSXElementChild, JSXExpr, Lit, @@ -16,8 +17,8 @@ pub struct JSXCurlyBraces; const CODE: &str = "jsx-curly-braces"; impl LintRule for JSXCurlyBraces { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX] } fn code(&self) -> &'static str { diff --git a/src/rules/jsx_no_children_prop.rs b/src/rules/jsx_no_children_prop.rs index 018f21312..b458ad001 100644 --- a/src/rules/jsx_no_children_prop.rs +++ b/src/rules/jsx_no_children_prop.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{JSXAttrName, JSXAttrOrSpread, JSXOpeningElement}; use deno_ast::SourceRanged; @@ -12,8 +13,8 @@ pub struct JSXNoChildrenProp; const CODE: &str = "jsx-no-children-prop"; impl LintRule for JSXNoChildrenProp { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx", "fresh"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX, tags::FRESH] } fn code(&self) -> &'static str { diff --git a/src/rules/jsx_no_duplicate_props.rs b/src/rules/jsx_no_duplicate_props.rs index 8b69ba8c5..da8dbd7db 100644 --- a/src/rules/jsx_no_duplicate_props.rs +++ b/src/rules/jsx_no_duplicate_props.rs @@ -4,6 +4,7 @@ use std::collections::HashSet; use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{JSXAttrName, JSXAttrOrSpread, JSXOpeningElement}; use deno_ast::SourceRanged; @@ -14,8 +15,8 @@ pub struct JSXNoDuplicateProps; const CODE: &str = "jsx-no-duplicate-props"; impl LintRule for JSXNoDuplicateProps { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX] } fn code(&self) -> &'static str { diff --git a/src/rules/jsx_props_no_spread_multi.rs b/src/rules/jsx_props_no_spread_multi.rs index 3c5bf654c..f92c84ba3 100644 --- a/src/rules/jsx_props_no_spread_multi.rs +++ b/src/rules/jsx_props_no_spread_multi.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; use super::{Context, LintRule}; use crate::diagnostic::{LintFix, LintFixChange}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{JSXAttrOrSpread, JSXOpeningElement, NodeTrait}; use deno_ast::{SourceRange, SourceRanged}; @@ -15,8 +16,8 @@ pub struct JSXPropsNoSpreadMulti; const CODE: &str = "jsx-props-no-spread-multi"; impl LintRule for JSXPropsNoSpreadMulti { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX] } fn code(&self) -> &'static str { diff --git a/src/rules/jsx_void_dom_elements_no_children.rs b/src/rules/jsx_void_dom_elements_no_children.rs index 2a52839ee..f23ff7ced 100644 --- a/src/rules/jsx_void_dom_elements_no_children.rs +++ b/src/rules/jsx_void_dom_elements_no_children.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{JSXElement, JSXElementName}; use deno_ast::SourceRanged; @@ -12,8 +13,8 @@ pub struct JSXVoidDomElementsNoChildren; const CODE: &str = "jsx-void-dom-elements-no-children"; impl LintRule for JSXVoidDomElementsNoChildren { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx", "fresh"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX, tags::FRESH] } fn code(&self) -> &'static str { diff --git a/src/rules/no_array_constructor.rs b/src/rules/no_array_constructor.rs index 64792627c..a61ff6c30 100644 --- a/src/rules/no_array_constructor.rs +++ b/src/rules/no_array_constructor.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CallExpr, Callee, Expr, ExprOrSpread, NewExpr}; use deno_ast::{SourceRange, SourceRanged}; @@ -14,8 +15,8 @@ const MESSAGE: &str = "Array Constructor is not allowed"; const HINT: &str = "Use array literal notation (e.g. []) or single argument specifying array size only (e.g. new Array(5)"; impl LintRule for NoArrayConstructor { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_async_promise_executor.rs b/src/rules/no_async_promise_executor.rs index 4426ac6a6..b743c0577 100644 --- a/src/rules/no_async_promise_executor.rs +++ b/src/rules/no_async_promise_executor.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{Expr, NewExpr, ParenExpr}; use deno_ast::SourceRanged; @@ -15,8 +16,8 @@ const HINT: &str = "Remove `async` from executor function and adjust promise code as needed"; impl LintRule for NoAsyncPromiseExecutor { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_await_in_sync_fn.rs b/src/rules/no_await_in_sync_fn.rs index fed3d243b..8ee658cfa 100644 --- a/src/rules/no_await_in_sync_fn.rs +++ b/src/rules/no_await_in_sync_fn.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, SourceRanged}; @@ -14,8 +15,8 @@ const MESSAGE: &str = "Unexpected `await` inside a non-async function."; const HINT: &str = "Remove `await` in the function body or change the function to an async function."; impl LintRule for NoAwaitInSyncFn { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_boolean_literal_for_arguments.rs b/src/rules/no_boolean_literal_for_arguments.rs index c0d3f0fc5..6af941bdf 100644 --- a/src/rules/no_boolean_literal_for_arguments.rs +++ b/src/rules/no_boolean_literal_for_arguments.rs @@ -1,5 +1,6 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::view::{CallExpr, NodeTrait}; use deno_ast::SourceRanged; @@ -26,7 +27,7 @@ impl LintRule for NoBooleanLiteralForArguments { CODE } - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/no_case_declarations.rs b/src/rules/no_case_declarations.rs index f4eaf7ef5..061333341 100644 --- a/src/rules/no_case_declarations.rs +++ b/src/rules/no_case_declarations.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{Decl, Stmt, SwitchCase, VarDeclKind}; use deno_ast::SourceRanged; @@ -14,8 +15,8 @@ const MESSAGE: &str = "Unexpected declaration in case"; const HINT: &str = "Wrap switch case and default blocks in brackets"; impl LintRule for NoCaseDeclarations { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_class_assign.rs b/src/rules/no_class_assign.rs index a2046719d..396afc56a 100644 --- a/src/rules/no_class_assign.rs +++ b/src/rules/no_class_assign.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::find_lhs_ids; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::AssignExpr; use deno_ast::{BindingKind, SourceRanged}; @@ -15,8 +16,8 @@ const MESSAGE: &str = "Reassigning class declaration is not allowed"; const HINT: &str = "Do you have the right variable here?"; impl LintRule for NoClassAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_compare_neg_zero.rs b/src/rules/no_compare_neg_zero.rs index 706243f1f..d179724c5 100644 --- a/src/rules/no_compare_neg_zero.rs +++ b/src/rules/no_compare_neg_zero.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::ast::BinaryOp::*; use deno_ast::swc::ast::Expr::Lit; @@ -30,8 +31,8 @@ enum NoCompareNegZeroHint { } impl LintRule for NoCompareNegZero { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_cond_assign.rs b/src/rules/no_cond_assign.rs index 720d81de0..94f7461a2 100644 --- a/src/rules/no_cond_assign.rs +++ b/src/rules/no_cond_assign.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CondExpr, DoWhileStmt, Expr, ForStmt, IfStmt, WhileStmt}; use deno_ast::{SourceRange, SourceRanged}; @@ -29,8 +30,8 @@ enum NoCondAssignHint { } impl LintRule for NoCondAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_console.rs b/src/rules/no_console.rs index 8c5047b1e..df1d31640 100644 --- a/src/rules/no_console.rs +++ b/src/rules/no_console.rs @@ -1,5 +1,6 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::view as ast_view; @@ -13,7 +14,7 @@ const MESSAGE: &str = "`console` usage is not allowed."; const CODE: &str = "no-console"; impl LintRule for NoConsole { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/no_constant_condition.rs b/src/rules/no_constant_condition.rs index aca8c04a7..cc58bca5a 100644 --- a/src/rules/no_constant_condition.rs +++ b/src/rules/no_constant_condition.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{BinaryOp, CondExpr, Expr, IfStmt, Lit, UnaryOp}; @@ -30,8 +31,8 @@ enum NoConstantConditionHint { } impl LintRule for NoConstantCondition { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_control_regex.rs b/src/rules/no_control_regex.rs index 97f42702b..ccd9fdd01 100644 --- a/src/rules/no_control_regex.rs +++ b/src/rules/no_control_regex.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::extract_regex; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CallExpr, Callee, Expr, NewExpr, Regex}; use deno_ast::{SourceRange, SourceRanged}; @@ -33,8 +34,8 @@ enum NoControlRegexHint { } impl LintRule for NoControlRegex { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_danger.rs b/src/rules/no_danger.rs index da73752ff..eb536d483 100644 --- a/src/rules/no_danger.rs +++ b/src/rules/no_danger.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{JSXAttr, JSXAttrName}; use deno_ast::SourceRanged; @@ -12,8 +13,8 @@ pub struct NoDanger; const CODE: &str = "no-danger"; impl LintRule for NoDanger { - fn tags(&self) -> &'static [&'static str] { - &["recommended", "react", "jsx"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED, tags::REACT, tags::JSX] } fn code(&self) -> &'static str { diff --git a/src/rules/no_debugger.rs b/src/rules/no_debugger.rs index 0c7c8c342..8123f9c14 100644 --- a/src/rules/no_debugger.rs +++ b/src/rules/no_debugger.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::DebuggerStmt; use deno_ast::SourceRanged; @@ -25,8 +26,8 @@ enum NoDebuggerHint { } impl LintRule for NoDebugger { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_delete_var.rs b/src/rules/no_delete_var.rs index 98e5bd30f..8fce984f4 100644 --- a/src/rules/no_delete_var.rs +++ b/src/rules/no_delete_var.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{Expr, UnaryExpr, UnaryOp}; use deno_ast::SourceRanged; @@ -25,8 +26,8 @@ enum NoDeleteVarHint { } impl LintRule for NoDeleteVar { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_deprecated_deno_api.rs b/src/rules/no_deprecated_deno_api.rs index 98fdea968..0e59b6034 100644 --- a/src/rules/no_deprecated_deno_api.rs +++ b/src/rules/no_deprecated_deno_api.rs @@ -4,6 +4,8 @@ use super::Context; use super::LintRule; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::view as ast_view; @@ -17,8 +19,8 @@ pub struct NoDeprecatedDenoApi; const CODE: &str = "no-deprecated-deno-api"; impl LintRule for NoDeprecatedDenoApi { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_dupe_args.rs b/src/rules/no_dupe_args.rs index dd5a27780..e591851bf 100644 --- a/src/rules/no_dupe_args.rs +++ b/src/rules/no_dupe_args.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ArrowExpr, Function, Param, Pat}; use deno_ast::{SourceRange, SourceRanged}; @@ -26,8 +27,8 @@ enum NoDupeArgsHint { } impl LintRule for NoDupeArgs { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_dupe_class_members.rs b/src/rules/no_dupe_class_members.rs index d176061f2..f05b42e33 100644 --- a/src/rules/no_dupe_class_members.rs +++ b/src/rules/no_dupe_class_members.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ @@ -33,8 +34,8 @@ enum NoDupeClassMembersHint { } impl LintRule for NoDupeClassMembers { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_dupe_else_if.rs b/src/rules/no_dupe_else_if.rs index 49791cc0d..e67674d1e 100644 --- a/src/rules/no_dupe_else_if.rs +++ b/src/rules/no_dupe_else_if.rs @@ -3,6 +3,7 @@ use super::program_ref; use super::{Context, LintRule}; use crate::swc_util::span_and_ctx_drop; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{BinExpr, BinaryOp, Expr, IfStmt, ParenExpr, Stmt}; @@ -33,8 +34,8 @@ enum NoDupeElseIfHint { } impl LintRule for NoDupeElseIf { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_dupe_keys.rs b/src/rules/no_dupe_keys.rs index fafe65b95..d382a2137 100644 --- a/src/rules/no_dupe_keys.rs +++ b/src/rules/no_dupe_keys.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ GetterProp, KeyValueProp, MethodProp, ObjectLit, Prop, PropOrSpread, @@ -31,8 +32,8 @@ enum NoDupeKeysHint { } impl LintRule for NoDupeKeys { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_duplicate_case.rs b/src/rules/no_duplicate_case.rs index 4d46b3344..5a6d46793 100644 --- a/src/rules/no_duplicate_case.rs +++ b/src/rules/no_duplicate_case.rs @@ -3,6 +3,7 @@ use super::program_ref; use super::{Context, LintRule}; use crate::swc_util::span_and_ctx_drop; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{Expr, SwitchStmt}; @@ -30,8 +31,8 @@ enum NoDuplicateCaseHint { } impl LintRule for NoDuplicateCase { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_empty.rs b/src/rules/no_empty.rs index 942046aa9..9cbba5e1b 100644 --- a/src/rules/no_empty.rs +++ b/src/rules/no_empty.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ArrowExpr, BlockStmt, Constructor, Function, SwitchStmt}; use deno_ast::{SourceRanged, SourceRangedForSpanned}; @@ -12,8 +13,8 @@ pub struct NoEmpty; const CODE: &str = "no-empty"; impl LintRule for NoEmpty { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_empty_character_class.rs b/src/rules/no_empty_character_class.rs index fa136b134..7d29b4ef6 100644 --- a/src/rules/no_empty_character_class.rs +++ b/src/rules/no_empty_character_class.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::Regex; use deno_ast::SourceRanged; @@ -16,8 +17,8 @@ const HINT: &str = "Remove or rework the empty character class (`[]`) in the RegExp"; impl LintRule for NoEmptyCharacterClass { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_empty_enum.rs b/src/rules/no_empty_enum.rs index dce25700d..6406aed2c 100644 --- a/src/rules/no_empty_enum.rs +++ b/src/rules/no_empty_enum.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{view as ast_view, SourceRanged}; @@ -12,8 +13,8 @@ const CODE: &str = "no-empty-enum"; const MESSAGE: &str = "An empty enum is equivalent to `{}`. Remove this enum or add members to this enum."; impl LintRule for NoEmptyEnum { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_empty_interface.rs b/src/rules/no_empty_interface.rs index f9f38e30d..03360820b 100644 --- a/src/rules/no_empty_interface.rs +++ b/src/rules/no_empty_interface.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::TsInterfaceDecl; use deno_ast::SourceRanged; @@ -25,8 +26,8 @@ enum NoEmptyInterfaceHint { } impl LintRule for NoEmptyInterface { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_empty_pattern.rs b/src/rules/no_empty_pattern.rs index 5caa934e4..0780fd637 100644 --- a/src/rules/no_empty_pattern.rs +++ b/src/rules/no_empty_pattern.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ArrayPat, ObjectPat, ObjectPatProp}; @@ -18,8 +19,8 @@ const HINT: &str = "Add variable to pattern or apply correct default value syntax with `=`"; impl LintRule for NoEmptyPattern { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_ex_assign.rs b/src/rules/no_ex_assign.rs index aa944e1ad..c89eeda9a 100644 --- a/src/rules/no_ex_assign.rs +++ b/src/rules/no_ex_assign.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ ArrayPat, AssignExpr, AssignTarget, AssignTargetPat, Ident, ObjectPat, @@ -28,8 +29,8 @@ enum NoExAssignHint { } impl LintRule for NoExAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_explicit_any.rs b/src/rules/no_explicit_any.rs index 0f640fad3..38b87b553 100644 --- a/src/rules/no_explicit_any.rs +++ b/src/rules/no_explicit_any.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::ast::TsKeywordTypeKind::TsAnyKeyword; use deno_ast::view::TsKeywordType; @@ -15,8 +16,8 @@ const MESSAGE: &str = "`any` type is not allowed"; const HINT: &str = "Use a specific type other than `any`"; impl LintRule for NoExplicitAny { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_external_imports.rs b/src/rules/no_external_imports.rs index fc18ee1ed..625d1bdbf 100644 --- a/src/rules/no_external_imports.rs +++ b/src/rules/no_external_imports.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::view::ImportDecl; use deno_ast::{ModuleSpecifier, SourceRanged}; @@ -26,7 +27,7 @@ enum NoExternalImportHint { } impl LintRule for NoExternalImport { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/no_extra_boolean_cast.rs b/src/rules/no_extra_boolean_cast.rs index 3eff036c8..3eda185d2 100644 --- a/src/rules/no_extra_boolean_cast.rs +++ b/src/rules/no_extra_boolean_cast.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ CallExpr, Callee, CondExpr, DoWhileStmt, Expr, ExprOrSpread, ForStmt, Ident, @@ -34,8 +35,8 @@ enum NoExtraBooleanCastHint { } impl LintRule for NoExtraBooleanCast { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_extra_non_null_assertion.rs b/src/rules/no_extra_non_null_assertion.rs index a245a31e5..40b81be8a 100644 --- a/src/rules/no_extra_non_null_assertion.rs +++ b/src/rules/no_extra_non_null_assertion.rs @@ -4,6 +4,8 @@ use super::Context; use super::LintRule; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::view::Expr; @@ -32,8 +34,8 @@ enum NoExtraNonNullAssertionHint { } impl LintRule for NoExtraNonNullAssertion { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_fallthrough.rs b/src/rules/no_fallthrough.rs index 05ec0b3eb..77ecbaaad 100644 --- a/src/rules/no_fallthrough.rs +++ b/src/rules/no_fallthrough.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::common::comments::Comment; @@ -32,8 +33,8 @@ enum NoFallthroughHint { } impl LintRule for NoFallthrough { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_func_assign.rs b/src/rules/no_func_assign.rs index 764239b8b..390a28396 100644 --- a/src/rules/no_func_assign.rs +++ b/src/rules/no_func_assign.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::find_lhs_ids; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::AssignExpr; use deno_ast::{BindingKind, SourceRanged}; @@ -28,8 +29,8 @@ enum NoFuncAssignHint { } impl LintRule for NoFuncAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_global_assign.rs b/src/rules/no_global_assign.rs index 226f13ddc..3658bcfcb 100644 --- a/src/rules/no_global_assign.rs +++ b/src/rules/no_global_assign.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use crate::{globals::GLOBALS, swc_util::find_lhs_ids}; use deno_ast::swc::ast::Id; @@ -28,8 +29,8 @@ enum NoGlobalAssignHint { } impl LintRule for NoGlobalAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_implicit_declare_namespace_export.rs b/src/rules/no_implicit_declare_namespace_export.rs index eba2dc844..5b11bd2aa 100644 --- a/src/rules/no_implicit_declare_namespace_export.rs +++ b/src/rules/no_implicit_declare_namespace_export.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::{view as ast_view, SourceRanged}; @@ -15,7 +16,7 @@ use"; const HINT: &str = "Try adding an `export {};` to the top of the namespace to disable this behavior"; impl LintRule for NoImplicitDeclareNamespaceExport { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/no_import_assertions.rs b/src/rules/no_import_assertions.rs index eb6494c03..231a25a96 100644 --- a/src/rules/no_import_assertions.rs +++ b/src/rules/no_import_assertions.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::parser::token::{IdentLike, KnownIdent, Token, Word}; use deno_ast::view as ast_view; @@ -17,8 +18,8 @@ const MESSAGE: &str = const HINT: &str = "Instead use the `with` keyword"; impl LintRule for NoImportAssertions { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_import_assign.rs b/src/rules/no_import_assign.rs index c094f95f9..1efe775b6 100644 --- a/src/rules/no_import_assign.rs +++ b/src/rules/no_import_assign.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::BindingKind; @@ -21,8 +22,8 @@ const MESSAGE: &str = "Assignment to import is not allowed"; const HINT: &str = "Assign to another variable, this assignment is invalid"; impl LintRule for NoImportAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_inner_declarations.rs b/src/rules/no_inner_declarations.rs index 2212a81d4..174b4bb68 100644 --- a/src/rules/no_inner_declarations.rs +++ b/src/rules/no_inner_declarations.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ @@ -32,8 +33,8 @@ enum NoInnerDeclarationsHint { } impl LintRule for NoInnerDeclarations { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_invalid_regexp.rs b/src/rules/no_invalid_regexp.rs index e5f8802ee..3f2ea3942 100644 --- a/src/rules/no_invalid_regexp.rs +++ b/src/rules/no_invalid_regexp.rs @@ -2,9 +2,10 @@ use super::program_ref; use super::{Context, LintRule}; -use crate::js_regex::*; +use crate::tags::Tags; use crate::Program; use crate::ProgramRef; +use crate::{js_regex::*, tags}; use deno_ast::swc::ast::Expr; use deno_ast::swc::ast::ExprOrSpread; use deno_ast::swc::visit::noop_visit_type; @@ -20,8 +21,8 @@ const MESSAGE: &str = "Invalid RegExp literal"; const HINT: &str = "Rework regular expression to be a valid"; impl LintRule for NoInvalidRegexp { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_invalid_triple_slash_reference.rs b/src/rules/no_invalid_triple_slash_reference.rs index eb0ff8f0a..02f7a366c 100644 --- a/src/rules/no_invalid_triple_slash_reference.rs +++ b/src/rules/no_invalid_triple_slash_reference.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::common::comments::{Comment, CommentKind}; use deno_ast::MediaType; @@ -14,8 +15,8 @@ pub struct NoInvalidTripleSlashReference; const CODE: &str = "no-invalid-triple-slash-reference"; impl LintRule for NoInvalidTripleSlashReference { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_irregular_whitespace.rs b/src/rules/no_irregular_whitespace.rs index 8eec87616..cd36466d2 100644 --- a/src/rules/no_irregular_whitespace.rs +++ b/src/rules/no_irregular_whitespace.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{RootNode, SourceRangedForSpanned}; use deno_ast::{SourceRange, SourceRanged}; @@ -40,8 +41,8 @@ fn test_for_whitespace(value: &str) -> Vec { } impl LintRule for NoIrregularWhitespace { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_misused_new.rs b/src/rules/no_misused_new.rs index 047da9781..676f41d4d 100644 --- a/src/rules/no_misused_new.rs +++ b/src/rules/no_misused_new.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ ClassDecl, ClassMember, Expr, Ident, PropName, TsEntityName, TsInterfaceDecl, @@ -45,8 +46,8 @@ impl LintRule for NoMisusedNew { NoMisusedNewHandler.traverse(program, context); } - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_namespace.rs b/src/rules/no_namespace.rs index 87ea62e06..ff0f24be4 100644 --- a/src/rules/no_namespace.rs +++ b/src/rules/no_namespace.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, MediaType, SourceRanged}; @@ -16,8 +17,8 @@ const HINT: &str = "Use ES2015 module syntax (`import`/`export`) to organize the code instead"; impl LintRule for NoNamespace { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_new_symbol.rs b/src/rules/no_new_symbol.rs index c4f11242d..683231913 100644 --- a/src/rules/no_new_symbol.rs +++ b/src/rules/no_new_symbol.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{Expr, NewExpr}; use deno_ast::SourceRanged; @@ -14,8 +15,8 @@ const CODE: &str = "no-new-symbol"; const MESSAGE: &str = "`Symbol` cannot be called as a constructor."; impl LintRule for NoNewSymbol { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_node_globals.rs b/src/rules/no_node_globals.rs index dcac55cc9..0fa0c4042 100644 --- a/src/rules/no_node_globals.rs +++ b/src/rules/no_node_globals.rs @@ -6,6 +6,8 @@ use crate::diagnostic::LintFix; use crate::diagnostic::LintFixChange; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use std::borrow::Cow; @@ -44,8 +46,8 @@ impl LintRule for NoNodeGlobals { CODE } - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } #[cfg(feature = "docs")] diff --git a/src/rules/no_obj_calls.rs b/src/rules/no_obj_calls.rs index 23bf8455e..952f3e9df 100644 --- a/src/rules/no_obj_calls.rs +++ b/src/rules/no_obj_calls.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CallExpr, Callee, Expr, Ident, NewExpr}; use deno_ast::{SourceRange, SourceRanged}; @@ -16,8 +17,8 @@ fn get_message(callee_name: &str) -> String { } impl LintRule for NoObjCalls { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_octal.rs b/src/rules/no_octal.rs index a8f613b6c..73ec565d9 100644 --- a/src/rules/no_octal.rs +++ b/src/rules/no_octal.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::Number; use deno_ast::SourceRanged; @@ -16,8 +17,8 @@ const MESSAGE: &str = "Numeric literals beginning with `0` are not allowed"; const HINT: &str = "To express octal numbers, use `0o` as a prefix instead"; impl LintRule for NoOctal { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_process_global.rs b/src/rules/no_process_global.rs index 2ded9763b..f0fe492d7 100644 --- a/src/rules/no_process_global.rs +++ b/src/rules/no_process_global.rs @@ -6,6 +6,8 @@ use crate::diagnostic::LintFix; use crate::diagnostic::LintFixChange; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::view as ast_view; @@ -36,8 +38,8 @@ impl LintRule for NoProcessGlobal { CODE } - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } #[cfg(feature = "docs")] diff --git a/src/rules/no_prototype_builtins.rs b/src/rules/no_prototype_builtins.rs index 83e6ecd60..599dc18c3 100644 --- a/src/rules/no_prototype_builtins.rs +++ b/src/rules/no_prototype_builtins.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CallExpr, Callee, Expr, MemberProp}; use deno_ast::SourceRanged; @@ -22,8 +23,8 @@ fn get_message(prop: &str) -> String { } impl LintRule for NoPrototypeBuiltins { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_redeclare.rs b/src/rules/no_redeclare.rs index aebfdb3ac..280b2ae58 100644 --- a/src/rules/no_redeclare.rs +++ b/src/rules/no_redeclare.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::Id; @@ -20,8 +21,8 @@ const CODE: &str = "no-redeclare"; const MESSAGE: &str = "Redeclaration is not allowed"; impl LintRule for NoRedeclare { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_regex_spaces.rs b/src/rules/no_regex_spaces.rs index 119ae2044..b8053ba0f 100644 --- a/src/rules/no_regex_spaces.rs +++ b/src/rules/no_regex_spaces.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::extract_regex; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{CallExpr, Callee, Expr, NewExpr, Regex}; use deno_ast::{SourceRange, SourceRanged}; @@ -16,8 +17,8 @@ const MESSAGE: &str = "more than one consecutive spaces in RegExp is not allowed"; impl LintRule for NoRegexSpaces { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_self_assign.rs b/src/rules/no_self_assign.rs index 7b62cbd66..3134ee5dd 100644 --- a/src/rules/no_self_assign.rs +++ b/src/rules/no_self_assign.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::AssignExpr; @@ -40,8 +41,8 @@ enum NoSelfAssignHint { } impl LintRule for NoSelfAssign { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_setter_return.rs b/src/rules/no_setter_return.rs index 03def3c52..290e5158b 100644 --- a/src/rules/no_setter_return.rs +++ b/src/rules/no_setter_return.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, SourceRanged}; @@ -13,8 +14,8 @@ const CODE: &str = "no-setter-return"; const MESSAGE: &str = "Setter cannot return a value"; impl LintRule for NoSetterReturn { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_shadow_restricted_names.rs b/src/rules/no_shadow_restricted_names.rs index 57f54633d..86510ef67 100644 --- a/src/rules/no_shadow_restricted_names.rs +++ b/src/rules/no_shadow_restricted_names.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ ArrowExpr, AssignExpr, AssignTarget, CatchClause, Expr, FnDecl, FnExpr, @@ -22,8 +23,8 @@ enum NoShadowRestrictedNamesMessage { } impl LintRule for NoShadowRestrictedNames { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_sync_fn_in_async_fn.rs b/src/rules/no_sync_fn_in_async_fn.rs index 9b2c434e6..96f089517 100644 --- a/src/rules/no_sync_fn_in_async_fn.rs +++ b/src/rules/no_sync_fn_in_async_fn.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, SourceRanged}; @@ -15,7 +16,7 @@ const MESSAGE: &str = "Sync fn is used inside an async fn, this blocks deno event loop"; impl LintRule for NoSyncFnInAsyncFn { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/no_this_alias.rs b/src/rules/no_this_alias.rs index 7830db6d7..340a53597 100644 --- a/src/rules/no_this_alias.rs +++ b/src/rules/no_this_alias.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{Expr, Pat, VarDecl}; use deno_ast::SourceRanged; @@ -14,8 +15,8 @@ const CODE: &str = "no-this-alias"; const MESSAGE: &str = "assign `this` to declare a value is not allowed"; impl LintRule for NoThisAlias { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_this_before_super.rs b/src/rules/no_this_before_super.rs index 0a543f012..59623916f 100644 --- a/src/rules/no_this_before_super.rs +++ b/src/rules/no_this_before_super.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, SourceRange, SourceRanged}; @@ -14,8 +15,8 @@ const MESSAGE: &str = "In the constructor of derived classes, `this` / `super` a const HINT: &str = "Call `super()` before using `this` or `super` keyword."; impl LintRule for NoThisBeforeSuper { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_unreachable.rs b/src/rules/no_unreachable.rs index 32250f503..7a906b179 100644 --- a/src/rules/no_unreachable.rs +++ b/src/rules/no_unreachable.rs @@ -3,6 +3,8 @@ use super::program_ref; use super::Context; use super::LintRule; +use crate::tags; +use crate::tags::Tags; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::Decl; @@ -19,8 +21,8 @@ const CODE: &str = "no-unreachable"; const MESSAGE: &str = "This statement is unreachable"; impl LintRule for NoUnreachable { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_unsafe_finally.rs b/src/rules/no_unsafe_finally.rs index fbd496640..811e6e34d 100644 --- a/src/rules/no_unsafe_finally.rs +++ b/src/rules/no_unsafe_finally.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::{view as ast_view, SourceRange, SourceRanged}; @@ -38,8 +39,8 @@ impl From> for NoUnsafeFinallyMessage { } impl LintRule for NoUnsafeFinally { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_unsafe_negation.rs b/src/rules/no_unsafe_negation.rs index 35e5ec214..2aa86730f 100644 --- a/src/rules/no_unsafe_negation.rs +++ b/src/rules/no_unsafe_negation.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{view as ast_view, SourceRanged}; use derive_more::Display; @@ -21,8 +22,8 @@ enum NoUnsafeNegationMessage { const HINT: &str = "Add parentheses to clarify which range the negation operator should be applied to"; impl LintRule for NoUnsafeNegation { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_unused_labels.rs b/src/rules/no_unused_labels.rs index 6b4004b8f..5ef642173 100644 --- a/src/rules/no_unused_labels.rs +++ b/src/rules/no_unused_labels.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::{view as ast_view, SourceRanged}; use derive_more::Display; @@ -19,8 +20,8 @@ enum NoUnusedLabelsMessage { } impl LintRule for NoUnusedLabels { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_unused_vars.rs b/src/rules/no_unused_vars.rs index 692d3d16e..86043689e 100644 --- a/src/rules/no_unused_vars.rs +++ b/src/rules/no_unused_vars.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ @@ -55,8 +56,8 @@ enum NoUnusedVarsHint { } impl LintRule for NoUnusedVars { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_var.rs b/src/rules/no_var.rs index 0fa99ef9c..e8cdf80ec 100644 --- a/src/rules/no_var.rs +++ b/src/rules/no_var.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{NodeTrait, VarDecl, VarDeclKind}; use deno_ast::SourceRangedForSpanned; @@ -13,8 +14,8 @@ const MESSAGE: &str = "`var` keyword is not allowed."; const CODE: &str = "no-var"; impl LintRule for NoVar { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_window.rs b/src/rules/no_window.rs index e1431bfd1..e3f80c181 100644 --- a/src/rules/no_window.rs +++ b/src/rules/no_window.rs @@ -5,6 +5,8 @@ use crate::diagnostic::LintFix; use crate::diagnostic::LintFixChange; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::view as ast_view; @@ -21,8 +23,8 @@ const HINT: &str = "Instead, use `globalThis`"; const FIX_DESC: &str = "Rename window to globalThis"; impl LintRule for NoWindow { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_window_prefix.rs b/src/rules/no_window_prefix.rs index 366a35ea9..21238071c 100644 --- a/src/rules/no_window_prefix.rs +++ b/src/rules/no_window_prefix.rs @@ -6,6 +6,8 @@ use crate::diagnostic::LintFix; use crate::diagnostic::LintFixChange; use crate::handler::Handler; use crate::handler::Traverse; +use crate::tags; +use crate::tags::Tags; use crate::Program; use deno_ast::view as ast_view; @@ -24,8 +26,8 @@ const HINT: &str = const FIX_DESC: &str = "Rename window to globalThis"; impl LintRule for NoWindowPrefix { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/no_with.rs b/src/rules/no_with.rs index a480e9fe0..5beb4d240 100644 --- a/src/rules/no_with.rs +++ b/src/rules/no_with.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view as ast_view; use deno_ast::SourceRanged; @@ -13,8 +14,8 @@ const CODE: &str = "no-with"; const MESSAGE: &str = "`with` statement is not allowed"; impl LintRule for NoWith { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/prefer_as_const.rs b/src/rules/prefer_as_const.rs index 7d489efae..fbcd7dc08 100644 --- a/src/rules/prefer_as_const.rs +++ b/src/rules/prefer_as_const.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{ ArrayPat, BindingIdent, Expr, Lit, ObjectPat, Pat, TsAsExpr, TsLit, TsType, @@ -30,8 +31,8 @@ enum PreferAsConstHint { pub struct PreferAsConst; impl LintRule for PreferAsConst { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/prefer_const.rs b/src/rules/prefer_const.rs index ef22bc235..6530db1b4 100644 --- a/src/rules/prefer_const.rs +++ b/src/rules/prefer_const.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::{ @@ -44,8 +45,8 @@ enum PreferConstHint { } impl LintRule for PreferConst { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/prefer_namespace_keyword.rs b/src/rules/prefer_namespace_keyword.rs index 4831d0dec..4a536eb27 100644 --- a/src/rules/prefer_namespace_keyword.rs +++ b/src/rules/prefer_namespace_keyword.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::view::{TsModuleDecl, TsModuleName}; use deno_ast::SourceRanged; @@ -15,8 +16,8 @@ const CODE: &str = "prefer-namespace-keyword"; const MESSAGE: &str = "`module` keyword in module declaration is not allowed"; impl LintRule for PreferNamespaceKeyword { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/prefer_primordials.rs b/src/rules/prefer_primordials.rs index 61cc22685..ee5c8348a 100644 --- a/src/rules/prefer_primordials.rs +++ b/src/rules/prefer_primordials.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; +use crate::tags::Tags; use crate::Program; use deno_ast::view::NodeTrait; use deno_ast::Scope; @@ -62,7 +63,7 @@ enum PreferPrimordialsHint { } impl LintRule for PreferPrimordials { - fn tags(&self) -> &'static [&'static str] { + fn tags(&self) -> Tags { &[] } diff --git a/src/rules/require_await.rs b/src/rules/require_await.rs index 713a83cd0..8f79d387d 100644 --- a/src/rules/require_await.rs +++ b/src/rules/require_await.rs @@ -3,6 +3,7 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use deno_ast::swc::parser::token::{Token, Word}; use deno_ast::view::{NodeTrait, Program}; @@ -51,8 +52,8 @@ enum RequireAwaitHint { } impl LintRule for RequireAwait { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/require_yield.rs b/src/rules/require_yield.rs index 62b212bec..8d8ce286d 100644 --- a/src/rules/require_yield.rs +++ b/src/rules/require_yield.rs @@ -2,6 +2,7 @@ use super::program_ref; use super::{Context, LintRule}; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::ClassMethod; @@ -22,8 +23,8 @@ const CODE: &str = "require-yield"; const MESSAGE: &str = "Generator function has no `yield`"; impl LintRule for RequireYield { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/use_isnan.rs b/src/rules/use_isnan.rs index 3404ca8da..6c49adb06 100644 --- a/src/rules/use_isnan.rs +++ b/src/rules/use_isnan.rs @@ -2,7 +2,8 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; -use crate::Program; +use crate::tags::Tags; +use crate::{tags, Program}; use deno_ast::view::{BinExpr, BinaryOp, Expr, Ident, SwitchStmt}; use deno_ast::SourceRanged; use derive_more::Display; @@ -29,8 +30,8 @@ enum UseIsNaNMessage { } impl LintRule for UseIsNaN { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { diff --git a/src/rules/valid_typeof.rs b/src/rules/valid_typeof.rs index 33d747765..e7803c52e 100644 --- a/src/rules/valid_typeof.rs +++ b/src/rules/valid_typeof.rs @@ -3,6 +3,7 @@ use super::program_ref; use super::{Context, LintRule}; use crate::swc_util::StringRepr; +use crate::tags::{self, Tags}; use crate::Program; use crate::ProgramRef; use deno_ast::swc::ast::BinExpr; @@ -20,8 +21,8 @@ const CODE: &str = "valid-typeof"; const MESSAGE: &str = "Invalid typeof comparison value"; impl LintRule for ValidTypeof { - fn tags(&self) -> &'static [&'static str] { - &["recommended"] + fn tags(&self) -> Tags { + &[tags::RECOMMENDED] } fn code(&self) -> &'static str { @@ -45,6 +46,10 @@ impl LintRule for ValidTypeof { fn docs(&self) -> &'static str { include_str!("../../docs/rules/valid_typeof.md") } + + fn priority(&self) -> u32 { + 0 + } } struct ValidTypeofVisitor<'c, 'view> { diff --git a/src/rules/verbatim_module_syntax.rs b/src/rules/verbatim_module_syntax.rs index 93bae01f4..6de638922 100644 --- a/src/rules/verbatim_module_syntax.rs +++ b/src/rules/verbatim_module_syntax.rs @@ -2,6 +2,7 @@ use super::{Context, LintRule}; use crate::diagnostic::{LintFix, LintFixChange}; +use crate::tags::{self, Tags}; use crate::Program; use deno_ast::swc::ast::{ BindingIdent, ExportNamedSpecifier, Id, Ident, ImportDecl, ImportSpecifier, @@ -212,8 +213,8 @@ impl VerbatimModuleSyntax { } impl LintRule for VerbatimModuleSyntax { - fn tags(&self) -> &'static [&'static str] { - &["jsr"] + fn tags(&self) -> Tags { + &[tags::JSR] } fn code(&self) -> &'static str { diff --git a/src/tags.rs b/src/tags.rs new file mode 100644 index 000000000..3bf795e09 --- /dev/null +++ b/src/tags.rs @@ -0,0 +1,28 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use std::fmt::Display; + +#[derive(Debug, Hash, PartialEq)] +pub struct Tag(&'static str); + +pub type Tags = &'static [Tag]; + +impl Display for Tag { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl Tag { + pub fn display(&self) -> &'static str { + self.0 + } +} + +pub const RECOMMENDED: Tag = Tag("recommended"); +pub const FRESH: Tag = Tag("fresh"); +pub const JSR: Tag = Tag("jsr"); +pub const REACT: Tag = Tag("react"); +pub const JSX: Tag = Tag("jsx"); + +pub const ALL_TAGS: Tags = &[RECOMMENDED, FRESH, JSR, REACT, JSX];