Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix clippy warnings in tests #1438

Merged
merged 1 commit into from
Apr 25, 2024
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
10 changes: 4 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"rust-analyzer.check.overrideCommand": [
"cargo",
"clippy",
"--workspace",
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.workspace": true,
"rust-analyzer.check.extraArgs": [
"--exclude=clarinet-sdk-wasm",
"--exclude=clarity-jupyter-kernel",
"--message-format=json"
"--exclude=clarity-jupyter-kernel"
]
}
11 changes: 3 additions & 8 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,16 +1858,11 @@ mod tests {
let mut cmd = Opts::command();
generate(shell, &mut cmd, "clarinet", &mut output_buffer);
assert!(
output_buffer.len() > 0,
"failed to generate completion for {}",
shell.to_string()
!output_buffer.is_empty(),
"failed to generate completion for {shell}",
);
});
assert!(
result.is_ok(),
"failed to generate completion for {}",
shell.to_string()
);
assert!(result.is_ok(), "failed to generate completion for {shell}",);
}
}
}
5 changes: 2 additions & 3 deletions components/clarinet-deployments/src/deployment_plan_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::collections::BTreeMap;

use clarinet_files::{chainhook_types::StacksNetwork, FileLocation};
use clarity_repl::clarity::{
vm::types::{QualifiedContractIdentifier, StandardPrincipalData},
ClarityName, ClarityVersion, ContractName,
vm::types::QualifiedContractIdentifier, ClarityName, ClarityVersion, ContractName,
};

