Struct doomdooz_lib::CONFIG
source · pub struct CONFIG { /* private fields */ }Methods from Deref<Target = Config>§
sourcepub fn get_array(&self, cop: &str, key: &str) -> Vec<String> ⓘ
pub fn get_array(&self, cop: &str, key: &str) -> Vec<String> ⓘ
Examples found in repository?
src/config.rs (line 32)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
pub fn get_array(&self, cop: &str, key: &str) -> Vec<String> {
let cop_config = &self.0[&Yaml::String(cop.to_string())];
let mut output: Vec<String> = vec![];
match &cop_config[key] {
Yaml::Array(array) => {
for item in array {
if let Yaml::String(string) = item {
output.push(string.clone());
} else {
panic!("item has to be string");
}
}
}
Yaml::BadValue => {
return self.get_array("AllCops", key);
}
_ => (),
}
output
}More examples
src/target_finder.rs (line 16)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
pub fn scan() -> types::TargetFilesMap {
// TODO: there is a lot of space to optimize this function
let cops = COPS.lock().unwrap();
let mut target_files: types::TargetFilesMap = HashMap::new();
for cop in cops.iter() {
if CONFIG.is_enabled(cop) {
let mut patterns = CONFIG.get_array(cop, "Include");
for exclude in CONFIG.get_array(cop, "Exclude") {
let string = String::from("!") + &exclude;
patterns.push(string);
}
let walker = globwalk::GlobWalkerBuilder::from_patterns(".", &patterns)
.file_type(globwalk::FileType::FILE)
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);
for file in walker {
let entry = target_files
.entry(file.path().display().to_string())
.or_insert(HashSet::new());
entry.insert(cop);
}
}
}
target_files
}sourcepub fn get_string(&self, cop: &str, key: &str) -> String
pub fn get_string(&self, cop: &str, key: &str) -> String
Examples found in repository?
src/cop/style/alias.rs (line 19)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
pub fn on_alias(node: &types::Node, file: &source::File) {
if CONFIG.get_string(COP_NAME, "EnforcedStyle") == "prefer_alias_method" {
if let types::Node::Alias(node) = node {
file.add_offense(COP_NAME, node.expression_l, MSG_ALIAS_METHOD);
}
}
}
pub fn on_alias_method(node: &types::Node, file: &source::File) {
if CONFIG.get_string(COP_NAME, "EnforcedStyle") == "prefer_alias" {
if let types::Node::Send(node) = node {
file.add_offense(COP_NAME, node.expression_l, MSG_ALIAS);
}
}
}sourcepub fn is_enabled(&self, cop: &str) -> bool
pub fn is_enabled(&self, cop: &str) -> bool
Examples found in repository?
src/target_finder.rs (line 15)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
pub fn scan() -> types::TargetFilesMap {
// TODO: there is a lot of space to optimize this function
let cops = COPS.lock().unwrap();
let mut target_files: types::TargetFilesMap = HashMap::new();
for cop in cops.iter() {
if CONFIG.is_enabled(cop) {
let mut patterns = CONFIG.get_array(cop, "Include");
for exclude in CONFIG.get_array(cop, "Exclude") {
let string = String::from("!") + &exclude;
patterns.push(string);
}
let walker = globwalk::GlobWalkerBuilder::from_patterns(".", &patterns)
.file_type(globwalk::FileType::FILE)
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);
for file in walker {
let entry = target_files
.entry(file.path().display().to_string())
.or_insert(HashSet::new());
entry.insert(cop);
}
}
}
target_files
}