Skip to content

fix: clean cargo check and cargo clippy #277

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 6 commits into from
Mar 30, 2025
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: 0 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ concurrency:
cancel-in-progress: true

env:
RUSTFLAGS: -A dead_code
RUST_LOG: info
RUST_BACKTRACE: 1
RUSTUP_WINDOWS_PATH_ADD_BIN: 1
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ permissions:
contents: write

env:
# Ultimately, we shouldn't ignore warnings.
# We need to pass it as an ENV because inlining doesn't work on Windows.
RUSTFLAGS: -A dead_code
# Need these guys for cross-compilation
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
Expand Down
4 changes: 0 additions & 4 deletions crates/pgt_analyse/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ impl RuleDiagnostic {
self.footer(LogCategory::Warn, msg)
}

pub(crate) fn span(&self) -> Option<TextRange> {
self.span
}

pub fn advices(&self) -> &RuleAdvice {
&self.rule_advice
}
Expand Down
4 changes: 0 additions & 4 deletions crates/pgt_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ impl CommandRunner for CheckCommandPayload {
self.stdin_file_path.as_deref()
}

fn should_write(&self) -> bool {
false
}

fn get_execution(
&self,
cli_options: &CliOptions,
Expand Down
29 changes: 1 addition & 28 deletions crates/pgt_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use pgt_console::{ConsoleExt, markup};
use pgt_lsp::ServerFactory;
use pgt_workspace::{TransportError, WorkspaceError, workspace::WorkspaceClient};
use std::{env, fs, path::PathBuf};
use std::{env, path::PathBuf};
use tokio::io;
use tokio::runtime::Runtime;
use tracing::subscriber::Interest;
Expand Down Expand Up @@ -175,33 +175,6 @@ async fn start_lsp_proxy(
}
}

pub(crate) fn read_most_recent_log_file(
log_path: Option<PathBuf>,
log_file_name_prefix: String,
) -> io::Result<Option<String>> {
let pgt_log_path = log_path.unwrap_or(default_pgt_log_path());

let most_recent = fs::read_dir(pgt_log_path)?
.flatten()
.filter(|file| file.file_type().is_ok_and(|ty| ty.is_file()))
.filter_map(|file| {
match file
.file_name()
.to_str()?
.split_once(log_file_name_prefix.as_str())
{
Some((_, date_part)) if date_part.split('-').count() == 4 => Some(file.path()),
_ => None,
}
})
.max();

match most_recent {
Some(file) => Ok(Some(fs::read_to_string(file)?)),
None => Ok(None),
}
}

/// Set up the [tracing]-based logging system for the server
/// The events received by the subscriber are filtered at the `info` level,
/// then printed using the [HierarchicalLayer] layer, and the resulting text
Expand Down
10 changes: 1 addition & 9 deletions crates/pgt_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use pgt_workspace::workspace::UpdateSettingsParams;
use pgt_workspace::{DynRef, Workspace, WorkspaceError};
use std::ffi::OsString;
use std::path::PathBuf;

pub(crate) mod check;
pub(crate) mod clean;
pub(crate) mod daemon;
Expand All @@ -24,6 +23,7 @@ pub(crate) mod version;

