yerba 0.8.0 → 0.9.0
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/README.md +170 -19
- data/ext/yerba/include/yerba.h +7 -0
- data/ext/yerba/yerba.c +54 -5
- data/lib/yerba/formatting.rb +9 -13
- data/lib/yerba/map.rb +11 -8
- data/lib/yerba/sequence.rb +2 -7
- data/lib/yerba/version.rb +1 -1
- data/rust/Cargo.toml +15 -6
- data/rust/src/commands/blank_lines.rs +23 -3
- data/rust/src/commands/directives.rs +4 -4
- data/rust/src/commands/get.rs +7 -10
- data/rust/src/commands/init.rs +10 -4
- data/rust/src/commands/insert.rs +18 -12
- data/rust/src/commands/location.rs +2 -2
- data/rust/src/commands/mate.rs +7 -7
- data/rust/src/commands/mod.rs +118 -90
- data/rust/src/commands/move_key.rs +9 -6
- data/rust/src/commands/quote_style.rs +4 -5
- data/rust/src/commands/schema.rs +6 -6
- data/rust/src/commands/selectors.rs +2 -2
- data/rust/src/commands/set.rs +18 -7
- data/rust/src/commands/sort.rs +36 -42
- data/rust/src/commands/sort_keys.rs +2 -2
- data/rust/src/commands/ui.rs +156 -0
- data/rust/src/commands/unique.rs +7 -7
- data/rust/src/commands/version.rs +13 -3
- data/rust/src/document/insert.rs +25 -9
- data/rust/src/document/mod.rs +7 -3
- data/rust/src/document/set.rs +115 -33
- data/rust/src/document/style.rs +131 -11
- data/rust/src/error.rs +27 -0
- data/rust/src/ffi.rs +55 -12
- data/rust/src/lib.rs +12 -2
- data/rust/src/quote_style.rs +12 -11
- data/rust/src/syntax.rs +285 -11
- data/rust/src/validation.rs +30 -0
- data/rust/src/yaml_writer.rs +9 -21
- data/rust/src/yerbafile.rs +76 -4
- metadata +3 -1
data/rust/src/yerbafile.rs
CHANGED
|
@@ -42,6 +42,7 @@ pub enum PipelineStep {
|
|
|
42
42
|
Unique(UniqueConfig),
|
|
43
43
|
Schema(SchemaConfig),
|
|
44
44
|
FinalNewline(FinalNewlineConfig),
|
|
45
|
+
Escapes(EscapesConfig),
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
#[derive(Debug, Clone, Deserialize)]
|
|
@@ -59,6 +60,12 @@ pub struct BlankLinesConfig {
|
|
|
59
60
|
#[serde(default)]
|
|
60
61
|
pub path: Option<String>,
|
|
61
62
|
pub count: usize,
|
|
63
|
+
#[serde(default)]
|
|
64
|
+
pub before: Vec<String>,
|
|
65
|
+
#[serde(default)]
|
|
66
|
+
pub after: Vec<String>,
|
|
67
|
+
#[serde(default)]
|
|
68
|
+
pub skip_empty: bool,
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
#[derive(Debug, Clone, Deserialize)]
|
|
@@ -102,6 +109,12 @@ pub struct FinalNewlineConfig {
|
|
|
102
109
|
pub count: usize,
|
|
103
110
|
}
|
|
104
111
|
|
|
112
|
+
#[derive(Debug, Clone, Deserialize)]
|
|
113
|
+
pub struct EscapesConfig {
|
|
114
|
+
#[serde(default)]
|
|
115
|
+
pub path: Option<String>,
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
fn default_one() -> usize {
|
|
106
119
|
1
|
|
107
120
|
}
|
|
@@ -199,13 +212,18 @@ impl<'de> Deserialize<'de> for PipelineStep {
|
|
|
199
212
|
return Ok(PipelineStep::Schema(config));
|
|
200
213
|
}
|
|
201
214
|
|
|
215
|
+
if let Some(value) = mapping.get(yaml_serde::Value::String("escapes".to_string())) {
|
|
216
|
+
let config: EscapesConfig = yaml_serde::from_value(value.clone()).map_err(serde::de::Error::custom)?;
|
|
217
|
+
return Ok(PipelineStep::Escapes(config));
|
|
218
|
+
}
|
|
219
|
+
|
|
202
220
|
if let Some(value) = mapping.get(yaml_serde::Value::String("final_newline".to_string())) {
|
|
203
221
|
let config: FinalNewlineConfig = yaml_serde::from_value(value.clone()).map_err(serde::de::Error::custom)?;
|
|
204
222
|
return Ok(PipelineStep::FinalNewline(config));
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
Err(serde::de::Error::custom(
|
|
208
|
-
"unknown pipeline step: expected sort_keys, quote_style, collection_style, sequence_indent, set, insert, delete, rename, remove, blank_lines, sort, directives, unique, schema, or final_newline",
|
|
226
|
+
"unknown pipeline step: expected sort_keys, quote_style, collection_style, sequence_indent, set, insert, delete, rename, remove, blank_lines, sort, directives, unique, schema, escapes, or final_newline",
|
|
209
227
|
))
|
|
210
228
|
}
|
|
211
229
|
}
|
|
@@ -246,6 +264,8 @@ pub struct SetConfig {
|
|
|
246
264
|
pub value: String,
|
|
247
265
|
#[serde(default)]
|
|
248
266
|
pub condition: Option<String>,
|
|
267
|
+
#[serde(default)]
|
|
268
|
+
pub plain: bool,
|
|
249
269
|
}
|
|
250
270
|
|
|
251
271
|
#[derive(Debug, Clone, Deserialize)]
|
|
@@ -254,6 +274,8 @@ pub struct InsertConfig {
|
|
|
254
274
|
pub value: String,
|
|
255
275
|
#[serde(default)]
|
|
256
276
|
pub condition: Option<String>,
|
|
277
|
+
#[serde(default)]
|
|
278
|
+
pub plain: bool,
|
|
257
279
|
}
|
|
258
280
|
|
|
259
281
|
#[derive(Debug, Clone, Deserialize)]
|
|
@@ -432,6 +454,14 @@ impl Yerbafile {
|
|
|
432
454
|
|
|
433
455
|
let original = document.to_string();
|
|
434
456
|
|
|
457
|
+
if let Some(error) = control_character_error(&original) {
|
|
458
|
+
return RuleResult {
|
|
459
|
+
file: file.to_string(),
|
|
460
|
+
changed: false,
|
|
461
|
+
error: Some(error),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
435
465
|
if run_global {
|
|
436
466
|
if let Err(error) = execute_pipeline(&mut document, &self.pipeline, None, file, self) {
|
|
437
467
|
return RuleResult {
|
|
@@ -513,6 +543,14 @@ impl Yerbafile {
|
|
|
513
543
|
|
|
514
544
|
let original = document.to_string();
|
|
515
545
|
|
|
546
|
+
if let Some(error) = control_character_error(&original) {
|
|
547
|
+
return RuleResult {
|
|
548
|
+
file: file.to_string(),
|
|
549
|
+
changed: false,
|
|
550
|
+
error: Some(error),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
516
554
|
if let Err(error) = execute_pipeline(&mut document, &self.pipeline, None, file, self) {
|
|
517
555
|
return RuleResult {
|
|
518
556
|
file: file.to_string(),
|
|
@@ -574,6 +612,11 @@ impl Yerbafile {
|
|
|
574
612
|
|
|
575
613
|
pub fn apply_to_document(&self, document: &mut Document, file_path: &str) -> Result<bool, YerbaError> {
|
|
576
614
|
let original = document.to_string();
|
|
615
|
+
|
|
616
|
+
if let Some(error) = control_character_error(&original) {
|
|
617
|
+
return Err(error);
|
|
618
|
+
}
|
|
619
|
+
|
|
577
620
|
let relative_path = self.relativize_path(file_path);
|
|
578
621
|
let match_path = relative_path.as_deref().unwrap_or(file_path);
|
|
579
622
|
|
|
@@ -603,6 +646,12 @@ impl Yerbafile {
|
|
|
603
646
|
}
|
|
604
647
|
}
|
|
605
648
|
|
|
649
|
+
fn control_character_error(source: &str) -> Option<YerbaError> {
|
|
650
|
+
let found = crate::validation::find_control_characters(source);
|
|
651
|
+
|
|
652
|
+
(!found.is_empty()).then_some(YerbaError::ControlCharacters(found))
|
|
653
|
+
}
|
|
654
|
+
|
|
606
655
|
fn execute_pipeline(document: &mut Document, steps: &[PipelineStep], base_path: Option<&str>, file: &str, yerbafile: &Yerbafile) -> Result<(), YerbaError> {
|
|
607
656
|
use crate::document::style::StyleEnforcement;
|
|
608
657
|
|
|
@@ -704,7 +753,11 @@ fn execute_step(document: &mut Document, step: &PipelineStep, base_path: Option<
|
|
|
704
753
|
}
|
|
705
754
|
}
|
|
706
755
|
|
|
707
|
-
|
|
756
|
+
if config.plain {
|
|
757
|
+
document.set_plain(&full_path, &config.value)
|
|
758
|
+
} else {
|
|
759
|
+
document.set(&full_path, &config.value)
|
|
760
|
+
}
|
|
708
761
|
}
|
|
709
762
|
|
|
710
763
|
PipelineStep::Insert(config) => {
|
|
@@ -718,7 +771,13 @@ fn execute_step(document: &mut Document, step: &PipelineStep, base_path: Option<
|
|
|
718
771
|
}
|
|
719
772
|
}
|
|
720
773
|
|
|
721
|
-
|
|
774
|
+
let value = if config.plain {
|
|
775
|
+
config.value.clone()
|
|
776
|
+
} else {
|
|
777
|
+
crate::syntax::quote_scalar(&config.value)
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
document.insert_into(&full_path, &value, crate::InsertPosition::Last)
|
|
722
781
|
}
|
|
723
782
|
|
|
724
783
|
PipelineStep::Delete(config) => {
|
|
@@ -784,7 +843,13 @@ fn execute_step(document: &mut Document, step: &PipelineStep, base_path: Option<
|
|
|
784
843
|
PipelineStep::BlankLines(config) => {
|
|
785
844
|
let full_path = resolve_step_path(base_path, config.path.as_deref());
|
|
786
845
|
|
|
787
|
-
|
|
846
|
+
let options = crate::BlankLineOptions {
|
|
847
|
+
before: config.before.clone(),
|
|
848
|
+
after: config.after.clone(),
|
|
849
|
+
skip_empty: config.skip_empty,
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
document.enforce_blank_lines_with(&full_path, config.count, &options)
|
|
788
853
|
}
|
|
789
854
|
|
|
790
855
|
PipelineStep::Sort(config) => {
|
|
@@ -848,6 +913,13 @@ fn execute_step(document: &mut Document, step: &PipelineStep, base_path: Option<
|
|
|
848
913
|
}
|
|
849
914
|
|
|
850
915
|
PipelineStep::FinalNewline(config) => document.enforce_final_newline(config.count),
|
|
916
|
+
|
|
917
|
+
PipelineStep::Escapes(config) => {
|
|
918
|
+
let full_path = resolve_step_path(base_path, config.path.as_deref());
|
|
919
|
+
let scope = if full_path.is_empty() { None } else { Some(full_path.as_str()) };
|
|
920
|
+
|
|
921
|
+
document.decode_escapes(scope).map(|_| ())
|
|
922
|
+
}
|
|
851
923
|
}
|
|
852
924
|
}
|
|
853
925
|
|
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.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- rust/src/commands/set.rs
|
|
64
64
|
- rust/src/commands/sort.rs
|
|
65
65
|
- rust/src/commands/sort_keys.rs
|
|
66
|
+
- rust/src/commands/ui.rs
|
|
66
67
|
- rust/src/commands/unique.rs
|
|
67
68
|
- rust/src/commands/version.rs
|
|
68
69
|
- rust/src/didyoumean.rs
|
|
@@ -85,6 +86,7 @@ files:
|
|
|
85
86
|
- rust/src/schema.rs
|
|
86
87
|
- rust/src/selector.rs
|
|
87
88
|
- rust/src/syntax.rs
|
|
89
|
+
- rust/src/validation.rs
|
|
88
90
|
- rust/src/yaml_writer.rs
|
|
89
91
|
- rust/src/yerbafile.rs
|
|
90
92
|
- sig/yerba.rbs
|