Skip to content

Commit cff8f6a

Browse files
committed
style: fix clippy warnings
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
1 parent b118a83 commit cff8f6a

1 file changed

Lines changed: 16 additions & 37 deletions

File tree

crates/jrsonnet-evaluator/src/builtin/manifest.rs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -189,40 +189,19 @@ fn yaml_needs_quotes(string: &str) -> bool {
189189
string.starts_with(' ') || string.ends_with(' ')
190190
}
191191

192-
string == ""
192+
string.is_empty()
193193
|| need_quotes_spaces(string)
194-
|| string.starts_with(|character: char| match character {
195-
'&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' => true,
196-
_ => false,
197-
}) || string.contains(|character: char| match character {
198-
':'
199-
| '{'
200-
| '}'
201-
| '['
202-
| ']'
203-
| ','
204-
| '#'
205-
| '`'
206-
| '\"'
207-
| '\''
208-
| '\\'
209-
| '\0'..='\x06'
210-
| '\t'
211-
| '\n'
212-
| '\r'
213-
| '\x0e'..='\x1a'
214-
| '\x1c'..='\x1f' => true,
215-
_ => false,
216-
}) || [
217-
// http://yaml.org/type/bool.html
218-
// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse
219-
// them as string, not booleans, although it is violating the YAML 1.1 specification.
220-
// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.
221-
"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",
222-
"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html
223-
"null", "Null", "NULL", "~",
224-
]
225-
.contains(&string)
194+
|| string.starts_with(|c| matches!(c, '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@'))
195+
|| string.contains(|c| matches!(c, ':' | '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0'..='\x06' | '\t' | '\n' | '\r' | '\x0e'..='\x1a' | '\x1c'..='\x1f'))
196+
|| [
197+
// http://yaml.org/type/bool.html
198+
// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse
199+
// them as string, not booleans, although it is violating the YAML 1.1 specification.
200+
// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.
201+
"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",
202+
"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html
203+
"null", "Null", "NULL", "~",
204+
].contains(&string)
226205
|| (string.chars().all(|c| matches!(c, '0'..='9' | '-'))
227206
&& string.chars().filter(|c| *c == '-').count() == 2)
228207
|| string.starts_with('.')
@@ -262,8 +241,8 @@ fn manifest_yaml_ex_buf(
262241
buf.push_str(options.padding);
263242
buf.push_str(line);
264243
}
265-
} else if !options.quote_keys && !yaml_needs_quotes(&s) {
266-
buf.push_str(&s);
244+
} else if !options.quote_keys && !yaml_needs_quotes(s) {
245+
buf.push_str(s);
267246
} else {
268247
escape_string_json_buf(s, buf);
269248
}
@@ -311,8 +290,8 @@ fn manifest_yaml_ex_buf(
311290
buf.push('\n');
312291
buf.push_str(cur_padding);
313292
}
314-
if !options.quote_keys && !yaml_needs_quotes(&key) {
315-
buf.push_str(&key);
293+
if !options.quote_keys && !yaml_needs_quotes(key) {
294+
buf.push_str(key);
316295
} else {
317296
escape_string_json_buf(key, buf);
318297
}

0 commit comments

Comments
 (0)