diff options
Diffstat (limited to 'cli/args/config_file.rs')
| -rw-r--r-- | cli/args/config_file.rs | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 0c0e5d2fa..47f8e9daa 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -295,43 +295,45 @@ impl SerializedFilesConfig { include: self .include .into_iter() - .map(|p| config_dir.join(&p)) - .collect::<Result<Vec<ModuleSpecifier>, _>>()?, + .map(|p| { + let url = config_dir.join(&p)?; + specifier_to_file_path(&url) + }) + .collect::<Result<Vec<_>, _>>()?, exclude: self .exclude .into_iter() - .map(|p| config_dir.join(&p)) - .collect::<Result<Vec<ModuleSpecifier>, _>>()?, + .map(|p| { + let url = config_dir.join(&p)?; + specifier_to_file_path(&url) + }) + .collect::<Result<Vec<_>, _>>()?, }) } } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct FilesConfig { - pub include: Vec<ModuleSpecifier>, - pub exclude: Vec<ModuleSpecifier>, + pub include: Vec<PathBuf>, + pub exclude: Vec<PathBuf>, } impl FilesConfig { /// Gets if the provided specifier is allowed based on the includes /// and excludes in the configuration file. pub fn matches_specifier(&self, specifier: &ModuleSpecifier) -> bool { + let file_path = match specifier_to_file_path(specifier) { + Ok(file_path) => file_path, + Err(_) => return false, + }; // Skip files which is in the exclude list. - let specifier_text = specifier.as_str(); - if self - .exclude - .iter() - .any(|i| specifier_text.starts_with(i.as_str())) - { + if self.exclude.iter().any(|i| file_path.starts_with(i)) { return false; } // Ignore files not in the include list if it's not empty. self.include.is_empty() - || self - .include - .iter() - .any(|i| specifier_text.starts_with(i.as_str())) + || self.include.iter().any(|i| file_path.starts_with(i)) } } @@ -663,6 +665,16 @@ impl ConfigFile { self.json.import_map.clone() } + pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> { + if let Some(config) = self.json.fmt.clone() { + let fmt_config: SerializedFmtConfig = serde_json::from_value(config) + .context("Failed to parse \"fmt\" configuration")?; + Ok(Some(fmt_config.into_resolved(&self.specifier)?)) + } else { + Ok(None) + } + } + pub fn to_lint_config(&self) -> Result<Option<LintConfig>, AnyError> { if let Some(config) = self.json.lint.clone() { let lint_config: SerializedLintConfig = serde_json::from_value(config) @@ -767,16 +779,6 @@ impl ConfigFile { }) } - pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> { - if let Some(config) = self.json.fmt.clone() { - let fmt_config: SerializedFmtConfig = serde_json::from_value(config) - .context("Failed to parse \"fmt\" configuration")?; - Ok(Some(fmt_config.into_resolved(&self.specifier)?)) - } else { - Ok(None) - } - } - pub fn resolve_tasks_config( &self, ) -> Result<BTreeMap<String, String>, AnyError> { @@ -1068,13 +1070,10 @@ mod tests { .to_lint_config() .expect("error parsing lint object") .expect("lint object should be defined"); - assert_eq!( - lint_config.files.include, - vec![config_dir.join("src/").unwrap()] - ); + assert_eq!(lint_config.files.include, vec![PathBuf::from("/deno/src/")]); assert_eq!( lint_config.files.exclude, - vec![config_dir.join("src/testdata/").unwrap()] + vec![PathBuf::from("/deno/src/testdata/")] ); assert_eq!( lint_config.rules.include, @@ -1090,13 +1089,10 @@ mod tests { .to_fmt_config() .expect("error parsing fmt object") .expect("fmt object should be defined"); - assert_eq!( - fmt_config.files.include, - vec![config_dir.join("src/").unwrap()] - ); + assert_eq!(fmt_config.files.include, vec![PathBuf::from("/deno/src/")]); assert_eq!( fmt_config.files.exclude, - vec![config_dir.join("src/testdata/").unwrap()] + vec![PathBuf::from("/deno/src/testdata/")], ); assert_eq!(fmt_config.options.use_tabs, Some(true)); assert_eq!(fmt_config.options.line_width, Some(80)); @@ -1190,6 +1186,8 @@ mod tests { let expected_exclude = ModuleSpecifier::from_file_path( testdata.join("fmt/with_config/subdir/b.ts"), ) + .unwrap() + .to_file_path() .unwrap(); assert_eq!(fmt_config.files.exclude, vec![expected_exclude]); |
