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

fix(rome_js_analyze): noNonoctalDecimalEscape returns single diagnostic #4663

Merged
merged 3 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rome_diagnostics::Applicability;
use rome_js_factory::make;
use rome_js_syntax::JsStringLiteralExpression;
use rome_rowan::{AstNode, BatchMutationExt, TextRange};
use std::ops::Range;
use std::{collections::HashSet, ops::Range};

declare_rule! {
/// Disallow `\8` and `\9` escape sequences in string literals.
Expand Down Expand Up @@ -41,10 +41,6 @@ declare_rule! {
/// const x = "Don't use \9 escape.";
/// ```
///
/// ```js,expect_diagnostic
/// const x = "\0\8";
/// ```
///
/// ## Valid
///
/// ```js
Expand All @@ -55,10 +51,6 @@ declare_rule! {
/// const x = "Don't use \\8 and \\9 escapes.";
/// ```
///
/// ```js
/// const x = "\0\u0038";;
/// ```
///
pub(crate) NoNonoctalDecimalEscape {
version: "next",
name: "noNonoctalDecimalEscape",
Expand All @@ -69,7 +61,6 @@ declare_rule! {
#[derive(Debug)]
pub(crate) enum FixSuggestionKind {
Refactor,
EscapeBackslash,
}

#[derive(Debug)]
Expand Down Expand Up @@ -157,15 +148,10 @@ impl Rule for NoNonoctalDecimalEscape {
})
}
}
// \8 -> \\8
signals.push(RuleState {
kind: FixSuggestionKind::EscapeBackslash,
diagnostics_text_range: decimal_escape_range,
replace_to: format!("\\{}", decimal_escape),
replace_from: decimal_escape.to_string(),
replace_string_range,
});
}

let mut seen = HashSet::new();
signals.retain(|rule_state| seen.insert(rule_state.diagnostics_text_range));
Comment on lines +153 to +154
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it removes duplicates from the signals by diaagnositcs_text_range used for diagnostics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be more efficient way

signals
}

Expand Down Expand Up @@ -219,9 +205,6 @@ impl Rule for NoNonoctalDecimalEscape {
FixSuggestionKind::Refactor => {
markup! ("Replace "<Emphasis>{replace_from}</Emphasis>" with "<Emphasis>{replace_to}</Emphasis>". This maintains the current functionality.").to_owned()
}
FixSuggestionKind::EscapeBackslash => {
markup! ("Replace "<Emphasis>{replace_from}</Emphasis>" with "<Emphasis>{replace_to}</Emphasis>" to include the actual backslash character." ).to_owned()
}
},
mutation,
})
Expand Down
Loading