Skip to content
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ manual_let_else = "deny"
explicit_iter_loop = "deny"
too_many_arguments = "allow"
disallowed_types = "deny"
uninlined_format_args = "deny"

[profile.dev]
debug = 0
Expand Down
16 changes: 5 additions & 11 deletions crates/squawk/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn format_comment(
summary_notice: Option<&str>,
) -> String {
let notice_section = if let Some(notice) = summary_notice {
format!("\n> {}\n", notice)
format!("\n> {notice}\n")
} else {
String::new()
};
Expand All @@ -274,13 +274,7 @@ fn format_comment(
[📚 More info on rules](https://github.com/sbdchd/squawk#rules)

⚡️ Powered by [`Squawk`](https://github.com/sbdchd/squawk) ({version}), a linter for PostgreSQL, focused on migrations
",
violations_emoji = violations_emoji,
violation_count = violation_count,
file_count = file_count,
notice_section = notice_section,
content = content,
version = version
"
)
.trim_matches('\n')
.into()
Expand Down Expand Up @@ -453,7 +447,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
assert_eq!(result, short_sql);

let long_sql = (0..100)
.map(|i| format!("-- Line {}", i))
.map(|i| format!("-- Line {i}"))
.collect::<Vec<_>>()
.join("\n");
let (result, truncated) = crate::github::truncate_sql_if_needed(&long_sql);
Expand All @@ -465,7 +459,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
fn generating_comment_with_large_content() {
// Create a very large SQL content
let large_sql = (0..1000)
.map(|i| format!("SELECT {} as col{};", i, i))
.map(|i| format!("SELECT {i} as col{i};"))
.collect::<Vec<_>>()
.join("\n");

Expand Down Expand Up @@ -500,7 +494,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
fn generating_comment_forced_summary() {
// Create content that will definitely trigger summary mode
let massive_sql = (0..10000)
.map(|i| format!("SELECT {} as col{};", i, i))
.map(|i| format!("SELECT {i} as col{i};"))
.collect::<Vec<_>>()
.join("\n");

Expand Down
17 changes: 4 additions & 13 deletions crates/squawk_fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,11 @@ fn build_type<'a>(ty: ast::Type) -> Doc<'a> {
fn leading_comments_token<'a>(node: &SyntaxToken) -> Doc<'a> {
let mut doc = Doc::nil();
for next in node.siblings_with_tokens(Direction::Prev).skip(1) {
println!("prev");
match next {
rowan::NodeOrToken::Node(node) => {
println!("before node {:?}", node);
rowan::NodeOrToken::Node(_node) => {
break;
}
rowan::NodeOrToken::Token(token) => {
println!("before token {:?}", token);
if token.kind() == SyntaxKind::COMMENT {
doc = doc
.append(Doc::text(token.text().to_string()))
Expand All @@ -478,14 +475,11 @@ fn leading_comments_token<'a>(node: &SyntaxToken) -> Doc<'a> {
fn leading_comments<'a>(node: &SyntaxNode) -> Doc<'a> {
let mut doc = Doc::nil();
for next in node.siblings_with_tokens(Direction::Prev).skip(1) {
println!("prev");
match next {
rowan::NodeOrToken::Node(node) => {
println!("before node {:?}", node);
rowan::NodeOrToken::Node(_node) => {
break;
}
rowan::NodeOrToken::Token(token) => {
println!("before token {:?}", token);
if token.kind() == SyntaxKind::COMMENT {
let is_block = token.text().starts_with("--");
doc = doc
Expand All @@ -509,14 +503,11 @@ fn leading_comments<'a>(node: &SyntaxNode) -> Doc<'a> {
fn trailing_comments<'a>(node: &SyntaxNode) -> Doc<'a> {
let mut doc = Doc::nil();
for next in node.siblings_with_tokens(Direction::Next).skip(1) {
println!("after");
match next {
rowan::NodeOrToken::Node(node) => {
println!("after node {:?}", node);
rowan::NodeOrToken::Node(_node) => {
break;
}
rowan::NodeOrToken::Token(token) => {
println!("after token {:?}", token);
if token.kind() == SyntaxKind::COMMENT {
doc = doc
.append(Doc::space())
Expand Down Expand Up @@ -562,7 +553,7 @@ fn build_target<'a>(target: ast::Target) -> Option<Doc<'a>> {
pub fn fmt(text: &str) -> String {
let parse = ast::SourceFile::parse(text);
let file = parse.tree();
println!("{}", text);
println!("{text}");
println!("---");
println!("{:#?}", file.syntax());
println!("---");
Expand Down
5 changes: 2 additions & 3 deletions crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,11 @@ pub(crate) fn classify_def_node(def_node: &SyntaxNode) -> Option<LocationKind> {
fn special_function() {
for kind in (0..SyntaxKind::__LAST as u16)
.map(SyntaxKind::from)
.filter(|kind| format!("{:?}", kind).ends_with("_FN"))
.filter(|kind| format!("{kind:?}").ends_with("_FN"))
{
assert!(
is_special_fn(kind),
"unhandled special function kind: {:?}. Please update is_special_fn",
kind
"unhandled special function kind: {kind:?}. Please update is_special_fn"
)
}
}
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/code_actions/add_explicit_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn add_explicit_alias(
let expr_end = target.expr().map(|e| e.syntax().text_range().end())?;

let quoted_alias = quote_column_alias(&alias);
let replacement = format!(" as {}", quoted_alias);
let replacement = format!(" as {quoted_alias}");

actions.push(CodeAction {
title: "Add explicit alias".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/code_actions/add_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(super) fn add_schema(
.search_path_at(token_start)
.first()?
.to_string();
let replacement = format!("{}.", schema);
let replacement = format!("{schema}.");

actions.push(CodeAction {
title: "Add schema".to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn rewrite_as_dollar_quoted_string(
fn string_to_dollar_quoted(text: &str) -> Option<String> {
let normalized = normalize_single_quoted_string(text)?;
let delimiter = dollar_delimiter(&normalized)?;
let boundary = format!("${}$", delimiter);
let boundary = format!("${delimiter}$");
Some(format!("{boundary}{normalized}{boundary}"))
}

Expand All @@ -53,7 +53,7 @@ fn dollar_delimiter(content: &str) -> Option<String> {
let mut delim = "q".to_owned();
// don't want to just loop forever
for idx in 0..10 {
if !content.contains(&format!("${}$", delim)) {
if !content.contains(&format!("${delim}$")) {
return Some(delim);
}
delim.push_str(&idx.to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ pub(super) fn rewrite_as_regular_string(
fn dollar_quoted_to_string(text: &str) -> Option<String> {
debug_assert!(text.starts_with('$'));
let (delimiter, content) = split_dollar_quoted(text)?;
let boundary = format!("${}$", delimiter);
let boundary = format!("${delimiter}$");

if !text.starts_with(&boundary) || !text.ends_with(&boundary) {
return None;
}

// quotes are escaped by using two of them in Postgres
let escaped = content.replace('\'', "''");
Some(format!("'{}'", escaped))
Some(format!("'{escaped}'"))
}

fn split_dollar_quoted(text: &str) -> Option<(String, &str)> {
debug_assert!(text.starts_with('$'));
let second_dollar = text[1..].find('$')?;
// the `foo` in `select $foo$bar$foo$`
let delimiter = &text[1..=second_dollar];
let boundary = format!("${}$", delimiter);
let boundary = format!("${delimiter}$");

if !text.ends_with(&boundary) {
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn rewrite_cast_to_double_colon(
let expr_text = expr.syntax().text();
let type_text = ty.syntax().text();

let replacement = format!("{}::{}", expr_text, type_text);
let replacement = format!("{expr_text}::{type_text}");

actions.push(CodeAction {
title: "Rewrite as cast operator `::`".to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn rewrite_double_colon_to_cast(
let expr_text = expr.syntax().text();
let type_text = ty.syntax().text();

let replacement = format!("cast({} as {})", expr_text, type_text);
let replacement = format!("cast({expr_text} as {type_text})");

actions.push(CodeAction {
title: "Rewrite as cast function `cast()`".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/code_actions/rewrite_leading_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(super) fn rewrite_leading_from(
edits: vec![
Edit::delete(select_with_ws),
Edit::insert(
format!("{} ", select_text),
format!("{select_text} "),
from_clause.syntax().text_range().start(),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(super) fn rewrite_values_as_select(
if row_targets.is_empty() {
return None;
}
select_parts.push(format!("union all\nselect {}", row_targets));
select_parts.push(format!("union all\nselect {row_targets}"));
}

let mut select_stmt = select_parts.join("\n");
Expand Down
5 changes: 1 addition & 4 deletions crates/squawk_ide/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,7 @@ fn function_detail(
let ret_type = create_function.ret_type()?;
let return_type = ret_type.syntax().text().to_string();

Some(format!(
"{}.{}{} {}",
schema, function_name, params, return_type
))
Some(format!("{schema}.{function_name}{params} {return_type}"))
}

fn default_completions() -> Vec<CompletionItem> {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/expand_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ $0
let unhandled_list_kinds = (0..SyntaxKind::__LAST as u16)
.map(SyntaxKind::from)
.filter(|kind| {
format!("{:?}", kind).ends_with("_LIST") && !delimited_ws_list_kinds.contains(kind)
format!("{kind:?}").ends_with("_LIST") && !delimited_ws_list_kinds.contains(kind)
})
.filter(|kind| !DELIMITED_LIST_KINDS.contains(kind))
.collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/find_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod test {
snippet = snippet.annotation(
AnnotationKind::Context
.span(range.into())
.label(format!("{}. reference", label_index)),
.label(format!("{label_index}. reference")),
);
}
snippet
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/folding_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ values
fn list_variants() {
let unhandled_list_kinds: Vec<SyntaxKind> = (0..SyntaxKind::__LAST as u16)
.map(SyntaxKind::from)
.filter(|kind| format!("{:?}", kind).ends_with("_LIST"))
.filter(|kind| format!("{kind:?}").ends_with("_LIST"))
.filter(|kind| fold_kind(*kind).is_none())
.collect();

Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod test {
snippet = snippet.annotation(
AnnotationKind::Context
.span(range.into())
.label(format!("{}. destination", label_index)),
.label(format!("{label_index}. destination")),
);
}

Expand Down
Loading
Loading