Skip to content

Commit

Permalink
chore: Removing dead code.
Browse files Browse the repository at this point in the history
We have a lot of dead code left over from prior work, especially
from the transition to the plugin system. This commit is the
start of removing a lot of that dead code while ensuring everything
still compiles and tests still pass.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored and mchernicoff committed Sep 11, 2024
1 parent 91a53e7 commit 9bee656
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 100 deletions.
31 changes: 0 additions & 31 deletions hipcheck/src/data/es_lint/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ pub struct ESLintReport {
#[serde(rename = "filePath")]
pub file_path: String,
pub messages: Vec<ESLintMessage>,
// These fields are present in the ESLint output, but we don't use them.
#[allow(unused)]
#[serde(rename = "errorCount")]
pub error_count: u64,
#[allow(unused)]
#[serde(rename = "warningCount")]
pub warning_count: u64,
#[allow(unused)]
#[serde(rename = "fixableErrorCount")]
pub fixable_error_count: u64,
#[allow(unused)]
#[serde(rename = "fixableWarningCount")]
pub fixable_warning_count: u64,
#[allow(unused)]
pub source: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
Expand All @@ -41,18 +26,6 @@ pub struct ESLintMessage {
pub rule_id: String,
pub line: u64,
pub column: u64,
// These fields are present in the ESlint output, but aren't used internally.
// We still include them here, but ignore that they're unused.
#[allow(unused)]
pub severity: u64,
#[allow(unused)]
pub message: String,
#[allow(unused)]
#[serde(rename = "endLine")]
pub end_line: u64,
#[allow(unused)]
#[serde(rename = "endColumn")]
pub end_column: u64,
}

#[cfg(test)]
Expand All @@ -75,7 +48,6 @@ mod test {

let msg: ESLintMessage = serde_json::from_str(json).unwrap();
assert_eq!(msg.rule_id, "no-eval");
assert_eq!(msg.severity, 2);
}

#[test]
Expand All @@ -92,7 +64,6 @@ mod test {

let report: ESLintReport = serde_json::from_str(json).unwrap();
assert_eq!(report.file_path, "src/hello.js");
assert_eq!(report.error_count, 0);
}

#[test]
Expand Down Expand Up @@ -155,10 +126,8 @@ mod test {

assert_eq!(reports[0].file_path, "no_issues.js");
assert_eq!(reports[0].messages.len(), 0);
assert_eq!(reports[0].source, None);

assert_eq!(reports[1].file_path, "problems.js");
assert_eq!(reports[1].messages.len(), 2);
assert!(reports[1].source.is_some());
}
}
3 changes: 0 additions & 3 deletions hipcheck/src/data/es_lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,5 @@ mod test {
assert!(reports[0].file_path.ends_with("bad.js"));
assert_eq!(reports[0].messages.len(), 1);
assert_eq!(reports[0].messages[0].rule_id, "no-eval");
assert!(reports[0].source.is_some());
assert!(reports[0].source.as_ref().unwrap().contains("bad_function"));
assert!(reports[0].source.as_ref().unwrap().contains("eval"));
}
}
8 changes: 0 additions & 8 deletions hipcheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,24 +820,16 @@ const EXIT_FAILURE: i32 = 1;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum CheckKind {
#[allow(dead_code)]
Repo,
Maven,
Npm,
Pypi,
#[allow(dead_code)]
Spdx,
}

