Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
add documentation and fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Jun 9, 2022
1 parent 445c4e5 commit 3933738
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/rome_analyze/src/analyzers/use_valid_typeof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ use rome_js_syntax::{
use rome_rowan::{AstNode, AstNodeExt};

use crate::{
registry::{Rule, RuleAction, RuleDiagnostic},
registry::{JsRuleAction, Rule, RuleDiagnostic},
ActionCategory, RuleCategory,
};

/// This rule verifies the result of `typeof $expr` unary expressions is being
/// compared to valid values, either string literals containing valid type
/// names or other `typeof` expressions
pub(crate) enum UseValidTypeof {}

impl Rule for UseValidTypeof {
Expand Down Expand Up @@ -127,7 +130,7 @@ impl Rule for UseValidTypeof {

fn diagnostic(node: &Self::Query, _: &Self::State) -> Option<RuleDiagnostic> {
Some(RuleDiagnostic {
severity: Severity::Error,
severity: Severity::Warning,
message: markup! {
"Invalid typeof comparison value"
}
Expand All @@ -136,7 +139,7 @@ impl Rule for UseValidTypeof {
})
}

fn action(root: JsAnyRoot, _node: &Self::Query, state: &Self::State) -> Option<RuleAction> {
fn action(root: JsAnyRoot, _node: &Self::Query, state: &Self::State) -> Option<JsRuleAction> {
let (expr, type_name) = state.as_ref()?;

let root = root.replace_node(
Expand All @@ -146,7 +149,7 @@ impl Rule for UseValidTypeof {
)),
)?;

Some(RuleAction {
Some(JsRuleAction {
category: ActionCategory::QuickFix,
applicability: Applicability::MaybeIncorrect,
message: markup! { "Compare the result of `typeof` with a valid type name" }.to_owned(),
Expand Down

0 comments on commit 3933738

Please sign in to comment.