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

Commit

Permalink
Clippy & Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 15, 2022
1 parent b473491 commit d8d2121
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 59 deletions.
8 changes: 3 additions & 5 deletions crates/rome_formatter/src/comments/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ where
// Using the `enclosing` as default but it's mainly to satisfy Rust. The only case where it is used
// is if someone formats a Parenthesized expression as the root. Something we explicitly disallow
// in rome_js_formatter
let enclosing = preceding.parent().unwrap_or_else(|| enclosing);
let enclosing = preceding.parent().unwrap_or(enclosing);

// Update the lines after of all comments as well as the positioning of end of line comments.
while let Some((index, comment)) = comments.next() {
Expand Down Expand Up @@ -515,7 +515,7 @@ impl<'a> SourceParentheses<'a> {
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.
return range.text.find(")").map(|r_paren_position| {
return range.text.find(')').map(|r_paren_position| {
let start = range.source + TextSize::from(r_paren_position as u32);
TextRange::at(start, TextSize::from(1))
});
Expand Down Expand Up @@ -840,9 +840,7 @@ b;"#;
.collect::<Vec<_>>(),
);

let new_reference_identifier = reference_identifier
.clone()
.with_value_token(new_identifier_token);
let new_reference_identifier = reference_identifier.with_value_token(new_identifier_token);

let new_identifier_expression = identifier_expression.with_name(new_reference_identifier);

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ fn handle_if_statement_comment(
// ```
if !comment.kind().is_block()
&& !comment.position().is_own_line()
&& !comment.preceding_node().is_none()
&& comment.preceding_node().is_some()
{
return CommentPlacement::dangling(consequent, comment);
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rome_js_formatter/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::comments::{FormatJsLeadingComment, JsCommentStyle, JsComments};
use rome_formatter::printer::PrinterOptions;
use rome_formatter::{
CstFormatContext, FormatContext, FormatOptions, IndentStyle, LineWidth,
TransformSourceMap,
CstFormatContext, FormatContext, FormatOptions, IndentStyle, LineWidth, TransformSourceMap,
};
use rome_js_syntax::{JsLanguage, SourceType};
use std::fmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rome_formatter::{write, CstFormatContext, FormatRuleWithOptions, GroupId};

use crate::utils::array::write_array_node;

use rome_js_syntax::{JsArrayElementList};
use rome_js_syntax::JsArrayElementList;
use rome_rowan::{AstNode, AstSeparatedList};

#[derive(Debug, Clone, Default)]
Expand Down
3 changes: 0 additions & 3 deletions crates/rome_js_formatter/src/js/unknown/unknown_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@


use crate::parentheses::NeedsParentheses;
use crate::FormatUnknownNodeRule;
use rome_js_syntax::{JsSyntaxNode, JsUnknownAssignment};


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownAssignment;

Expand Down
3 changes: 0 additions & 3 deletions crates/rome_js_formatter/src/js/unknown/unknown_binding.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownBinding;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownBinding;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownImportAssertionEntry;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownImportAssertionEntry;

Expand Down
3 changes: 0 additions & 3 deletions crates/rome_js_formatter/src/js/unknown/unknown_member.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownMember;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownMember;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownNamedImportSpecifier;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownNamedImportSpecifier;

Expand Down
3 changes: 0 additions & 3 deletions crates/rome_js_formatter/src/js/unknown/unknown_parameter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownParameter;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownParameter;

Expand Down
3 changes: 0 additions & 3 deletions crates/rome_js_formatter/src/js/unknown/unknown_statement.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


use crate::FormatUnknownNodeRule;
use rome_js_syntax::JsUnknownStatement;


#[derive(Debug, Clone, Default)]
pub struct FormatJsUnknownStatement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::prelude::*;

use rome_formatter::{format_args, write, CstFormatContext};
use rome_js_syntax::{
JsAnyExpression, JsxAnyTag, JsxExpressionAttributeValue,
JsxExpressionAttributeValueFields,
JsAnyExpression, JsxAnyTag, JsxExpressionAttributeValue, JsxExpressionAttributeValueFields,
};

#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 1 addition & 3 deletions crates/rome_js_formatter/src/jsx/lists/child_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use crate::utils::jsx::{
JsxRawSpace, JsxSpace,
};
use crate::JsFormatter;
use rome_formatter::{
format_args, write, CstFormatContext, FormatRuleWithOptions, VecBuffer,
};
use rome_formatter::{format_args, write, CstFormatContext, FormatRuleWithOptions, VecBuffer};
use rome_js_syntax::{JsxAnyChild, JsxChildList};

#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_formatter/src/jsx/tag/opening_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::prelude::*;

use rome_formatter::{write, CstFormatContext};
use rome_js_syntax::{
JsSyntaxToken, JsxAnyAttribute, JsxAnyAttributeValue, JsxAnyElementName,
JsxAttributeList, JsxOpeningElement, JsxSelfClosingElement, JsxString, TsTypeArguments,
JsSyntaxToken, JsxAnyAttribute, JsxAnyAttributeValue, JsxAnyElementName, JsxAttributeList,
JsxOpeningElement, JsxSelfClosingElement, JsxString, TsTypeArguments,
};
use rome_rowan::{declare_node_union, SyntaxResult};

Expand Down
37 changes: 15 additions & 22 deletions crates/rome_js_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ mod tests {
use rome_js_syntax::SourceType;
use rome_rowan::{TextRange, TextSize};

use crate::check_reformat::{check_reformat, CheckReformatParams};

#[test]
fn test_range_formatting() {
let input = "
Expand Down Expand Up @@ -814,35 +816,26 @@ function() {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
export {
foooo,
barrr
// rome-ignore format: test
as // comment
a,
} from 'foo'"#;
type C = B & (C | A) & B;
"#;
let syntax = SourceType::tsx();
let tree = parse(src, 0, syntax);
let options = JsFormatOptions::new(syntax);

let formatted = format_node(options, &tree.syntax()).unwrap();
let result = formatted.print();
// check_reformat(CheckReformatParams {
// root: &tree.syntax(),
// text: result.as_code(),
// source_type: syntax,
// file_name: "quick_test",
// options,
// });
let result = format_node(options.clone(), &tree.syntax())
.unwrap()
.print();
check_reformat(CheckReformatParams {
root: &tree.syntax(),
text: result.as_code(),
source_type: syntax,
file_name: "quick_test",
options,
});
assert_eq!(
result.as_code(),
r#"a;
loooooooooooooooooooooooooong7 =
// rome-ignore format: test
! "looooooooooooooooooooooooooooooooooooooooooog";
"#
"type Example = {\n\t[A in B]: T;\n} & {\n\t[A in B]: T;\n};\n"
);
}

Expand Down

0 comments on commit d8d2121

Please sign in to comment.