Skip to content

Commit ee95553

Browse files
committed
refactor(core): remove unused code
1 parent 641f895 commit ee95553

File tree

11 files changed

+6
-130
lines changed

11 files changed

+6
-130
lines changed

src/dependency.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ use {
77
version_group::VersionGroupVariant,
88
},
99
itertools::Itertools,
10-
std::{
11-
cell::RefCell,
12-
cmp::Ordering,
13-
collections::{BTreeMap, HashSet},
14-
rc::Rc,
15-
vec,
16-
},
10+
std::{cell::RefCell, cmp::Ordering, rc::Rc, vec},
1711
};
1812

1913
#[derive(Debug)]
@@ -63,16 +57,6 @@ impl Dependency {
6357
}
6458
}
6559

66-
pub fn get_unique_specifiers(&self) -> Vec<Specifier> {
67-
let set: HashSet<Specifier> = self
68-
.instances
69-
.borrow()
70-
.iter()
71-
.map(|instance| instance.descriptor.specifier.clone())
72-
.collect();
73-
set.into_iter().collect()
74-
}
75-
7660
/// Return the most severe state of all instances in this group
7761
pub fn get_state(&self) -> InstanceState {
7862
self
@@ -92,15 +76,6 @@ impl Dependency {
9276
.collect::<Vec<_>>()
9377
}
9478

95-
pub fn get_instances_by_specifier(&self) -> BTreeMap<String, Vec<Rc<Instance>>> {
96-
let mut map = BTreeMap::new();
97-
for instance in self.instances.borrow().iter() {
98-
let raw = instance.descriptor.specifier.get_raw();
99-
map.entry(raw).or_insert_with(Vec::new).push(Rc::clone(instance));
100-
}
101-
map
102-
}
103-
10479
pub fn set_expected_specifier(&self, specifier: &Specifier) -> &Self {
10580
*self.expected.borrow_mut() = Some(specifier.clone());
10681
self

src/effects/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn run(ctx: Context) -> Context {
3737

3838
match state {
3939
InstanceState::Unknown => {}
40-
InstanceState::Valid(variant) => {
40+
InstanceState::Valid(_) => {
4141
valid += 1;
4242
}
4343
InstanceState::Invalid(variant) => match variant {

src/effects/lint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub fn run(ctx: Context) -> Context {
1515
}
1616
ui.print_group_header(group);
1717
if group.dependencies.borrow().len() == 0 {
18-
let label = &group.selector.label;
1918
ui.print_empty_group();
2019
return;
2120
}

src/effects/ui.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,21 +419,6 @@ impl Ui<'_> {
419419
format!("in {file_link} at {path_to_prop}").normal()
420420
}
421421

422-
/// Issues related to whether a specifier is the highest or lowest semver are
423-
/// all the same logic internally, so we have combined enum branches for them.
424-
///
425-
/// From an end user point of view though it is clearer to have a specific
426-
/// status code related to what has happened.
427-
fn to_public_status_code(group_variant: &VersionGroupVariant, code: &str) -> ColoredString {
428-
if matches!(group_variant, VersionGroupVariant::HighestSemver) {
429-
code.replace("HighestOrLowestSemver", "HighestSemver").normal()
430-
} else if matches!(group_variant, VersionGroupVariant::LowestSemver) {
431-
code.replace("HighestOrLowestSemver", "LowestSemver").normal()
432-
} else {
433-
code.normal()
434-
}
435-
}
436-
437422
pub fn print_empty_group(&self) {
438423
warn!("Version Group is empty");
439424
}

src/instance.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use {
1010
},
1111
log::debug,
1212
serde_json::Value,
13-
std::{cell::RefCell, path::PathBuf, rc::Rc},
13+
std::{cell::RefCell, rc::Rc},
1414
};
1515

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

9289
descriptor,
9390
expected_specifier: RefCell::new(None),
94-
file_path,
9591
id,
9692
is_local,
9793
preferred_semver_range: RefCell::new(None),

src/packages.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ use {
99
specifier::{basic_semver::BasicSemver, Specifier},
1010
},
1111
glob::glob,
12-
itertools::Itertools,
1312
log::debug,
1413
serde::Deserialize,
1514
serde_json::Value,
1615
std::{
1716
cell::RefCell,
18-
cmp::Ordering,
1917
collections::HashMap,
2018
fs,
2119
path::{Path, PathBuf},
2220
rc::Rc,
23-
vec::IntoIter,
2421
},
2522
};
2623

@@ -53,21 +50,6 @@ impl Packages {
5350
self
5451
}
5552

56-
/// Get all packages sorted by their file path
57-
pub fn sorted_by_path(&self, cwd: &PathBuf) -> IntoIter<&Rc<RefCell<PackageJson>>> {
58-
self.all.iter().sorted_by(|a, b| {
59-
let a = a.borrow().get_relative_file_path(cwd);
60-
let b = b.borrow().get_relative_file_path(cwd);
61-
if a == "package.json" {
62-
return Ordering::Less;
63-
}
64-
if b == "package.json" {
65-
return Ordering::Greater;
66-
}
67-
Ord::cmp(&a, &b)
68-
})
69-
}
70-
7153
/// Get a package.json file by its name
7254
pub fn get_by_name(&self, name: &str) -> Option<Rc<RefCell<PackageJson>>> {
7355
self.all.iter().find(|package| package.borrow().name == name).map(Rc::clone)

src/rcfile.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,6 @@ pub struct Rcfile {
129129
}
130130

131131
impl Rcfile {
132-
/// Create a new rcfile containing only default values.
133-
pub fn new() -> Rcfile {
134-
Rcfile {
135-
custom_types: empty_custom_types(),
136-
dependency_groups: vec![],
137-
format_bugs: default_true(),
138-
format_repository: default_true(),
139-
indent: default_indent(),
140-
semver_groups: vec![],
141-
sort_az: default_sort_az(),
142-
sort_exports: default_sort_exports(),
143-
sort_first: sort_first(),
144-
sort_packages: default_true(),
145-
source: default_source(),
146-
strict: default_false(),
147-
version_groups: vec![],
148-
}
149-
}
150-
151132
/// Until we can port cosmiconfig to Rust, call out to Node.js to get the
152133
/// rcfile from the filesystem
153134
pub fn from_cosmiconfig(cli: &Cli) -> Rcfile {

src/semver_group.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ use {
33
serde::Deserialize,
44
};
55

6-
#[derive(Debug)]
7-
pub enum SemverGroupVariant {
8-
Disabled,
9-
Ignored,
10-
WithRange,
11-
}
12-
136
#[derive(Debug)]
147
pub struct SemverGroup {
15-
/// What behaviour has this group been configured to exhibit?
16-
pub variant: SemverGroupVariant,
178
/// Data to determine which instances should be added to this group
189
pub selector: GroupSelector,
1910
/// The Semver Range which all instances in this group should use
@@ -24,7 +15,6 @@ impl SemverGroup {
2415
/// Create a default group which ensures local packages are an exact version
2516
pub fn get_exact_local_specifiers() -> SemverGroup {
2617
SemverGroup {
27-
variant: SemverGroupVariant::WithRange,
2818
selector: GroupSelector::new(
2919
/* all_packages: */ &Packages::new(),
3020
/* include_dependencies: */ vec![],
@@ -40,7 +30,6 @@ impl SemverGroup {
4030
/// Create a default/catch-all group which would apply to any instance
4131
pub fn get_catch_all() -> SemverGroup {
4232
SemverGroup {
43-
variant: SemverGroupVariant::Disabled,
4433
selector: GroupSelector::new(
4534
/* all_packages: */ &Packages::new(),
4635
/* include_dependencies: */ vec![],
@@ -65,20 +54,11 @@ impl SemverGroup {
6554
);
6655

6756
if let Some(true) = group.is_disabled {
68-
SemverGroup {
69-
variant: SemverGroupVariant::Disabled,
70-
selector,
71-
range: None,
72-
}
57+
SemverGroup { selector, range: None }
7358
} else if let Some(true) = group.is_ignored {
74-
SemverGroup {
75-
variant: SemverGroupVariant::Ignored,
76-
selector,
77-
range: None,
78-
}
59+
SemverGroup { selector, range: None }
7960
} else if let Some(range) = &group.range {
8061
SemverGroup {
81-
variant: SemverGroupVariant::WithRange,
8262
selector,
8363
range: SemverRange::new(range),
8464
}

src/specifier/parser.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
use {super::regexes, log::debug};
2-
3-
/// Convert non-semver specifiers to semver when behaviour is identical
4-
pub fn sanitise(specifier: &str) -> &str {
5-
if specifier == "latest" || specifier == "x" {
6-
debug!("Sanitising specifier: {} → *", specifier);
7-
"*"
8-
} else {
9-
specifier
10-
}
11-
}
1+
use super::regexes;
122

133
pub fn is_simple_semver(str: &str) -> bool {
144
is_exact(str) || is_latest(str) || is_major(str) || is_minor(str) || is_range(str) || is_range_major(str) || is_range_minor(str)

src/specifier/regexes.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,3 @@ lazy_static! {
8080
/// "<1.0.0 >2.0.0"
8181
pub static ref INFIX_OPERATORS:Regex = Regex::new(r" ?(-|\|\|) ?| ").unwrap();
8282
}
83-
84-
/// Check if a string matches any of the regexes
85-
pub fn matches_any(regexes: Vec<&Regex>, string: &str) -> bool {
86-
regexes.iter().any(|re| re.is_match(string))
87-
}

0 commit comments

Comments
 (0)