yerba 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63abf64d4cc9319d72226b4c0a01757e2ef3770f3b5eb5d50691f9dba8d5541c
4
- data.tar.gz: c809e6afbcf9dac67783853cab1b34017458204eadfc2a58bf82cf6b4d58afdd
3
+ metadata.gz: bb111282dd32e6a5bf4f79fc20fb71b1e4f40f56424b27ee74d14e581ca4f645
4
+ data.tar.gz: 6e3e5e7066e624e3263beaee6c76cebfc02c4ab645c282bfc8760264f5e19ae3
5
5
  SHA512:
6
- metadata.gz: a6df761da07e009e2207f66d1fdc745733e3575e3faa5a1708d7d51ac37f03ac5cbd0f567962ed8e747e79396eed486794131915c1cf5350d1e82dc6451a90f7
7
- data.tar.gz: ae74066e2fa54fc7e6eaa8defd68e786e18ab5bc871ba48996fb35536543fd7ef9f9e330d20855846a43d8e9718ba9d957a165c37c4391fcdb43984492f5d4b0
6
+ metadata.gz: 6d489126e1fbec945069ad81e6b16775a562133364a9a196061d7024248c155ef72e11c73ffcd292bf69ddf601545ba32087cce155d64f3673a91487b2a0a0d1
7
+ data.tar.gz: 75403eab424bfd79654703fc43640ee45f5e8b9f0142805e4fce938bb27c5bc510046d602ccd1a8c2be082c749a29454fd15aae2f1b2de90c05c6d22bd04dd0a
data/lib/yerba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yerba
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
data/rust/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "yerba"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  edition = "2021"
5
5
  authors = ["Marco Roth <marco.roth@intergga.ch>"]
6
6
  description = "YAML Editing and Refactoring with Better Accuracy"
@@ -674,6 +674,23 @@ impl Document {
674
674
  self.root.descendants_with_tokens().any(|element| element.kind() == SyntaxKind::DIRECTIVES_END)
675
675
  }
676
676
 
677
+ pub fn directive_locations(&self) -> Vec<(usize, usize)> {
678
+ let source = self.root.text().to_string();
679
+
680
+ self
681
+ .root
682
+ .descendants_with_tokens()
683
+ .filter(|element| element.kind() == SyntaxKind::DIRECTIVES_END)
684
+ .map(|element| {
685
+ let offset: usize = element.text_range().start().into();
686
+ let line = source[..offset].matches('\n').count() + 1;
687
+ let column = offset - source[..offset].rfind('\n').map(|position| position + 1).unwrap_or(0) + 1;
688
+
689
+ (line, column)
690
+ })
691
+ .collect()
692
+ }
693
+
677
694
  pub fn ensure_directives(&mut self) -> Result<(), YerbaError> {
678
695
  if self.has_directives_marker() {
679
696
  return Ok(());
@@ -66,6 +66,8 @@ pub struct DirectivesConfig {
66
66
  pub ensure: bool,
67
67
  #[serde(default)]
68
68
  pub remove: bool,
69
+ #[serde(default)]
70
+ pub max: Option<usize>,
69
71
  }
70
72
 
71
73
  #[derive(Debug, Clone, Deserialize)]
@@ -675,6 +677,21 @@ fn execute_step(document: &mut Document, step: &PipelineStep, base_path: Option<
675
677
  return Err(YerbaError::ParseError("directives: ensure and remove are mutually exclusive".to_string()));
676
678
  }
677
679
 
680
+ if let Some(max) = config.max {
681
+ let locations = document.directive_locations();
682
+
683
+ if locations.len() > max {
684
+ let positions: Vec<String> = locations.iter().map(|(line, col)| format!("{}:{}", line, col)).collect();
685
+
686
+ return Err(YerbaError::ParseError(format!(
687
+ "found {} directive markers (---) at {}, expected at most {}",
688
+ locations.len(),
689
+ positions.join(", "),
690
+ max
691
+ )));
692
+ }
693
+ }
694
+
678
695
  if config.ensure {
679
696
  document.ensure_directives()
680
697
  } else if config.remove {
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth