Skip to content

Commit a96c13e

Browse files
committed
Address review comments
1 parent d0af80d commit a96c13e

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

cargo-marker/src/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ macro_rules! unsupported_fields {
9292
}
9393

9494
impl Config {
95-
pub fn get_marker_config() -> Result<Config, ConfigFetchError> {
95+
fn get_raw_manifest() -> Result<String, ConfigFetchError> {
9696
let Ok(mut config_file) = File::open(CARGO_TOML) else {
9797
return Err(ConfigFetchError::FileNotFound);
9898
};
@@ -101,6 +101,11 @@ impl Config {
101101
if let Err(e) = config_file.read_to_string(&mut config_str) {
102102
return Err(ConfigFetchError::IoError(e));
103103
}
104+
Ok(config_str)
105+
}
106+
107+
pub fn get_marker_config() -> Result<Config, ConfigFetchError> {
108+
let config_str = Self::get_raw_manifest()?;
104109

105110
let cargo_config = match from_str::<Value>(&config_str) {
106111
Ok(v) => v,

cargo-marker/src/lints.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ use std::{
77
use crate::ExitStatus;
88

99
pub struct LintCrateSpec<'a> {
10+
/// Optional package name, exists if supplied from config:
11+
/// ```toml
12+
/// lint_a = { path = "" }
13+
/// # `lint_a` is the package_name
14+
/// lint_b = { path = "", package = "lint_c"}
15+
/// # `lint_c` is the package name
16+
/// ```
17+
/// if the lint crate was supplied only from path, this is `None`, for example in case of
18+
/// command-line arguments:
19+
///
20+
/// `--lints ./marker_lints`
21+
///
22+
/// where `./marker_lints` is `dir`, and `package_name` in this case is empty.
23+
///
24+
/// Setting this to `None` won't validate the package name when building the package with
25+
/// [`build()`](`Self::build`)
1026
package_name: Option<&'a str>,
27+
/// Path to lint crate
1128
dir: &'a Path,
1229
}
1330

@@ -17,22 +34,20 @@ impl<'a> LintCrateSpec<'a> {
1734
}
1835

1936
/// Currently only checks for semicolons, can be extended in the future
20-
pub fn validate(&self) -> bool {
21-
self.dir.to_string_lossy().contains(';')
37+
pub fn is_valid(&self) -> bool {
38+
!self.dir.to_string_lossy().contains(';')
2239
}
2340

24-
pub fn build_self(&self, target_dir: &Path, verbose: bool) -> Result<PathBuf, ExitStatus> {
41+
/// Creates a debug build for this crate. The path of the build library
42+
/// will be returned, if the operation was successful.
43+
pub fn build(&self, target_dir: &Path, verbose: bool) -> Result<PathBuf, ExitStatus> {
2544
build_local_lint_crate(self, target_dir, verbose)
2645
}
2746
}
2847

2948
/// This creates a debug build for a local crate. The path of the build library
3049
/// will be returned, if the operation was successful.
31-
pub fn build_local_lint_crate(
32-
krate: &LintCrateSpec<'_>,
33-
target_dir: &Path,
34-
verbose: bool,
35-
) -> Result<PathBuf, ExitStatus> {
50+
fn build_local_lint_crate(krate: &LintCrateSpec<'_>, target_dir: &Path, verbose: bool) -> Result<PathBuf, ExitStatus> {
3651
if !krate.dir.exists() {
3752
eprintln!("The given lint can't be found, searched at: `{}`", krate.dir.display());
3853
return Err(ExitStatus::LintCrateNotFound);

cargo-marker/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn run_check(
160160
return Err(ExitStatus::NoLints);
161161
}
162162

163-
if crate_entries.iter().any(LintCrateSpec::validate) {
163+
if !crate_entries.iter().all(LintCrateSpec::is_valid) {
164164
eprintln!("The absolute paths of lint crates are not allowed to contain a `;`");
165165
return Err(ExitStatus::InvalidValue);
166166
}
@@ -171,7 +171,7 @@ fn run_check(
171171
println!("Compiling Lints:");
172172
let target_dir = Path::new(&*MARKER_LINT_DIR);
173173
for krate in crate_entries {
174-
let crate_file = krate.build_self(target_dir, verbose)?;
174+
let crate_file = krate.build(target_dir, verbose)?;
175175
lint_crates.push(crate_file.as_os_str().to_os_string());
176176
}
177177

0 commit comments

Comments
 (0)