yerba 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/yerba/version.rb +1 -1
- data/rust/Cargo.toml +1 -1
- data/rust/src/document/mod.rs +31 -3
- data/rust/src/document/style.rs +28 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 348708380a914448a30474477d2134dd552422af8f09b291e0aaccc5b9a31c68
|
|
4
|
+
data.tar.gz: 2daa3d76bd50762c592fce4c325cdbe29b693bb3ee20b2c7e17ab66bc4231ba7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcf5266c9f6382480b9bdc209cb17cfd2479ff0e2807cf55726f89baf0ec860ac878e012273569a382592ab3cc1a9d695078946c38530229743e6e289916d1f9
|
|
7
|
+
data.tar.gz: 04102f3e431b582d9e4dd122dd33b3c5056105d1f3db96d9ed2cda6f36d7fff58bd02d251e9568d303101357ad96f6cb2e5b64dceab2af37af9af9528632e174
|
data/lib/yerba/version.rb
CHANGED
data/rust/Cargo.toml
CHANGED
data/rust/src/document/mod.rs
CHANGED
|
@@ -47,8 +47,8 @@ use crate::QuoteStyle;
|
|
|
47
47
|
use crate::syntax::{
|
|
48
48
|
column_at, dedent_block_scalar, extract_scalar, extract_scalar_text, find_block_map, find_block_sequence, find_entry_by_key, find_flow_entry_by_key,
|
|
49
49
|
find_flow_map, find_flow_sequence, find_scalar_token, first_collection, flow_map_entries, flow_sequence_entries, format_scalar_value, in_flow_collection,
|
|
50
|
-
is_map_key, is_yaml_non_string, line_at, line_start_at,
|
|
51
|
-
FirstCollection, LineIndex, ScalarValue,
|
|
50
|
+
is_map_key, is_yaml_non_string, line_at, line_start_at, needs_quoting, needs_quoting_in_flow, preceding_whitespace_indent, preceding_whitespace_token,
|
|
51
|
+
raw_scalar_value, removal_range, FirstCollection, LineIndex, ScalarValue,
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
#[derive(Debug, Clone)]
|
|
@@ -889,7 +889,7 @@ impl EntryGroup {
|
|
|
889
889
|
pub(crate) fn collect_blank_line_edits(node: &SyntaxNode, blank_lines: usize, edits: &mut Vec<(TextRange, String)>) {
|
|
890
890
|
use crate::syntax::preceding_whitespace_token;
|
|
891
891
|
|
|
892
|
-
if let Some(whitespace_token) = preceding_whitespace_token(node) {
|
|
892
|
+
if let Some(whitespace_token) = preceding_whitespace_token(node).map(leading_comment_whitespace) {
|
|
893
893
|
let whitespace_text = whitespace_token.text();
|
|
894
894
|
let newline_count = whitespace_text.chars().filter(|character| *character == '\n').count();
|
|
895
895
|
|
|
@@ -905,6 +905,34 @@ pub(crate) fn collect_blank_line_edits(node: &SyntaxNode, blank_lines: usize, ed
|
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
|
|
908
|
+
fn leading_comment_whitespace(whitespace_token: SyntaxToken) -> SyntaxToken {
|
|
909
|
+
let mut current = whitespace_token;
|
|
910
|
+
|
|
911
|
+
loop {
|
|
912
|
+
if current.text().matches('\n').count() != 1 {
|
|
913
|
+
return current;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
let Some(comment) = current.prev_sibling_or_token().and_then(|sibling| sibling.into_token()) else {
|
|
917
|
+
return current;
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
if comment.kind() != SyntaxKind::COMMENT {
|
|
921
|
+
return current;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
let Some(previous) = comment.prev_sibling_or_token().and_then(|sibling| sibling.into_token()) else {
|
|
925
|
+
return current;
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
if previous.kind() != SyntaxKind::WHITESPACE || !previous.text().contains('\n') {
|
|
929
|
+
return current;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
current = previous;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
908
936
|
fn collect_entry_groups(parent: &SyntaxNode) -> Vec<EntryGroup> {
|
|
909
937
|
let mut groups: Vec<EntryGroup> = Vec::new();
|
|
910
938
|
let mut buffer = String::new();
|
data/rust/src/document/style.rs
CHANGED
|
@@ -193,7 +193,7 @@ impl Document {
|
|
|
193
193
|
continue;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
let new_text = match inline_quote_replacement(&raw_value, current_kind, value_style) {
|
|
196
|
+
let new_text = match inline_quote_replacement(&raw_value, current_kind, value_style, token_in_flow_collection(token)) {
|
|
197
197
|
Some(new_text) => new_text,
|
|
198
198
|
None => continue,
|
|
199
199
|
};
|
|
@@ -910,10 +910,19 @@ impl Document {
|
|
|
910
910
|
}
|
|
911
911
|
|
|
912
912
|
QuoteStyle::Plain => {
|
|
913
|
-
|
|
913
|
+
let has_special_characters = trimmed.contains(':') || trimmed.contains('#') || trimmed.contains('"') || trimmed.contains('\'');
|
|
914
|
+
|
|
915
|
+
if is_multiline || has_special_characters || needs_quoting(trimmed) {
|
|
914
916
|
let offset: usize = token.text_range().start().into();
|
|
915
917
|
let line = line_at(&source, offset);
|
|
916
|
-
|
|
918
|
+
|
|
919
|
+
let reason = if is_multiline {
|
|
920
|
+
"multiline content"
|
|
921
|
+
} else if has_special_characters {
|
|
922
|
+
"special characters"
|
|
923
|
+
} else {
|
|
924
|
+
"a value that needs quotes"
|
|
925
|
+
};
|
|
917
926
|
|
|
918
927
|
warnings.push(format!("line {}: skipped block scalar → plain ({} can't be plain)", line, reason));
|
|
919
928
|
|
|
@@ -981,7 +990,7 @@ impl Document {
|
|
|
981
990
|
continue;
|
|
982
991
|
}
|
|
983
992
|
|
|
984
|
-
let new_text = match inline_quote_replacement(&raw_value, current_kind, style) {
|
|
993
|
+
let new_text = match inline_quote_replacement(&raw_value, current_kind, style, token_in_flow_collection(&token)) {
|
|
985
994
|
Some(new_text) => new_text,
|
|
986
995
|
None => continue,
|
|
987
996
|
};
|
|
@@ -1046,7 +1055,11 @@ fn block_scalar_indent(line_prefix: &str) -> usize {
|
|
|
1046
1055
|
column + 2
|
|
1047
1056
|
}
|
|
1048
1057
|
|
|
1049
|
-
fn
|
|
1058
|
+
fn token_in_flow_collection(token: &SyntaxToken) -> bool {
|
|
1059
|
+
token.parent().is_some_and(|parent| in_flow_collection(&parent))
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
fn inline_quote_replacement(raw_value: &str, current_kind: SyntaxKind, style: &QuoteStyle, in_flow: bool) -> Option<String> {
|
|
1050
1063
|
match style {
|
|
1051
1064
|
QuoteStyle::Double => {
|
|
1052
1065
|
if raw_value.contains('"') && current_kind == SyntaxKind::SINGLE_QUOTED_SCALAR {
|
|
@@ -1063,6 +1076,16 @@ fn inline_quote_replacement(raw_value: &str, current_kind: SyntaxKind, style: &Q
|
|
|
1063
1076
|
return None;
|
|
1064
1077
|
}
|
|
1065
1078
|
|
|
1079
|
+
let needs_quotes = if in_flow {
|
|
1080
|
+
needs_quoting_in_flow(raw_value)
|
|
1081
|
+
} else {
|
|
1082
|
+
needs_quoting(raw_value)
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
if needs_quotes {
|
|
1086
|
+
return None;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1066
1089
|
Some(raw_value.to_string())
|
|
1067
1090
|
}
|
|
1068
1091
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yerba
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
117
117
|
- !ruby/object:Gem::Version
|
|
118
118
|
version: '0'
|
|
119
119
|
requirements: []
|
|
120
|
-
rubygems_version: 4.0.
|
|
120
|
+
rubygems_version: 4.0.20
|
|
121
121
|
specification_version: 4
|
|
122
122
|
summary: YAML Editing and Refactoring with Better Accuracy
|
|
123
123
|
test_files: []
|