Skip to content

Commit

Permalink
Cut down unnecessary lint allows (nushell#14335)
Browse files Browse the repository at this point in the history
Trying to reduce lint allows either by checking if they are former false
positives or by fixing the underlying warning.

- **Remove dead `allow(dead_code)`**
- **Remove recursive dead code**
- **Remove dead code**
- **Move test only functions to test module**
  The unit tests that use them, themselves are somewhat sus in that they
mock the usage and not test specificly used methods of the
implementation, so there is a risk for divergence
- **Remove `clippy::uninit_vec` allow.**
  May have been a false positive, or the impl has changed somewhat.
We certainly want to look at the unsafe code here to vet for
correctness.
  • Loading branch information
sholderbach authored Nov 15, 2024
1 parent 7bd801a commit 455d32d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 54 deletions.
9 changes: 0 additions & 9 deletions crates/nu-cli/src/prompt_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,21 @@ pub(crate) const TRANSIENT_PROMPT_MULTILINE_INDICATOR: &str =
pub(crate) const PRE_PROMPT_MARKER: &str = "\x1b]133;A\x1b\\";
pub(crate) const POST_PROMPT_MARKER: &str = "\x1b]133;B\x1b\\";
pub(crate) const PRE_EXECUTION_MARKER: &str = "\x1b]133;C\x1b\\";
#[allow(dead_code)]
pub(crate) const POST_EXECUTION_MARKER_PREFIX: &str = "\x1b]133;D;";
#[allow(dead_code)]
pub(crate) const POST_EXECUTION_MARKER_SUFFIX: &str = "\x1b\\";

// OSC633 is the same as OSC133 but specifically for VSCode
pub(crate) const VSCODE_PRE_PROMPT_MARKER: &str = "\x1b]633;A\x1b\\";
pub(crate) const VSCODE_POST_PROMPT_MARKER: &str = "\x1b]633;B\x1b\\";
#[allow(dead_code)]
pub(crate) const VSCODE_PRE_EXECUTION_MARKER: &str = "\x1b]633;C\x1b\\";
#[allow(dead_code)]
//"\x1b]633;D;{}\x1b\\"
pub(crate) const VSCODE_POST_EXECUTION_MARKER_PREFIX: &str = "\x1b]633;D;";
#[allow(dead_code)]
pub(crate) const VSCODE_POST_EXECUTION_MARKER_SUFFIX: &str = "\x1b\\";
#[allow(dead_code)]
//"\x1b]633;E;{}\x1b\\"
pub(crate) const VSCODE_COMMANDLINE_MARKER_PREFIX: &str = "\x1b]633;E;";
#[allow(dead_code)]
pub(crate) const VSCODE_COMMANDLINE_MARKER_SUFFIX: &str = "\x1b\\";
#[allow(dead_code)]
// "\x1b]633;P;Cwd={}\x1b\\"
pub(crate) const VSCODE_CWD_PROPERTY_MARKER_PREFIX: &str = "\x1b]633;P;Cwd=";
#[allow(dead_code)]
pub(crate) const VSCODE_CWD_PROPERTY_MARKER_SUFFIX: &str = "\x1b\\";

pub(crate) const RESET_APPLICATION_MODE: &str = "\x1b[?1l";
Expand Down
4 changes: 0 additions & 4 deletions crates/nu-cli/src/reedline_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ pub(crate) fn create_keybindings(config: &Config) -> Result<KeybindingsMode, She
}
for keybinding in parsed_keybindings {
add_keybinding(
&keybinding.name,
&keybinding.mode,
keybinding,
config,
Expand All @@ -730,9 +729,7 @@ pub(crate) fn create_keybindings(config: &Config) -> Result<KeybindingsMode, She
}
}

