Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: index slicing
Adrian Duke committed 3 months ago
commit 28d73ea08b385119286ea227622171aac74eadce
parent 31397e99427e254c325e758c88c3b5c11c544675
6 files changed +12 -7
modified Cargo.toml
@@ -81,6 +81,7 @@ radicle-surf = "0.26.0"
[workspace.lints]
clippy.type_complexity = "allow"
clippy.enum_variant_names = "allow"
+
clippy.indexing_slicing = "deny"
clippy.fallible_impl_from = "deny"
clippy.wildcard_enum_match_arm = "deny"
clippy.unneeded_field_pattern = "deny"
modified crates/radicle-cli/src/commands/cob/args.rs
@@ -210,6 +210,7 @@ where

    chunks.map(|chunk| {
        // Slice accesses will not panic, guaranteed by `chunks_exact(2)`.
+
        #[allow(clippy::indexing_slicing)]
        Embed {
            name: chunk[0].to_string(),
            content: EmbedContent::from(T::from(chunk[1].clone())),
modified crates/radicle-cli/src/commands/id/args.rs
@@ -55,6 +55,7 @@ pub(super) fn parse_many_upserts(

    chunks.map(|chunk| {
        // Slice accesses will not panic, guaranteed by `chunks_exact(3)`.
+
        #[allow(clippy::indexing_slicing)]
        Ok(PayloadUpsert {
            id: PayloadId::from_str(&chunk[0])?,
            key: chunk[1].to_owned(),
modified crates/radicle-cli/src/git/pretty_diff.rs
@@ -537,14 +537,14 @@ impl ToPretty for Modification {
        match self {
            Modification::Deletion(diff::Deletion { line, line_no }) => {
                if let Some(lines) = &blobs.old.as_ref() {
-
                    lines[*line_no as usize - 1].clone()
+
                    lines.get(*line_no as usize - 1).unwrap().clone()
                } else {
                    term::Line::new(String::from_utf8_lossy(line.as_bytes()).as_ref())
                }
            }
            Modification::Addition(diff::Addition { line, line_no }) => {
                if let Some(lines) = &blobs.new.as_ref() {
-
                    lines[*line_no as usize - 1].clone()
+
                    lines.get(*line_no as usize - 1).unwrap().clone()
                } else {
                    term::Line::new(String::from_utf8_lossy(line.as_bytes()).as_ref())
                }
@@ -554,7 +554,7 @@ impl ToPretty for Modification {
            } => {
                // Nb. we can check in the old or the new blob, we choose the new.
                if let Some(lines) = &blobs.new.as_ref() {
-
                    lines[*line_no_new as usize - 1].clone()
+
                    lines.get(*line_no_new as usize - 1).unwrap().clone()
                } else {
                    term::Line::new(String::from_utf8_lossy(line.as_bytes()).as_ref())
                }
modified crates/radicle-cli/src/terminal/highlight.rs
@@ -145,9 +145,11 @@ impl Builder {
                    }
                }
                ts::HighlightEvent::HighlightStart(h) => {
-
                    let name = HIGHLIGHTS[h.0];
-
                    let style =
-
                        term::Style::default().fg(theme.highlight(name).unwrap_or_default());
+
                    let color = HIGHLIGHTS
+
                        .get(h.0)
+
                        .and_then(|name| theme.highlight(name))
+
                        .unwrap_or_default();
+
                    let style = term::Style::default().fg(color);

                    self.advance();
                    self.styles.push(style);
modified crates/radicle-cli/src/terminal/io.rs
@@ -78,7 +78,7 @@ pub fn comment_select(issue: &Issue) -> anyhow::Result<(&CommentId, &Comment)> {
        (0..comments.len()).collect(),
    )
    .with_render_config(*CONFIG)
-
    .with_formatter(&|i| comments[i.index].1.body().to_owned())
+
    .with_formatter(&|i| comments.get(i.index).unwrap().1.body().to_owned())
    .prompt()?;

    comments