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 +4 -4
- data/lib/yerba/version.rb +1 -1
- data/rust/Cargo.toml +1 -1
- data/rust/src/document/style.rs +17 -0
- data/rust/src/yerbafile.rs +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb111282dd32e6a5bf4f79fc20fb71b1e4f40f56424b27ee74d14e581ca4f645
|
|
4
|
+
data.tar.gz: 6e3e5e7066e624e3263beaee6c76cebfc02c4ab645c282bfc8760264f5e19ae3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d489126e1fbec945069ad81e6b16775a562133364a9a196061d7024248c155ef72e11c73ffcd292bf69ddf601545ba32087cce155d64f3673a91487b2a0a0d1
|
|
7
|
+
data.tar.gz: 75403eab424bfd79654703fc43640ee45f5e8b9f0142805e4fce938bb27c5bc510046d602ccd1a8c2be082c749a29454fd15aae2f1b2de90c05c6d22bd04dd0a
|
data/lib/yerba/version.rb
CHANGED
data/rust/Cargo.toml
CHANGED
data/rust/src/document/style.rs
CHANGED
|
@@ -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(());
|
data/rust/src/yerbafile.rs
CHANGED
|
@@ -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 {
|