impl CheckKind {
/// Get the name of the check.
const fn name(&self) -> &'static str {
match self {
CheckKind::Repo => "repo",
CheckKind::Maven => "maven",
CheckKind::Npm => "npm",
CheckKind::Pypi => "pypi",
CheckKind::Spdx => "spdx",
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions hipcheck/src/plugin/download_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub struct Compress {
}

impl Compress {
#[allow(unused)]
#[cfg(test)]
pub fn new(archive_format: ArchiveFormat) -> Self {
Self {
format: archive_format,
Expand Down Expand Up @@ -176,7 +176,7 @@ pub struct Size {
}

impl Size {
#[allow(unused)]
#[cfg(test)]
pub fn new(bytes: u64) -> Self {
Self { bytes }
}
Expand Down Expand Up @@ -367,12 +367,12 @@ pub struct DownloadManifest {
}

impl DownloadManifest {
#[allow(unused)]
#[cfg(test)]
pub fn iter(&self) -> impl Iterator<Item = &DownloadManifestEntry> {
self.entries.iter()
}

#[allow(unused)]
#[cfg(test)]
pub fn len(&self) -> usize {
self.entries.len()
}
Expand Down
6 changes: 6 additions & 0 deletions hipcheck/src/plugin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl PluginExecutor {
jitter_percent
));
}

let backoff_interval = Duration::from_micros(backoff_interval_micros);

Ok(PluginExecutor {
max_spawn_attempts,
max_conn_attempts,
Expand All @@ -42,6 +44,7 @@ impl PluginExecutor {
jitter_percent,
})
}

fn get_available_port(&self) -> Result<u16> {
for _i in self.port_range.start..self.port_range.end {
// @Todo - either TcpListener::bind returns Ok even if port is bound
Expand All @@ -55,14 +58,17 @@ impl PluginExecutor {
}
}
}

Err(hc_error!("Failed to find available port"))
}

pub async fn start_plugins(&self, plugins: Vec<Plugin>) -> Result<Vec<PluginContext>> {
join_all(plugins.into_iter().map(|p| self.start_plugin(p)))
.await
.into_iter()
.collect()
}

pub async fn start_plugin(&self, plugin: Plugin) -> Result<PluginContext> {
// Plugin startup design has inherent TOCTOU flaws since we tell the plugin
// which port we expect it to bind to. We can try to ensure the port we pass
Expand Down
4 changes: 1 addition & 3 deletions hipcheck/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ impl ActivePlugin {

#[derive(Debug)]
pub struct HcPluginCore {
#[allow(unused)]
executor: PluginExecutor,
pub plugins: HashMap<String, ActivePlugin>,
}

Expand Down Expand Up @@ -150,6 +148,6 @@ impl HcPluginCore {
);

// Now we have a set of started and initialized plugins to interact with
Ok(HcPluginCore { executor, plugins })
Ok(HcPluginCore { plugins })
}
}
17 changes: 1 addition & 16 deletions hipcheck/src/plugin/plugin_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ impl Entrypoints {
None => Ok(()),
}
}

#[allow(unused)]
pub fn iter(&self) -> impl Iterator<Item = (&SupportedArch, &String)> {
self.0.iter()
}
}

impl ParseKdlNode for Entrypoints {
Expand Down Expand Up @@ -90,7 +85,7 @@ pub struct PluginDependency {
}

impl PluginDependency {
#[allow(unused)]
#[cfg(test)]
pub fn new(
publisher: PluginPublisher,
name: PluginName,
Expand Down Expand Up @@ -152,19 +147,9 @@ impl PluginDependencyList {
Self(Vec::new())
}

#[allow(unused)]
pub fn with_capacity(capacity: usize) -> Self {
Self(Vec::with_capacity(capacity))
}

pub fn push(&mut self, dependency: PluginDependency) {
self.0.push(dependency);
}

#[allow(unused)]
pub fn pop(&mut self) -> Option<PluginDependency> {
self.0.pop()
}
}

impl ParseKdlNode for PluginDependencyList {
Expand Down
2 changes: 0 additions & 2 deletions hipcheck/src/session/pm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

#![allow(dead_code)]
use crate::{
error::{Context as _, Error, Result},
hc_error,
Expand All @@ -16,7 +15,6 @@ use std::{
use url::{Host, Url};
use xml::reader::{EventReader, XmlEvent};

const MAVEN: &str = CheckKind::Maven.name();
const NPM: &str = CheckKind::Npm.name();
const PYPI: &str = CheckKind::Pypi.name();

Expand Down
33 changes: 0 additions & 33 deletions hipcheck/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
shell::spinner_phase::SpinnerPhase,
target::{KnownRemote, LocalGitRepo, RemoteGitRepo, Target},
};
use log::debug;
use pathbuf::pathbuf;
use std::path::{Path, PathBuf};
use url::{Host, Url};
Expand Down Expand Up @@ -216,38 +215,6 @@ pub fn get_github_owner_and_repo(url: &Url) -> Result<(String, String)> {
Ok((owner, repo))
}

#[allow(dead_code)]
fn get_github_owner_repo_and_pull_request(url: &Url) -> Result<(String, String, u64)> {
let mut segments = url.path_segments().ok_or_else(|| {
Error::msg("GitHub URL missing path for owner, repository, and pull request number")
})?;

let owner = segments
.next()
.ok_or_else(|| Error::msg("GitHub URL missing owner"))?
.to_owned();

let repo = segments
.next()
.ok_or_else(|| Error::msg("GitHub URL missing repository"))?
.to_owned();

let test_pull = segments.next();

if test_pull == Some("pull") {
let pull_request = segments
.next()
.ok_or_else(|| Error::msg("GitHub URL missing pull request number"))?
.to_owned();
let pull_request_number: u64 = pull_request.parse().unwrap();
debug!("Pull request number: {}", pull_request_number);

Ok((owner, repo, pull_request_number))
} else {
Err(Error::msg("GitHub URL not a pull request"))
}
}

fn build_unknown_remote_clone_dir(url: &Url) -> Result<String> {
let mut dir = String::new();

Expand Down

0 comments on commit 9bee656

Please sign in to comment.