Skip to content

Commit f996add

Browse files
(MAINT) Fix clippy for sshdconfig
1 parent 1b84d0f commit f996add

5 files changed

Lines changed: 20 additions & 30 deletions

File tree

resources/sshdconfig/src/export.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub fn invoke_export(input: Option<&String>, compare: bool) -> Result<Map<String
1919
let mut exist = false;
2020

2121
for (keyword, input_value) in &cmd_info.input {
22-
if !CanonicalProperties::is_canonical(keyword) {
23-
if let Some(actual_value) = result.get(keyword) {
22+
if !CanonicalProperties::is_canonical(keyword)
23+
&& let Some(actual_value) = result.get(keyword) {
2424
if let Value::Array(entries) = actual_value {
2525
// As more keywords are supported, different structured formats may be needed.
2626
if let Ok(entry) = serde_json::from_value::<NameValueEntry>(input_value.clone()) {
@@ -36,7 +36,6 @@ pub fn invoke_export(input: Option<&String>, compare: bool) -> Result<Map<String
3636
}
3737
}
3838
}
39-
}
4039
// The only result should be the input to match the expected output for DSC
4140
result.insert(keyword.clone(), input_value.clone());
4241
}

resources/sshdconfig/src/formatter.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ impl<'a> SshdConfigValue<'a> {
4141
));
4242
}
4343

44-
if let Value::Array(arr) = value {
45-
if arr.is_empty() {
46-
return Err(SshdConfigError::ParserError(
47-
t!("formatter.invalidValue", key = key).to_string()
48-
));
49-
}
44+
if let Value::Array(arr) = value && arr.is_empty() {
45+
return Err(SshdConfigError::ParserError(
46+
t!("formatter.invalidValue", key = key).to_string()
47+
));
5048
}
5149

5250
let mut keyword_info = KeywordInfo::from_keyword(key);

resources/sshdconfig/src/get.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ pub fn get_sshd_settings(cmd_info: &CommandInfo, is_get: bool) -> Result<Map<Str
144144
// Update inherited_defaults with any keys that are not explicitly set
145145
// check result for any keys that are in defaults
146146
for (key, value) in &result {
147-
if let Some(default) = defaults.get(key) {
148-
if default == value {
149-
inherited_defaults.push(key.clone());
150-
}
147+
if let Some(default) = defaults.get(key) && default == value {
148+
inherited_defaults.push(key.clone());
151149
}
152150
}
153151
} else {

resources/sshdconfig/src/parser.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,19 @@ impl SshdConfigParser {
180180
}
181181

182182
// Validate that structured keywords cannot use operators
183-
if let Some(ref info) = keyword_info {
184-
if !info.allows_operator() && operator.is_some() {
185-
return Err(SshdConfigError::ParserError(
186-
t!("parser.structuredKeywordCannotUseOperator", keyword = &info.name).to_string()
187-
));
188-
}
183+
if let Some(ref info) = keyword_info && !info.allows_operator() && operator.is_some() {
184+
return Err(SshdConfigError::ParserError(
185+
t!("parser.structuredKeywordCannotUseOperator", keyword = &info.name).to_string()
186+
));
189187
}
190188

191189
for node in keyword_node.named_children(&mut cursor) {
192190
if node.is_error() {
193191
return Err(SshdConfigError::ParserError(t!("parser.failedToParseNode", input = input).to_string()));
194192
}
195-
if node.kind() == "arguments" {
196-
if let Some(ref info) = keyword_info {
197-
value = parse_arguments_node(node, input, input_bytes, info)?;
198-
debug!("{}: {:?}", t!("parser.valueDebug").to_string(), value);
199-
}
193+
if node.kind() == "arguments" && let Some(ref info) = keyword_info {
194+
value = parse_arguments_node(node, input, input_bytes, info)?;
195+
debug!("{}: {:?}", t!("parser.valueDebug").to_string(), value);
200196
}
201197
}
202198

resources/sshdconfig/src/repeat_keyword.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ pub fn parse_and_validate_entries(entries_array: &[Value]) -> Result<Vec<NameVal
244244
/// or `None` if no matching entry exists.
245245
pub fn find_name_value_entry_index(keyword_array: &[Value], entry_name: &str, match_value: Option<&str>) -> Option<usize> {
246246
keyword_array.iter().position(|item| {
247-
if let Value::Object(obj) = item {
248-
if let Some(Value::String(name)) = obj.get("name") {
247+
if let Value::Object(obj) = item
248+
&& let Some(Value::String(name)) = obj.get("name") {
249249
if name != entry_name {
250250
return false;
251251
}
@@ -260,7 +260,7 @@ pub fn find_name_value_entry_index(keyword_array: &[Value], entry_name: &str, ma
260260

261261
return true;
262262
}
263-
}
263+
264264
false
265265
})
266266
}
@@ -324,9 +324,8 @@ pub fn add_or_update_entry(config: &mut Map<String, Value>, keyword: &str, entry
324324
/// * `keyword` - The keyword name (e.g., "subsystem")
325325
/// * `entry_name` - The name of the entry to remove
326326
pub fn remove_entry(config: &mut Map<String, Value>, keyword: &str, entry_name: &str) {
327-
if let Some(Value::Array(arr)) = config.get_mut(keyword) {
328-
if let Some(index) = find_name_value_entry_index(arr, entry_name, None) {
327+
if let Some(Value::Array(arr)) = config.get_mut(keyword)
328+
&& let Some(index) = find_name_value_entry_index(arr, entry_name, None) {
329329
arr.remove(index);
330330
}
331-
}
332331
}

0 commit comments

Comments
 (0)