ConfigWasSet(self)
}
- fn fill_from_parsed_config(mut self, parsed: PartialConfig) -> Config {
+ fn fill_from_parsed_config(mut self, parsed: PartialConfig, dir: &Path) -> Config {
$(
if let Some(val) = parsed.$i {
if self.$i.3 {
)+
self.set_heuristics();
self.set_license_template();
+ self.set_ignore(dir);
self
}
}
}
+ fn set_ignore(&mut self, dir: &Path) {
+ self.ignore.2.add_prefix(dir);
+ }
/// Returns `true` if the config key was explicitly set and is the default value.
pub fn is_default(&self, key: &str) -> bool {
let mut file = File::open(&file_path)?;
let mut toml = String::new();
file.read_to_string(&mut toml)?;
- Config::from_toml(&toml).map_err(|err| Error::new(ErrorKind::InvalidData, err))
+ Config::from_toml(&toml, file_path.parent().unwrap())
+ .map_err(|err| Error::new(ErrorKind::InvalidData, err))
}
/// Resolves the config for input in `dir`.
}
}
- pub(crate) fn from_toml(toml: &str) -> Result<Config, String> {
+ pub(crate) fn from_toml(toml: &str, dir: &Path) -> Result<Config, String> {
let parsed: ::toml::Value = toml
.parse()
.map_err(|e| format!("Could not parse TOML: {}", e))?;
if !err.is_empty() {
eprint!("{}", err);
}
- Ok(Config::default().fill_from_parsed_config(parsed_config))
+ Ok(Config::default().fill_from_parsed_config(parsed_config, dir))
}
Err(e) => {
err.push_str("Error: Decoding config file failed:\n");
#[test]
fn test_was_set() {
- let config = Config::from_toml("hard_tabs = true").unwrap();
+ let config = Config::from_toml("hard_tabs = true", Path::new("")).unwrap();
assert_eq!(config.was_set().hard_tabs(), true);
assert_eq!(config.was_set().verbose(), false);
-use ignore::{self, gitignore};
use std::path::PathBuf;
+use ignore::{self, gitignore};
+
use crate::config::{FileName, IgnoreList};
pub struct IgnorePathSet {
#[cfg(test)]
mod test {
+ use std::path::{Path, PathBuf};
+
use crate::config::{Config, FileName};
use crate::ignore_path::IgnorePathSet;
- use std::path::PathBuf;
#[test]
fn test_ignore_path_set() {
match option_env!("CFG_RELEASE_CHANNEL") {
// this test requires nightly
None | Some("nightly") => {
- let config = Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#).unwrap();
+ let config =
+ Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#, Path::new(""))
+ .unwrap();
let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap();
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs"))));
.read_to_string(&mut def_config)
.expect("Couldn't read config");
- Config::from_toml(&def_config).expect("invalid TOML")
+ Config::from_toml(&def_config, Path::new("tests/config/")).expect("invalid TOML")
}
// Reads significant comments of the form: `// rustfmt-key: value` into a hash map.