Merge pull request #1413 from gitbutlerapp/cargo-cranky-fix-bin-and-lib

fix bin/lib and use cargo cranky instead of clippy
This commit is contained in:
Nikita Galaiko 2023-10-19 08:18:31 +02:00 committed by GitHub
commit e3d8b850b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 173 additions and 154 deletions

View File

@ -79,7 +79,8 @@ jobs:
- uses: ./.github/actions/init-env-rust
- uses: ./.github/actions/init-env-node
- run: pnpm build
- run: cargo clippy --all-features --tests
- run: cargo install cargo-cranky
- run: cargo cranky --all-targets --all-features
- run: cargo test --locked
udeps:

82
Cranky.toml Normal file
View File

@ -0,0 +1,82 @@
# https://github.com/ericseppanen/cargo-cranky
# cargo install cargo-cranky && cargo cranky
deny = [
"clippy::all",
"clippy::perf",
"clippy::correctness",
"clippy::complexity",
"clippy::style",
"clippy::pedantic",
# selection from clippy::restriction (see https://rust-lang.github.io/rust-clippy/master/index.html#/?groups=restriction)
"clippy::as_underscore",
"clippy::assertions_on_result_states",
"clippy::clone_on_ref_ptr",
"clippy::create_dir",
"clippy::dbg_macro",
"clippy::decimal_literal_representation",
"clippy::default_numeric_fallback",
"clippy::empty_drop",
"clippy::empty_structs_with_brackets",
"clippy::exit",
"clippy::filetype_is_file",
"clippy::float_cmp_const",
"clippy::fn_to_numeric_cast_any",
"clippy::format_push_string",
"clippy::get_unwrap",
"clippy::integer_division",
"clippy::lossy_float_literal",
"clippy::mem_forget",
"clippy::mixed_read_write_in_expression",
"clippy::mutex_atomic",
"clippy::needless_raw_strings",
"clippy::non_ascii_literal",
"clippy::panic",
"clippy::print_stderr",
"clippy::pub_without_shorthand",
"clippy::rc_buffer",
"clippy::rc_mutex",
"clippy::redundant_type_annotations",
"clippy::ref_patterns",
"clippy::rest_pat_in_fully_bound_structs",
"clippy::same_name_method",
"clippy::string_add",
"clippy::string_lit_chars_any",
"clippy::string_slice",
"clippy::string_to_string",
"clippy::suspicious_xor_used_as_pow",
"clippy::todo",
"clippy::try_err",
"clippy::unimplemented",
"clippy::unnecessary_self_imports",
"clippy::unneeded_field_pattern",
"clippy::unseparated_literal_suffix",
#TODO:
#clippy::if_then_some_else_none
#clippy::partial_pub_fields
#clippy::print_stdout
#clippy::unwrap_in_result
#clippy::unwrap_used
#clippy::use_debug
]
allow = [
# reason = "noise and or false-positives"
"clippy::missing_errors_doc",
"clippy::used_underscore_binding",
"clippy::must_use_candidate",
"clippy::module_name_repetitions",
"clippy::missing_panics_doc",
"clippy::too_many_lines",
"clippy::implicit_hasher",
"clippy::if_not_else",
"clippy::return_self_not_must_use",
"clippy::inconsistent_struct_constructor",
"clippy::match_wildcard_for_single_variants",
"clippy::unnested_or_patterns",
#TODO: should probably be cleaned up as any of these could lead to panics or unexpected behaviour (the cast-ones)
"clippy::cast_sign_loss",
"clippy::cast_lossless",
"clippy::match_same_arms",
"clippy::similar_names"
]

View File