#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version(VERSION))]
#[allow(clippy::large_enum_variant)]
/// Postgres Tools official CLI. Use it to check the health of your project or run it to check single files.
pub enum PgtCommand {
/// Shows the version information and quit.
Expand Down Expand Up @@ -338,9 +338,6 @@ pub(crate) trait CommandRunner: Sized {
/// It returns the file path to use in `stdin` mode.
fn get_stdin_file_path(&self) -> Option<&str>;

/// Whether the command should write the files.
fn should_write(&self) -> bool;

/// Returns the [Execution] mode.
fn get_execution(
&self,
Expand All @@ -357,11 +354,6 @@ pub(crate) trait CommandRunner: Sized {
fn check_incompatible_arguments(&self) -> Result<(), CliDiagnostic> {
Ok(())
}

/// Checks whether the configuration has errors.
fn should_validate_configuration_diagnostics(&self) -> bool {
true
}
}

fn get_files_to_process_with_cli_options(
Expand Down
20 changes: 0 additions & 20 deletions crates/pgt_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use pgt_console::fmt::Display;
use pgt_console::markup;
use pgt_diagnostics::adapters::{BpafError, IoError, SerdeJsonError};
use pgt_diagnostics::{
Expand Down Expand Up @@ -231,25 +230,6 @@ pub struct IncompatibleEndConfiguration {
)]
pub struct NoFilesWereProcessed;

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
severity = Warning,
tags(DEPRECATED_CODE)
)]
pub struct DeprecatedArgument {
#[message]
pub message: MessageAndDescription,
}

impl DeprecatedArgument {
pub fn new(message: impl Display) -> Self {
Self {
message: MessageAndDescription::from(markup! {{message}}.to_owned()),
}
}
}

#[derive(Debug, Diagnostic)]
pub enum ReportDiagnostic {
/// Emitted when trying to serialise the report
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_cli/src/execute/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) trait ResultExt {
code: &'static Category,
) -> Result<Self::Result, Error>;

#[allow(unused)]
fn with_file_path_and_code_and_tags(
self,
file_path: String,
Expand Down
27 changes: 4 additions & 23 deletions crates/pgt_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use crate::reporter::junit::{JunitReporter, JunitReporterVisitor};
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
use crate::{CliDiagnostic, CliSession, DiagnosticsPayload, Reporter};
use pgt_diagnostics::{Category, category};
use pgt_fs::PgTPath;
use std::borrow::Borrow;
use std::ffi::OsString;
use std::fmt::{Display, Formatter};
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use tracing::info;

/// Useful information during the traversal of files and virtual content
Expand All @@ -37,25 +36,17 @@ impl Execution {
}
}

#[derive(Debug, Clone, Copy)]
pub enum ExecutionEnvironment {
GitHub,
}

/// A type that holds the information to execute the CLI via `stdin
#[derive(Debug, Clone)]
pub struct Stdin(
#[allow(unused)]
/// The virtual path to the file
PathBuf,
/// The content of the file
String,
);

impl Stdin {
fn as_path(&self) -> &Path {
self.0.as_path()
}

fn as_content(&self) -> &str {
self.1.as_str()
}
Expand Down Expand Up @@ -170,10 +161,6 @@ impl Execution {
}
}

pub(crate) const fn is_dummy(&self) -> bool {
matches!(self.traversal_mode, TraversalMode::Dummy)
}

/// Whether the traversal mode requires write access to files
pub(crate) const fn requires_write_access(&self) -> bool {
match self.traversal_mode {
Expand Down Expand Up @@ -202,6 +189,7 @@ impl Execution {
false
}

#[allow(unused)]
/// Returns [true] if the user used the `--write`/`--fix` option
pub(crate) fn is_write(&self) -> bool {
match self.traversal_mode {
Expand Down Expand Up @@ -232,14 +220,7 @@ pub fn execute_mode(

// don't do any traversal if there's some content coming from stdin
if let Some(stdin) = execution.as_stdin_file() {
let pgt_path = PgTPath::new(stdin.as_path());
std_in::run(
session,
&execution,
pgt_path,
stdin.as_content(),
cli_options.verbose,
)
std_in::run(session, stdin.as_content())
} else {
let TraverseResult {
summary,
Expand Down
30 changes: 11 additions & 19 deletions crates/pgt_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@ pub(crate) enum FileStatus {
Changed,
/// File unchanged, and it was a success
Unchanged,

/// While handling the file, something happened
#[allow(unused)]
Message(Message),

/// A match was found while searching a file
#[allow(unused)]
SearchResult(usize, Message),

/// File ignored, it should not be count as "handled"
#[allow(unused)]
Ignored,

/// Files that belong to other tools and shouldn't be touched
#[allow(unused)]
Protected(String),
}

impl FileStatus {
pub const fn is_changed(&self) -> bool {
matches!(self, Self::Changed)
}
}

/// Wrapper type for messages that can be printed during the traversal process
#[derive(Debug)]
pub(crate) enum Message {
#[allow(unused)]
SkippedFixes {
/// Suggested fixes skipped during the lint traversal
skipped_suggested_fixes: u32,
},

#[allow(unused)]
Failure,
Error(Error),
Diagnostics {
Expand All @@ -48,19 +53,6 @@ pub(crate) enum Message {
},
}

impl Message {
pub(crate) const fn is_failure(&self) -> bool {
matches!(self, Message::Failure)
}
}

#[derive(Debug)]
pub(crate) enum DiffKind {
Format,
OrganizeImports,
Assists,
}

impl<D> From<D> for Message
where
Error: From<D>,
Expand Down
6 changes: 1 addition & 5 deletions crates/pgt_cli/src/execute/process_file/workspace_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use pgt_diagnostics::{Error, category};
use pgt_fs::{File, OpenOptions, PgTPath};
use pgt_workspace::workspace::{ChangeParams, FileGuard, OpenFileParams};
use pgt_workspace::{Workspace, WorkspaceError};
use std::ffi::OsStr;
use std::path::{Path, PathBuf};

/// Small wrapper that holds information and operations around the current processed file
Expand Down Expand Up @@ -59,11 +58,8 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
self.guard().get_file_content()
}

pub(crate) fn as_extension(&self) -> Option<&OsStr> {
self.path.extension()
}

/// It updates the workspace file with `new_content`
#[allow(dead_code)]
pub(crate) fn update_file(&mut self, new_content: impl Into<String>) -> Result<(), Error> {
let new_content = new_content.into();

Expand Down
12 changes: 1 addition & 11 deletions crates/pgt_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
//! In here, there are the operations that run via standard input
//!
use crate::execute::Execution;
use crate::{CliDiagnostic, CliSession};
use pgt_console::{ConsoleExt, markup};
use pgt_fs::PgTPath;

pub(crate) fn run<'a>(
session: CliSession,
mode: &'a Execution,
pgt_path: PgTPath,
content: &'a str,
verbose: bool,
) -> Result<(), CliDiagnostic> {
let workspace = &*session.app.workspace;
pub(crate) fn run(session: CliSession, content: &str) -> Result<(), CliDiagnostic> {
let console = &mut *session.app.console;
let version = 0;

console.append(markup! {{content}});
Ok(())
Expand Down
5 changes: 1 addition & 4 deletions crates/pgt_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fn traverse_inputs(

struct DiagnosticsPrinter<'ctx> {
/// Execution of the traversal
#[allow(dead_code)]
execution: &'ctx Execution,
/// The maximum number of diagnostics the console thread is allowed to print
max_diagnostics: u32,
Expand Down Expand Up @@ -435,10 +436,6 @@ impl TraversalOptions<'_, '_> {
pub(crate) fn push_message(&self, msg: impl Into<Message>) {
self.messages.send(msg.into()).ok();
}

pub(crate) fn protected_file(&self, pgt_path: &PgTPath) {
self.push_diagnostic(WorkspaceError::protected_file(pgt_path.display().to_string()).into())
}
}

impl TraversalContext for TraversalOptions<'_, '_> {
Expand Down
10 changes: 5 additions & 5 deletions crates/pgt_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ impl fmt::Display for Files {
}
}

struct SummaryDetail<'a>(pub(crate) &'a TraversalMode, usize);
struct SummaryDetail(usize);

impl fmt::Display for SummaryDetail<'_> {
impl fmt::Display for SummaryDetail {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
if self.1 > 0 {
if self.0 > 0 {
fmt.write_markup(markup! {
" Fixed "{Files(self.1)}"."
" Fixed "{Files(self.0)}"."
})
} else {
fmt.write_markup(markup! {
Expand Down Expand Up @@ -168,7 +168,7 @@ pub(crate) struct ConsoleTraversalSummary<'a>(
impl fmt::Display for ConsoleTraversalSummary<'_> {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
let summary = SummaryTotal(self.0, self.1.changed + self.1.unchanged, &self.1.duration);
let detail = SummaryDetail(self.0, self.1.changed);
let detail = SummaryDetail(self.1.changed);
fmt.write_markup(markup!(<Info>{summary}{detail}</Info>))?;

if self.1.errors > 0 {
Expand Down
Loading
Loading