use crate::types::*;
Expand All @@ -12,7 +11,7 @@ fn get_test_txs() -> (TransactionSpecification, TransactionSpecification) {
let contract_id =
QualifiedContractIdentifier::parse("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.test")
.unwrap();
let tx_sender = StandardPrincipalData::from(contract_id.issuer.clone());
let tx_sender = contract_id.issuer.clone();

let contract_publish_tx =
TransactionSpecification::EmulatedContractPublish(EmulatedContractPublishSpecification {
Expand Down
8 changes: 4 additions & 4 deletions components/clarity-lsp/src/common/requests/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ mod populate_snippet_with_options_tests {
let snippet = data.populate_snippet_with_options(
&ClarityVersion::Clarity2,
&"var-get".to_string(),
&"var-get ${1:var}".to_string(),
"var-get ${1:var}",
);
assert_eq!(snippet, Some("var-get ${1|counter,is-active|}".to_string()));
}
Expand All @@ -914,7 +914,7 @@ mod populate_snippet_with_options_tests {
let snippet = data.populate_snippet_with_options(
&ClarityVersion::Clarity2,
&"map-get?".to_string(),
&"map-get? ${1:map-name} ${2:key-tuple}".to_string(),
"map-get? ${1:map-name} ${2:key-tuple}",
);
assert_eq!(
snippet,
Expand All @@ -928,7 +928,7 @@ mod populate_snippet_with_options_tests {
let snippet = data.populate_snippet_with_options(
&ClarityVersion::Clarity2,
&"ft-mint?".to_string(),
&"ft-mint? ${1:token-name} ${2:amount} ${3:recipient}".to_string(),
"ft-mint? ${1:token-name} ${2:amount} ${3:recipient}",
);
assert_eq!(
snippet,
Expand All @@ -942,7 +942,7 @@ mod populate_snippet_with_options_tests {
let snippet = data.populate_snippet_with_options(
&ClarityVersion::Clarity2,
&"nft-mint?".to_string(),
&"nft-mint? ${1:asset-name} ${2:asset-identifier} ${3:recipient}".to_string(),
"nft-mint? ${1:asset-name} ${2:asset-identifier} ${3:recipient}",
);
assert_eq!(
snippet,
Expand Down
8 changes: 4 additions & 4 deletions components/clarity-lsp/src/common/requests/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ mod definitions_visitor_tests {
clarity_repl::clarity::ast::ASTRules::Typical,
)
.unwrap();
return contract_ast.expressions;
contract_ast.expressions
}

fn get_tokens(sources: &str) -> HashMap<(u32, u32), DefinitionLocation> {
Expand Down Expand Up @@ -669,7 +669,7 @@ mod definitions_visitor_tests {
#[test]
fn find_data_var_definition() {
let tokens = get_tokens(
vec![
[
"(define-data-var var1 int 1)",
"(var-get var1)",
"(var-set var1 2)",
Expand All @@ -693,7 +693,7 @@ mod definitions_visitor_tests {
#[test]
fn find_map_definition() {
let tokens = get_tokens(
vec![
[
"(define-map owners int principal)",
"(map-insert owners 1 tx-sender)",
"(map-get? owners 1)",
Expand Down Expand Up @@ -727,7 +727,7 @@ mod definitions_visitor_tests {
#[test]
fn find_ft_definition() {
let tokens = get_tokens(
vec![
[
"(define-fungible-token ft u1)",
"(ft-mint? ft u1 tx-sender)",
"(ft-burn? ft u1 tx-sender)",
Expand Down
48 changes: 24 additions & 24 deletions components/clarity-lsp/src/common/requests/document_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ mod tests {
// ranges are painful to test and just reflects the `span`s
// of the ast, it can be safe to not test it
fn to_partial(symbol: &DocumentSymbol) -> PartialDocumentSymbol {
let children = match &symbol.children {
Some(children) => Some(children.iter().map(|child| to_partial(child)).collect()),
None => None,
};
let children = symbol
.children
.as_ref()
.map(|children| children.iter().map(to_partial).collect());
PartialDocumentSymbol {
name: symbol.name.to_string(),
detail: symbol.detail.clone(),
Expand All @@ -553,7 +553,7 @@ mod tests {
)
.unwrap();

return contract_ast.expressions;
contract_ast.expressions
}

fn get_symbols(source: &str) -> Vec<DocumentSymbol> {
Expand All @@ -568,7 +568,7 @@ mod tests {
assert_eq!(
symbols,
vec![build_symbol(
&"impl-trait".to_owned(),
"impl-trait",
Some("sip-010-trait".to_owned()),
ClaritySymbolKind::IMPL_TRAIT,
&new_span(1, 1, 1, 95),
Expand All @@ -583,7 +583,7 @@ mod tests {
assert_eq!(
symbols,
vec![build_symbol(
&"next-id".to_owned(),
"next-id",
Some("uint".to_owned()),
ClaritySymbolKind::VARIABLE,
&new_span(1, 1, 1, 33),
Expand All @@ -598,7 +598,7 @@ mod tests {
assert_eq!(
symbols,
vec![build_symbol(
&"data".to_owned(),
"data",
Some("list".to_owned()),
ClaritySymbolKind::VARIABLE,
&new_span(1, 1, 1, 46),
Expand All @@ -610,7 +610,7 @@ mod tests {
#[test]
fn test_data_var_tuple() {
let symbols = get_symbols(
vec![
[
"(define-data-var owners",
" { addr: principal, p: int }",
" { addr: contract-caller, p: 1 }",
Expand All @@ -628,7 +628,7 @@ mod tests {
#[test]
fn test_data_var_nested_tuple() {
let symbols = get_symbols(
vec![
[
"(define-data-var names",
" { id: { addr: principal, name: (string-ascii 10) }, qt: int }",
" {",
Expand All @@ -652,7 +652,7 @@ mod tests {
assert_eq!(
symbols,
vec![build_symbol(
&"ERR_PANIC".to_owned(),
"ERR_PANIC",
None,
ClaritySymbolKind::CONSTANT,
&new_span(1, 1, 1, 29),
Expand All @@ -664,7 +664,7 @@ mod tests {
assert_eq!(
symbols,
vec![build_symbol(
&"ERR_PANIC".to_owned(),
"ERR_PANIC",
None,
ClaritySymbolKind::CONSTANT,
&new_span(1, 1, 1, 35),
Expand All @@ -680,18 +680,18 @@ mod tests {
assert_eq!(
to_partial(&symbols[0]),
build_partial_symbol(
&"owners".to_owned(),
"owners",
None,
ClaritySymbolKind::MAP,
Some(vec![
build_partial_symbol(
&"key".to_owned(),
"key",
Some("principal".to_owned()),
ClaritySymbolKind::KEY,
None
),
build_partial_symbol(
&"value".to_owned(),
"value",
Some("tuple".to_owned()),
ClaritySymbolKind::VALUE,
None
Expand All @@ -703,7 +703,7 @@ mod tests {

#[test]
fn test_define_functions() {
let source = vec![
let source = [
"(define-read-only (get-id) (ok u1))",
"(define-public (get-id-again) (ok u1))",
"(define-private (set-id (new-id uint)) (ok u1))",
Expand All @@ -716,7 +716,7 @@ mod tests {
assert_eq!(
symbols[0],
build_symbol(
&"get-id".to_owned(),
"get-id",
Some("read-only".to_owned()),
ClaritySymbolKind::FUNCTION,
&new_span(1, 1, 1, 35),
Expand All @@ -733,7 +733,7 @@ mod tests {
assert_eq!(
symbols[1],
build_symbol(
&"get-id-again".to_owned(),
"get-id-again",
Some("public".to_owned()),
ClaritySymbolKind::FUNCTION,
&new_span(2, 1, 2, 38),
Expand All @@ -750,7 +750,7 @@ mod tests {
assert_eq!(
symbols[2],
build_symbol(
&"set-id".to_owned(),
"set-id",
Some("private".to_owned()),
ClaritySymbolKind::FUNCTION,
&new_span(3, 1, 3, 47),
Expand Down Expand Up @@ -791,7 +791,7 @@ mod tests {
#[test]
fn test_let() {
let symbols = get_symbols(
vec![
[
"(define-public (with-let)",
" (let ((id u1))",
" (ok id)))",
Expand Down Expand Up @@ -841,7 +841,7 @@ mod tests {
#[test]
fn test_define_trait() {
let symbols = get_symbols(
vec![
[
"(define-trait my-trait (",
" (get-id () (response uint uint))",
" (set-id () (response bool uint))",
Expand All @@ -853,18 +853,18 @@ mod tests {
assert_eq!(
to_partial(&symbols[0]),
build_partial_symbol(
&"my-trait".to_owned(),
"my-trait",
None,
ClaritySymbolKind::TRAIT,
Some(vec![
build_partial_symbol(
&"get-id".to_owned(),
"get-id",
Some("trait method".to_owned()),
ClaritySymbolKind::FUNCTION,
None
),
build_partial_symbol(
&"set-id".to_owned(),
"set-id",
Some("trait method".to_owned()),
ClaritySymbolKind::FUNCTION,
None
Expand Down
6 changes: 3 additions & 3 deletions components/clarity-lsp/src/common/requests/signature_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod definitions_visitor_tests {
position: &Position,
) -> Option<Vec<lsp_types::SignatureInformation>> {
let contract = &ActiveContractData::new(Clarity2, Epoch21, None, source);
get_signatures(&contract, position)
get_signatures(contract, position)
}

#[test]
Expand All @@ -115,7 +115,7 @@ mod definitions_visitor_tests {
let signatures = signatures.unwrap();
assert_eq!(signatures.len(), 1);
assert_eq!(
signatures.get(0).unwrap(),
signatures.first().unwrap(),
&SignatureInformation {
label: "(var-set var-name expr1) -> bool".to_string(),
documentation: None,
Expand Down Expand Up @@ -149,7 +149,7 @@ mod definitions_visitor_tests {
"begin",
"tuple",
]
.contains(&method)
.contains(method)
{
continue;
}
Expand Down
Loading
Loading