Skip to content

Commit

Permalink
refactor(core): remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Feb 9, 2025
1 parent 641f895 commit ee95553
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 130 deletions.
27 changes: 1 addition & 26 deletions src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ use {
version_group::VersionGroupVariant,
},
itertools::Itertools,
std::{
cell::RefCell,
cmp::Ordering,
collections::{BTreeMap, HashSet},
rc::Rc,
vec,
},
std::{cell::RefCell, cmp::Ordering, rc::Rc, vec},
};

#[derive(Debug)]
Expand Down Expand Up @@ -63,16 +57,6 @@ impl Dependency {
}
}

pub fn get_unique_specifiers(&self) -> Vec<Specifier> {
let set: HashSet<Specifier> = self
.instances
.borrow()
.iter()
.map(|instance| instance.descriptor.specifier.clone())
.collect();
set.into_iter().collect()
}

/// Return the most severe state of all instances in this group
pub fn get_state(&self) -> InstanceState {
self
Expand All @@ -92,15 +76,6 @@ impl Dependency {
.collect::<Vec<_>>()
}

pub fn get_instances_by_specifier(&self) -> BTreeMap<String, Vec<Rc<Instance>>> {
let mut map = BTreeMap::new();
for instance in self.instances.borrow().iter() {
let raw = instance.descriptor.specifier.get_raw();
map.entry(raw).or_insert_with(Vec::new).push(Rc::clone(instance));
}
map
}

pub fn set_expected_specifier(&self, specifier: &Specifier) -> &Self {
*self.expected.borrow_mut() = Some(specifier.clone());
self
Expand Down
2 changes: 1 addition & 1 deletion src/effects/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn run(ctx: Context) -> Context {

match state {
InstanceState::Unknown => {}
InstanceState::Valid(variant) => {
InstanceState::Valid(_) => {
valid += 1;
}
InstanceState::Invalid(variant) => match variant {
Expand Down
1 change: 0 additions & 1 deletion src/effects/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub fn run(ctx: Context) -> Context {
}
ui.print_group_header(group);
if group.dependencies.borrow().len() == 0 {
let label = &group.selector.label;
ui.print_empty_group();
return;
}
Expand Down
15 changes: 0 additions & 15 deletions src/effects/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,6 @@ impl Ui<'_> {
format!("in {file_link} at {path_to_prop}").normal()
}

/// Issues related to whether a specifier is the highest or lowest semver are
/// all the same logic internally, so we have combined enum branches for them.
///
/// From an end user point of view though it is clearer to have a specific
/// status code related to what has happened.
fn to_public_status_code(group_variant: &VersionGroupVariant, code: &str) -> ColoredString {
if matches!(group_variant, VersionGroupVariant::HighestSemver) {
code.replace("HighestOrLowestSemver", "HighestSemver").normal()
} else if matches!(group_variant, VersionGroupVariant::LowestSemver) {
code.replace("HighestOrLowestSemver", "LowestSemver").normal()
} else {
code.normal()
}
}

pub fn print_empty_group(&self) {
warn!("Version Group is empty");
}
Expand Down
6 changes: 1 addition & 5 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
},
log::debug,
serde_json::Value,
std::{cell::RefCell, path::PathBuf, rc::Rc},
std::{cell::RefCell, rc::Rc},
};

pub type InstanceId = String;
Expand Down Expand Up @@ -58,8 +58,6 @@ pub struct Instance {
/// be set to, if it was not possible to determine without user intervention,
/// this will be a `None`.
pub expected_specifier: RefCell<Option<Specifier>>,
/// The file path of the package.json file this instance belongs to
pub file_path: PathBuf,
/// A unique identifier for this instance
pub id: InstanceId,
/// Whether this is a package developed in this repo
Expand All @@ -79,7 +77,6 @@ impl Instance {
let package_name = descriptor.package.borrow().name.clone();
let id = format!("{} in {} of {}", &descriptor.name, dependency_type_name, package_name);
let is_local = dependency_type_name == "/version";
let file_path = descriptor.package.borrow().file_path.clone();
Instance {
// deprecated
actual_specifier: descriptor.specifier.clone(),
Expand All @@ -91,7 +88,6 @@ impl Instance {

descriptor,
expected_specifier: RefCell::new(None),
file_path,
id,
is_local,
preferred_semver_range: RefCell::new(None),
Expand Down
18 changes: 0 additions & 18 deletions src/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ use {
specifier::{basic_semver::BasicSemver, Specifier},
},
glob::glob,
itertools::Itertools,
log::debug,
serde::Deserialize,
serde_json::Value,
std::{
cell::RefCell,
cmp::Ordering,
collections::HashMap,
fs,
path::{Path, PathBuf},
rc::Rc,
vec::IntoIter,
},
};

Expand Down Expand Up @@ -53,21 +50,6 @@ impl Packages {
self
}

/// Get all packages sorted by their file path
pub fn sorted_by_path(&self, cwd: &PathBuf) -> IntoIter<&Rc<RefCell<PackageJson>>> {
self.all.iter().sorted_by(|a, b| {
let a = a.borrow().get_relative_file_path(cwd);
let b = b.borrow().get_relative_file_path(cwd);
if a == "package.json" {
return Ordering::Less;
}
if b == "package.json" {
return Ordering::Greater;
}
Ord::cmp(&a, &b)
})
}

/// Get a package.json file by its name
pub fn get_by_name(&self, name: &str) -> Option<Rc<RefCell<PackageJson>>> {
self.all.iter().find(|package| package.borrow().name == name).map(Rc::clone)
Expand Down
19 changes: 0 additions & 19 deletions src/rcfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,6 @@ pub struct Rcfile {
}

impl Rcfile {
/// Create a new rcfile containing only default values.
pub fn new() -> Rcfile {
Rcfile {
custom_types: empty_custom_types(),
dependency_groups: vec![],
format_bugs: default_true(),
format_repository: default_true(),
indent: default_indent(),
semver_groups: vec![],
sort_az: default_sort_az(),
sort_exports: default_sort_exports(),
sort_first: sort_first(),
sort_packages: default_true(),
source: default_source(),
strict: default_false(),
version_groups: vec![],
}
}

/// Until we can port cosmiconfig to Rust, call out to Node.js to get the
/// rcfile from the filesystem
pub fn from_cosmiconfig(cli: &Cli) -> Rcfile {
Expand Down
24 changes: 2 additions & 22 deletions src/semver_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@ use {
serde::Deserialize,
};

#[derive(Debug)]
pub enum SemverGroupVariant {
Disabled,
Ignored,
WithRange,
}

#[derive(Debug)]
pub struct SemverGroup {
/// What behaviour has this group been configured to exhibit?
pub variant: SemverGroupVariant,
/// Data to determine which instances should be added to this group
pub selector: GroupSelector,
/// The Semver Range which all instances in this group should use
Expand All @@ -24,7 +15,6 @@ impl SemverGroup {
/// Create a default group which ensures local packages are an exact version
pub fn get_exact_local_specifiers() -> SemverGroup {
SemverGroup {
variant: SemverGroupVariant::WithRange,
selector: GroupSelector::new(
/* all_packages: */ &Packages::new(),
/* include_dependencies: */ vec![],
Expand All @@ -40,7 +30,6 @@ impl SemverGroup {
/// Create a default/catch-all group which would apply to any instance
pub fn get_catch_all() -> SemverGroup {
SemverGroup {
variant: SemverGroupVariant::Disabled,
selector: GroupSelector::new(
/* all_packages: */ &Packages::new(),
/* include_dependencies: */ vec![],
Expand All @@ -65,20 +54,11 @@ impl SemverGroup {
);

if let Some(true) = group.is_disabled {
SemverGroup {
variant: SemverGroupVariant::Disabled,
selector,
range: None,
}
SemverGroup { selector, range: None }
} else if let Some(true) = group.is_ignored {
SemverGroup {
variant: SemverGroupVariant::Ignored,
selector,
range: None,
}
SemverGroup { selector, range: None }
} else if let Some(range) = &group.range {
SemverGroup {
variant: SemverGroupVariant::WithRange,
selector,
range: SemverRange::new(range),
}
Expand Down
12 changes: 1 addition & 11 deletions src/specifier/parser.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
use {super::regexes, log::debug};

/// Convert non-semver specifiers to semver when behaviour is identical
pub fn sanitise(specifier: &str) -> &str {
if specifier == "latest" || specifier == "x" {
debug!("Sanitising specifier: {} → *", specifier);
"*"
} else {
specifier
}
}
use super::regexes;

pub fn is_simple_semver(str: &str) -> bool {
is_exact(str) || is_latest(str) || is_major(str) || is_minor(str) || is_range(str) || is_range_major(str) || is_range_minor(str)
Expand Down
5 changes: 0 additions & 5 deletions src/specifier/regexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ lazy_static! {
/// "<1.0.0 >2.0.0"
pub static ref INFIX_OPERATORS:Regex = Regex::new(r" ?(-|\|\|) ?| ").unwrap();
}

/// Check if a string matches any of the regexes
pub fn matches_any(regexes: Vec<&Regex>, string: &str) -> bool {
regexes.iter().any(|re| re.is_match(string))
}
7 changes: 0 additions & 7 deletions src/version_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,6 @@ impl VersionGroup {
}
}

struct SnapToMismatches {
pub instance_ids: Vec<String>,
pub actual_specifier: Specifier,
pub expected_specifier: Specifier,
pub snap_to_instance_id: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AnyVersionGroup {
Expand Down

0 comments on commit ee95553

Please sign in to comment.