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

Commit

Permalink
More clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 15, 2022
1 parent d8d2121 commit eb5aea6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions crates/rome_formatter/src/comments/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,13 @@ impl<'a> SourceParentheses<'a> {
/// Must be called with offsets in increasing order.
///
/// Returns the source range of the `)` if there's any `)` in the deleted range at this offset. Returns `None` otherwise

fn r_paren_source_range(&mut self, offset: TextSize) -> Option<TextRange> {
match self {
SourceParentheses::Empty => None,
SourceParentheses::SourceMap { next, tail, .. } => {
while let Some(range) = next {
#[allow(clippy::comparison_chain)]
if range.transformed == offset {
// A deleted range can contain multiple tokens. See if there's any `)` in the deleted
// range and compute its source range.
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/comments/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<K: std::hash::Hash + Eq, V> CommentsMap<K, V> {
#[cold]
fn entry_to_out_of_order<'a>(
entry: &'a mut Entry,
values: &Vec<V>,
values: &[V],
out_of_order: &mut Vec<Vec<V>>,
) -> &'a mut OutOfOrderEntry
where
Expand Down
30 changes: 20 additions & 10 deletions crates/rome_formatter/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,12 @@ pub struct FormatSkippedTokenTrivia<'a, L: Language> {
token: &'a SyntaxToken<L>,
}

impl<Context> Format<Context> for FormatSkippedTokenTrivia<'_, Context::Language>
where
Context: CstFormatContext,
{
fn fmt(&self, f: &mut Formatter<Context>) -> FormatResult<()> {
if !f.comments().has_skipped(self.token) {
return Ok(());
}

impl<L: Language> FormatSkippedTokenTrivia<'_, L> {
#[cold]
fn fmt_skipped<Context>(&self, f: &mut Formatter<Context>) -> FormatResult<()>
where
Context: CstFormatContext<Language = L>,
{
// Lines/spaces before the next token/comment
let (mut lines, mut spaces) = match self.token.prev_token() {
Some(token) => {
Expand Down Expand Up @@ -488,7 +485,7 @@ where
}

let skipped_range =
skipped_range.unwrap_or(TextRange::empty(self.token.text_range().start()));
skipped_range.unwrap_or_else(|| TextRange::empty(self.token.text_range().start()));

let verbatim = {
let mut buffer = VecBuffer::new(f.state_mut());
Expand Down Expand Up @@ -534,3 +531,16 @@ where
}
}
}

impl<Context> Format<Context> for FormatSkippedTokenTrivia<'_, Context::Language>
where
Context: CstFormatContext,
{
fn fmt(&self, f: &mut Formatter<Context>) -> FormatResult<()> {
if f.comments().has_skipped(self.token) {
self.fmt_skipped(f)
} else {
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Format<JsFormatContext> for FormatVerbatimNode<'_> {
.map(|trivia| source_range(f, trivia.text_range()).start())
.take_while(|start| *start < trimmed_source_range.start())
.next()
.unwrap_or(trimmed_source_range.start());
.unwrap_or_else(|| trimmed_source_range.start());

let original_source = f.context().source_map().map_or_else(
|| self.node.text_trimmed().to_string(),
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ fn handle_continue_break_comment(
///
/// ```javascript
/// switch (x) {
/// default: // comment
/// default: // comment
/// {
/// break;
/// break;
/// }
/// ```
///
Expand Down
2 changes: 2 additions & 0 deletions crates/rome_service/src/workspace_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn instance_type<'a>(
if let Some(description) = description {
let comment = format!("/**\n\t* {} \n\t */", description);
let trivia = vec![
(TriviaPieceKind::Newline, "\n"),
(TriviaPieceKind::MultiLineComment, comment.as_str()),
(TriviaPieceKind::Newline, "\n"),
];
Expand Down Expand Up @@ -326,6 +327,7 @@ pub fn generate_type<'a>(
if let Some(description) = description {
let comment = format!("/**\n\t* {} \n\t */", description);
let trivia = vec![
(TriviaPieceKind::Newline, "\n"),
(TriviaPieceKind::MultiLineComment, comment.as_str()),
(TriviaPieceKind::Newline, "\n"),
];
Expand Down
1 change: 1 addition & 0 deletions xtask/codegen/src/generate_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub(crate) fn generate_workspace_bindings(mode: Mode) -> Result<()> {
if let Some(description) = description {
let comment = format!("/**\n\t* {} \n\t */\n", description);
let trivia = vec![
(TriviaPieceKind::Newline, "\n"),
(TriviaPieceKind::MultiLineComment, comment.as_str()),
(TriviaPieceKind::Newline, "\n"),
];
Expand Down

0 comments on commit eb5aea6

Please sign in to comment.