@ -1,9 +1,9 @@
use std::path;
use std::path::{self, Path};
use anyhow::{Context, Result};
use git2::Repository;
use gitbutler::{
use gblib::{
database, gb_repository, paths::DataDir, project_repository, projects, sessions, storage, users,
};
@ -18,7 +18,7 @@ pub struct App {
impl App {
pub fn new() -> Result<Self> {
let path = find_git_directory().context("failed to find project directory")?;
let local_data_dir = find_local_data_dir().context("could not find local data dir")?;
let local_data_dir = find_local_data_dir();
let storage = storage::Storage::from(&local_data_dir);
let users_storage = users::Controller::from(&storage);
@ -83,13 +83,13 @@ impl App {
fn find_git_directory() -> Option<path::PathBuf> {
match Repository::discover("./") {
Ok(repo) => repo.workdir().map(|p| p.to_path_buf()),
Ok(repo) => repo.workdir().map(Path::to_path_buf),
Err(_) => None,
}
}
fn find_local_data_dir() -> Option<DataDir> {
fn find_local_data_dir() -> DataDir {
let mut path = dirs::config_dir().unwrap();
path.push("com.gitbutler.app.dev");
Some(path::PathBuf::from(path.to_string_lossy().to_string()).into())
path::PathBuf::from(path.to_string_lossy().to_string()).into()
}

View File

@ -43,7 +43,7 @@ impl Cli {
};
match output {
Ok(_) => ExitCode::SUCCESS,
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("{}: {:#}", "error".red(), e);
ExitCode::FAILURE

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use colored::Colorize;
use gitbutler::virtual_branches;
use gblib::virtual_branches;
use crate::app::App;
#[derive(Debug, Args)]
pub struct Branches {}
pub struct Branches;
impl super::RunCommand for Branches {
fn run(self) -> Result<()> {

View File

@ -1,12 +1,12 @@
use anyhow::{Context, Result};
use clap::Args;
use gitbutler::{sessions, virtual_branches};
use gblib::{sessions, virtual_branches};
use crate::app::App;
#[derive(Debug, Args)]
pub struct Clear {}
pub struct Clear;
impl super::RunCommand for Clear {
fn run(self) -> Result<()> {

View File

@ -3,7 +3,7 @@ use clap::Args;
use colored::Colorize;
use dialoguer::{console::Term, theme::ColorfulTheme, Input, Select};
use gitbutler::{
use gblib::{
reader, sessions,
virtual_branches::{self, BranchId},
};
@ -11,7 +11,7 @@ use gitbutler::{
use crate::app::App;
#[derive(Debug, Args)]
pub struct Commit {}
pub struct Commit;
impl super::RunCommand for Commit {
fn run(self) -> Result<()> {

View File

@ -4,7 +4,7 @@ use clap::Args;
use crate::app::App;
#[derive(Debug, Args)]
pub struct Flush {}
pub struct Flush;
impl super::RunCommand for Flush {
fn run(self) -> Result<()> {

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use colored::Colorize;
use gitbutler::{reader, sessions, virtual_branches};
use gblib::{reader, sessions, virtual_branches};
use crate::app::App;
#[derive(Debug, Args)]
pub struct Info {}
pub struct Info;
impl super::RunCommand for Info {
fn run(self) -> Result<()> {

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use dialoguer::{console::Term, theme::ColorfulTheme, MultiSelect, Select};
use gitbutler::{reader, sessions, virtual_branches};
use gblib::{reader, sessions, virtual_branches};
use crate::app::App;
#[derive(Debug, Args)]
pub struct Move {}
pub struct Move;
impl super::RunCommand for Move {
fn run(self) -> Result<()> {

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use dialoguer::{theme::ColorfulTheme, Input};
use gitbutler::virtual_branches;
use gblib::virtual_branches;
use crate::app::App;
#[derive(Debug, Args)]
pub struct New {}
pub struct New;
impl super::RunCommand for New {
fn run(self) -> Result<()> {

View File

@ -1,12 +1,12 @@
use anyhow::{Context, Result};
use clap::Args;
use gitbutler::virtual_branches;
use gblib::virtual_branches;
use crate::app::App;
#[derive(Debug, Args)]
pub struct Remotes {}
pub struct Remotes;
impl super::RunCommand for Remotes {
fn run(self) -> Result<()> {

View File

@ -1,12 +1,12 @@
use anyhow::{Context, Result};
use clap::Args;
use gitbutler::{reader, sessions, virtual_branches};
use gblib::{reader, sessions, virtual_branches};
use crate::app::App;
#[derive(Debug, Args)]
pub struct Reset {}
pub struct Reset;
impl super::RunCommand for Reset {
fn run(self) -> Result<()> {

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use colored::Colorize;
use dialoguer::{console::Term, theme::ColorfulTheme, Select};
use gitbutler::virtual_branches::set_base_branch;
use gblib::virtual_branches::set_base_branch;
use crate::app::App;
#[derive(Debug, Args)]
pub struct Setup {}
pub struct Setup;
impl super::RunCommand for Setup {
fn run(self) -> Result<()> {

View File

@ -2,12 +2,12 @@ use anyhow::{Context, Result};
use clap::Args;
use colored::Colorize;
use gitbutler::virtual_branches;
use gblib::virtual_branches;
use crate::app::App;
#[derive(Debug, Args)]
pub struct Status {}
pub struct Status;
impl super::RunCommand for Status {
fn run(self) -> Result<()> {

View File

@ -1,3 +1,5 @@
#![allow(clippy::print_stderr, clippy::panic)]
use std::process::ExitCode;
use clap::Parser;

View File

@ -4,6 +4,14 @@ version = "0.0.0"
edition = "2021"
rust-version = "1.57"
[lib]
name = "gblib"
path = "src/lib.rs"
[[bin]]
name = "gitbutler"
path = "src/bin.rs"
[build-dependencies]
tauri-build = { version = "1.5", features = [] }

View File

@ -1,3 +1,3 @@
fn main() {
tauri_build::build()
tauri_build::build();
}

View File

@ -1,8 +1,13 @@
#![forbid(unsafe_code)]
use anyhow::Context;
use futures::executor::block_on;
use tauri::{generate_context, Manager};
use gitbutler::{zip, *};
use gblib::{
analytics, app, assets, commands, database, github, keys, logs, projects, search, storage,
users, virtual_branches, watcher, zip,
};
fn main() {
let tauri_context = generate_context!();
@ -45,21 +50,20 @@ fn main() {
tracing::info!("Quitting app");
app_handle.exit(0);
}
"toggle" => match get_window(app_handle) {
Some(window) => {
"toggle" => {
if let Some(window) = get_window(app_handle) {
if window.is_visible().unwrap() {
hide_window(app_handle).expect("Failed to hide window");
} else {
show_window(app_handle).expect("Failed to show window");
}
}
None => {
} else {
create_window(app_handle).expect("Failed to create window");
item_handle
.set_title(format!("Hide {}", app_title))
.unwrap();
}
},
}
_ => {}
}
}
@ -134,7 +138,7 @@ fn main() {
let users_controller = users::Controller::try_from(&app_handle)
.expect("failed to initialize users controller");
if let Some(user) = users_controller.get_user().context("failed to get user")? {
sentry::configure_scope(|scope| scope.set_user(Some(user.clone().into())))
sentry::configure_scope(|scope| scope.set_user(Some(user.clone().into())));
}
app_handle.manage(users_controller);

View File

@ -1,87 +1,4 @@
#![forbid(unsafe_code, dead_code)]
#![deny(
clippy::all,
clippy::perf,
clippy::correctness,
clippy::complexity,
clippy::style,
clippy::pedantic
)]
// clippy::restriction (see https://rust-lang.github.io/rust-clippy/master/index.html#/?groups=restriction)
// it is recommended to enable individually based on style and requirements
#![deny(
clippy::as_underscore,
clippy::assertions_on_result_states,
clippy::clone_on_ref_ptr,
clippy::create_dir,
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::default_numeric_fallback,
clippy::empty_drop,
clippy::empty_structs_with_brackets,
clippy::exit,
clippy::filetype_is_file,
clippy::float_cmp_const,
clippy::fn_to_numeric_cast_any,
clippy::format_push_string,
clippy::get_unwrap,
clippy::integer_division,
clippy::lossy_float_literal,
clippy::mem_forget,
clippy::mixed_read_write_in_expression,
clippy::mutex_atomic,
clippy::needless_raw_strings,
clippy::non_ascii_literal,
clippy::panic,
clippy::print_stderr,
clippy::pub_without_shorthand,
clippy::rc_buffer,
clippy::rc_mutex,
clippy::redundant_type_annotations,
clippy::ref_patterns,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_name_method,
clippy::string_add,
clippy::string_lit_chars_any,
clippy::string_slice,
clippy::string_to_string,
clippy::suspicious_xor_used_as_pow,
clippy::todo,
clippy::try_err,
clippy::unimplemented,
clippy::unnecessary_self_imports,
clippy::unneeded_field_pattern,
clippy::unseparated_literal_suffix,
//TODO:
// clippy::if_then_some_else_none
// clippy::partial_pub_fields
// clippy::print_stdout
// clippy::unwrap_in_result
// clippy::unwrap_used
// clippy::use_debug
)]
// reason = "noise and or false-positives"
#![allow(
clippy::missing_errors_doc,
clippy::used_underscore_binding,
clippy::must_use_candidate,
clippy::module_name_repetitions,
clippy::missing_panics_doc,
clippy::too_many_lines,
clippy::implicit_hasher,
clippy::if_not_else,
clippy::return_self_not_must_use,
clippy::inconsistent_struct_constructor,
clippy::match_wildcard_for_single_variants,
clippy::unnested_or_patterns
)]
//TODO: should probably be cleaned up as any of these could lead to panics or unexpected behaviour (the cast-ones)
#![allow(
clippy::cast_sign_loss,
clippy::cast_lossless,
clippy::match_same_arms,
clippy::similar_names
)]
pub mod analytics;
pub mod app;

View File

@ -1,4 +1,4 @@
use gitbutler::git;
use gblib::git;
pub fn temp_dir() -> std::path::PathBuf {
tempfile::tempdir()

View File

@ -1,3 +1,5 @@
#![allow(clippy::dbg_macro)]
mod common;
mod paths;
mod projects;

View File

@ -1,4 +1,4 @@
use gitbutler::paths::DataDir;
use gblib::paths::DataDir;
use crate::common::temp_dir;

View File

@ -1,4 +1,4 @@
use gitbutler::projects::Controller;
use gblib::projects::Controller;
use crate::{common, paths};
@ -21,7 +21,7 @@ mod add {
}
mod error {
use gitbutler::projects::AddError;
use gblib::projects::AddError;
use super::*;

View File

@ -1,10 +1,16 @@
//TODO:
#![allow(
clippy::redundant_closure_for_method_calls,
clippy::rest_pat_in_fully_bound_structs
)]
use std::{fs, str::FromStr};
use gitbutler::{
use gblib::{
git, keys,
projects::{self, ProjectId},
users,
virtual_branches::{Controller, ControllerError},
virtual_branches::{branch, Controller, ControllerError},
};
use crate::{common::TestProject, paths};
@ -39,6 +45,7 @@ mod references {
use super::*;
mod create_virtual_branch {
use super::*;
#[tokio::test]
@ -58,7 +65,7 @@ mod references {
.unwrap();
let branch_id = controller
.create_virtual_branch(&project_id, &Default::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
@ -72,7 +79,7 @@ mod references {
.into_iter()
.filter_map(|reference| reference.name().map(|name| name.to_string()))
.collect::<Vec<_>>();
assert!(refnames.contains(&"refs/gitbutler/virtual-branch".to_string()))
assert!(refnames.contains(&"refs/gitbutler/virtual-branch".to_string()));
}
#[tokio::test]
@ -94,7 +101,7 @@ mod references {
let branch1_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&gblib::virtual_branches::branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -105,7 +112,7 @@ mod references {
let branch2_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&gblib::virtual_branches::branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -153,7 +160,7 @@ mod references {
let branch_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -164,7 +171,7 @@ mod references {
controller
.update_virtual_branch(
&project_id,
gitbutler::virtual_branches::branch::BranchUpdateRequest {
branch::BranchUpdateRequest {
id: branch_id,
name: Some("new name".to_string()),
..Default::default()
@ -206,7 +213,7 @@ mod references {
let branch1_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -217,7 +224,7 @@ mod references {
let branch2_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
..Default::default()
},
)
@ -227,7 +234,7 @@ mod references {
controller
.update_virtual_branch(
&project_id,
gitbutler::virtual_branches::branch::BranchUpdateRequest {
branch::BranchUpdateRequest {
id: branch2_id,
name: Some("name".to_string()),
..Default::default()
@ -275,7 +282,7 @@ mod references {
let id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -301,8 +308,6 @@ mod references {
}
mod push_virtual_branch {
use gitbutler::virtual_branches::branch::BranchUpdateRequest;
use super::*;
#[tokio::test]
@ -324,7 +329,7 @@ mod references {
let branch1_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -381,7 +386,7 @@ mod references {
let branch1_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -404,7 +409,7 @@ mod references {
controller
.update_virtual_branch(
&project_id,
BranchUpdateRequest {
branch::BranchUpdateRequest {
id: branch1_id,
name: Some("updated name".to_string()),
..Default::default()
@ -418,7 +423,7 @@ mod references {
let branch2_id = controller
.create_virtual_branch(
&project_id,
&gitbutler::virtual_branches::branch::BranchCreateRequest {
&branch::BranchCreateRequest {
name: Some("name".to_string()),
..Default::default()
},
@ -507,8 +512,6 @@ mod set_base_branch {
}
mod conflicts {
use gitbutler::virtual_branches::branch::BranchCreateRequest;
use super::*;
mod apply_virtual_branch {
@ -531,7 +534,7 @@ mod conflicts {
let branch1_id = {
let branch1_id = controller
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("file.txt"), "branch one").unwrap();
@ -548,7 +551,7 @@ mod conflicts {
{
// create another vbranch that conflicts with the first one
controller
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("file.txt"), "branch two").unwrap();
@ -598,7 +601,7 @@ mod conflicts {
let branch1_id = {
// create a branch with some commited work
let branch1_id = controller
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
@ -721,7 +724,7 @@ mod conflicts {
let branch1_id = {
// make a branch with some work
let branch1_id = controller
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("another_file.txt"), "").unwrap();
@ -824,7 +827,7 @@ mod conflicts {
let branch1_id = {
// make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch1_id = controller
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap();
@ -918,7 +921,7 @@ mod reset {
.unwrap();
let branch1_id = controller
.create_virtual_branch(&project_id, &Default::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
@ -981,7 +984,7 @@ mod reset {
.unwrap();
let branch1_id = controller
.create_virtual_branch(&project_id, &Default::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
@ -1041,7 +1044,7 @@ mod reset {
.unwrap();
let branch1_id = controller
.create_virtual_branch(&project_id, &Default::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();
@ -1127,7 +1130,7 @@ mod reset {
.unwrap();
let branch1_id = controller
.create_virtual_branch(&project_id, &Default::default())
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
.await
.unwrap();

View File

@ -7,7 +7,7 @@ set -o pipefail
function rust() {
cargo fmt --check
cargo sort -c -w
cargo clippy --all-features --tests
cargo cranky --all-targets --all-features
cargo test
}