Skip to content

Commit fd2fdfd

Browse files
committed
refactor utils::config
1 parent 74bb5e0 commit fd2fdfd

File tree

5 files changed

+258
-278
lines changed

5 files changed

+258
-278
lines changed

clippy_lints/src/lib.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ use rustc::lint::{self, LintId};
4848
use rustc::session::Session;
4949
use rustc_data_structures::fx::FxHashSet;
5050

51-
use std::path::Path;
52-
5351
/// Macro used to declare a Clippy lint.
5452
///
5553
/// Every lint declaration consists of 4 parts:
@@ -303,7 +301,7 @@ pub mod write;
303301
pub mod zero_div_zero;
304302
// end lints modules, do not remove this comment, it’s used in `update_lints`
305303

306-
pub use crate::utils::conf::Conf;
304+
pub use crate::utils::config::Conf;
307305

308306
mod reexport {
309307
crate use syntax::ast::Name;
@@ -330,42 +328,41 @@ pub fn register_pre_expansion_lints(store: &mut rustc::lint::LintStore, conf: &C
330328

331329
#[doc(hidden)]
332330
pub fn read_conf(args: &[syntax::ast::NestedMetaItem], sess: &Session) -> Conf {
333-
match utils::conf::file_from_args(args) {
331+
use std::path::Path;
332+
match utils::config::file_from_args(args) {
334333
Ok(file_name) => {
335334
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but
336335
// do not require the file to exist
337-
let file_name = if let Some(file_name) = file_name {
338-
Some(file_name)
339-
} else {
340-
match utils::conf::lookup_conf_file() {
341-
Ok(path) => path,
336+
let file_name = match file_name {
337+
Some(file_name) => file_name,
338+
None => match utils::config::lookup_conf_file() {
339+
Ok(Some(path)) => path,
340+
Ok(None) => return Conf::default(),
342341
Err(error) => {
343342
sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
344343
.emit();
345-
None
344+
return Conf::default();
346345
},
347-
}
346+
},
348347
};
349348

350-
let file_name = file_name.map(|file_name| {
351-
if file_name.is_relative() {
352-
sess.local_crate_source_file
353-
.as_deref()
354-
.and_then(Path::parent)
355-
.unwrap_or_else(|| Path::new(""))
356-
.join(file_name)
357-
} else {
358-
file_name
359-
}
360-
});
349+
let file_name = if file_name.is_relative() {
350+
sess.local_crate_source_file
351+
.as_deref()
352+
.and_then(Path::parent)
353+
.unwrap_or_else(|| Path::new(""))
354+
.join(file_name)
355+
} else {
356+
file_name
357+
};
361358

362-
let (conf, errors) = utils::conf::read(file_name.as_ref().map(AsRef::as_ref));
359+
let (conf, errors) = utils::config::read(&file_name);
363360

364361
// all conf errors are non-fatal, we just use the default conf in case of error
365362
for error in errors {
366363
sess.struct_err(&format!(
367364
"error reading Clippy's configuration file `{}`: {}",
368-
file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""),
365+
file_name.display(),
369366
error
370367
))
371368
.emit();

clippy_lints/src/utils/conf.rs

Lines changed: 0 additions & 253 deletions
This file was deleted.

0 commit comments

Comments
 (0)