Skip to content

refactor utils::config #4950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ use rustc::session::Session;
use rustc_data_structures::fx::FxHashSet;
use rustc_lint::LintId;

use std::path::Path;

/// Macro used to declare a Clippy lint.
///
/// Every lint declaration consists of 4 parts:
Expand Down Expand Up @@ -310,7 +308,7 @@ pub mod write;
pub mod zero_div_zero;
// end lints modules, do not remove this comment, it’s used in `update_lints`

pub use crate::utils::conf::Conf;
pub use crate::utils::config::Conf;

mod reexport {
crate use syntax::ast::Name;
Expand All @@ -337,42 +335,41 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, conf: &Co

#[doc(hidden)]
pub fn read_conf(args: &[syntax::ast::NestedMetaItem], sess: &Session) -> Conf {
match utils::conf::file_from_args(args) {
use std::path::Path;
match utils::config::file_from_args(args) {
Ok(file_name) => {
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but
// do not require the file to exist
let file_name = if let Some(file_name) = file_name {
Some(file_name)
} else {
match utils::conf::lookup_conf_file() {
Ok(path) => path,
let file_name = match file_name {
Some(file_name) => file_name,
None => match utils::config::lookup_conf_file() {
Ok(Some(path)) => path,
Ok(None) => return Conf::default(),
Err(error) => {
sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
.emit();
None
return Conf::default();
},
}
},
};

let file_name = file_name.map(|file_name| {
if file_name.is_relative() {
sess.local_crate_source_file
.as_deref()
.and_then(Path::parent)
.unwrap_or_else(|| Path::new(""))
.join(file_name)
} else {
file_name
}
});
let file_name = if file_name.is_relative() {
sess.local_crate_source_file
.as_deref()
.and_then(Path::parent)
.unwrap_or_else(|| Path::new(""))
.join(file_name)
} else {
file_name
};

let (conf, errors) = utils::conf::read(file_name.as_ref().map(AsRef::as_ref));
let (conf, errors) = utils::config::read(&file_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe import crate::utils::config and use config::Conf, config::read, ...


// all conf errors are non-fatal, we just use the default conf in case of error
for error in errors {
sess.struct_err(&format!(
"error reading Clippy's configuration file `{}`: {}",
file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""),
file_name.display(),
error
))
.emit();
Expand Down
256 changes: 0 additions & 256 deletions clippy_lints/src/utils/conf.rs

This file was deleted.

Loading