Skip to content

Commit

Permalink
style: fix clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Yaroslav Bolyukin <[email protected]>
  • Loading branch information
CertainLach committed Nov 27, 2021
1 parent b118a83 commit cff8f6a
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions crates/jrsonnet-evaluator/src/builtin/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,40 +189,19 @@ fn yaml_needs_quotes(string: &str) -> bool {
string.starts_with(' ') || string.ends_with(' ')
}

string == ""
string.is_empty()
|| need_quotes_spaces(string)
|| string.starts_with(|character: char| match character {
'&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' => true,
_ => false,
}) || string.contains(|character: char| match character {
':'
| '{'
| '}'
| '['
| ']'
| ','
| '#'
| '`'
| '\"'
| '\''
| '\\'
| '\0'..='\x06'
| '\t'
| '\n'
| '\r'
| '\x0e'..='\x1a'
| '\x1c'..='\x1f' => true,
_ => false,
}) || [
// http://yaml.org/type/bool.html
// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse
// them as string, not booleans, although it is violating the YAML 1.1 specification.
// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.
"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",
"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html
"null", "Null", "NULL", "~",
]
.contains(&string)
|| string.starts_with(|c| matches!(c, '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@'))
|| string.contains(|c| matches!(c, ':' | '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0'..='\x06' | '\t' | '\n' | '\r' | '\x0e'..='\x1a' | '\x1c'..='\x1f'))
|| [
// http://yaml.org/type/bool.html
// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse
// them as string, not booleans, although it is violating the YAML 1.1 specification.
// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.
"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",
"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html
"null", "Null", "NULL", "~",
].contains(&string)
|| (string.chars().all(|c| matches!(c, '0'..='9' | '-'))
&& string.chars().filter(|c| *c == '-').count() == 2)
|| string.starts_with('.')
Expand Down Expand Up @@ -262,8 +241,8 @@ fn manifest_yaml_ex_buf(
buf.push_str(options.padding);
buf.push_str(line);
}
} else if !options.quote_keys && !yaml_needs_quotes(&s) {
buf.push_str(&s);
} else if !options.quote_keys && !yaml_needs_quotes(s) {
buf.push_str(s);
} else {
escape_string_json_buf(s, buf);
}
Expand Down Expand Up @@ -311,8 +290,8 @@ fn manifest_yaml_ex_buf(
buf.push('\n');
buf.push_str(cur_padding);
}
if !options.quote_keys && !yaml_needs_quotes(&key) {
buf.push_str(&key);
if !options.quote_keys && !yaml_needs_quotes(key) {
buf.push_str(key);
} else {
escape_string_json_buf(key, buf);
}
Expand Down

0 comments on commit cff8f6a

Please sign in to comment.