#[allow(clippy::only_used_in_recursion)]
fn add_keybinding(
name: &Option<Value>,
mode: &Value,
keybinding: &ParsedKeybinding,
config: &Config,
Expand All @@ -755,7 +752,6 @@ fn add_keybinding(
Value::List { vals, .. } => {
for inner_mode in vals {
add_keybinding(
name,
inner_mode,
keybinding,
config,
Expand Down
5 changes: 0 additions & 5 deletions crates/nu-command/src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ impl NuProgressBar {
self.pb.set_position(bytes_processed);
}

#[allow(dead_code)]
pub fn finished_msg(&self, msg: String) {
self.pb.finish_with_message(msg);
}

pub fn abandoned_msg(&self, msg: String) {
self.pb.abandon_with_message(msg);
}
Expand Down
65 changes: 31 additions & 34 deletions crates/nu-command/src/strings/guess_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,42 +291,39 @@ fn positions_helper(blanks: &[usize], min_lines: usize) -> Vec<usize> {
pos
}

// to_rows returns rows separated by columns.
#[allow(dead_code)]
fn to_rows(lines: Vec<String>, pos: Vec<usize>, trim_space: bool) -> Vec<Vec<String>> {
let mut rows: Vec<Vec<String>> = Vec::with_capacity(lines.len());
for line in lines {
let columns = split(&line, &pos, trim_space);
rows.push(columns);
}
rows
}

// to_table parses a slice of lines and returns a table.
#[allow(dead_code)]
pub fn to_table(lines: Vec<String>, header: usize, trim_space: bool) -> Vec<Vec<String>> {
let pos = positions(&lines, header, 2);
to_rows(lines, pos, trim_space)
}

// to_table_n parses a slice of lines and returns a table, but limits the number of splits.
#[allow(dead_code)]
pub fn to_table_n(
lines: Vec<String>,
header: usize,
num_split: usize,
trim_space: bool,
) -> Vec<Vec<String>> {
let mut pos = positions(&lines, header, 2);
if pos.len() > num_split {
pos.truncate(num_split);
}
to_rows(lines, pos, trim_space)
}

#[cfg(test)]
mod tests {
use super::{to_table, to_table_n, GuessWidth};
use super::*;

/// to_rows returns rows separated by columns.
fn to_rows(lines: Vec<String>, pos: Vec<usize>, trim_space: bool) -> Vec<Vec<String>> {
let mut rows: Vec<Vec<String>> = Vec::with_capacity(lines.len());
for line in lines {
let columns = split(&line, &pos, trim_space);
rows.push(columns);
}
rows
}

/// to_table parses a slice of lines and returns a table.
pub fn to_table(lines: Vec<String>, header: usize, trim_space: bool) -> Vec<Vec<String>> {
let pos = positions(&lines, header, 2);
to_rows(lines, pos, trim_space)
}

/// to_table_n parses a slice of lines and returns a table, but limits the number of splits.
pub fn to_table_n(
lines: Vec<String>,
header: usize,
num_split: usize,
trim_space: bool,
) -> Vec<Vec<String>> {
let mut pos = positions(&lines, header, 2);
if pos.len() > num_split {
pos.truncate(num_split);
}
to_rows(lines, pos, trim_space)
}

#[test]
fn test_guess_width_ps_trim() {
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-system/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ unsafe fn null_terminated_wchar_to_string(slice: &[u16]) -> String {
}
}

#[allow(clippy::uninit_vec)]
unsafe fn get_process_data(
handle: HANDLE,
ptr: *const c_void,
Expand Down Expand Up @@ -518,7 +517,6 @@ unsafe fn get_region_size(handle: HANDLE, ptr: *const c_void) -> Result<usize, &
Ok((meminfo.RegionSize as isize - ptr.offset_from(meminfo.BaseAddress)) as usize)
}

#[allow(clippy::uninit_vec)]
unsafe fn ph_query_process_variable_size(
process_handle: HANDLE,
process_information_class: PROCESSINFOCLASS,
Expand Down

0 comments on commit 455d32d

Please sign in to comment.