diff --git a/Makefile b/Makefile index afb961b..67a8fc9 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,6 @@ dockerclippy: clippy: > cargo clippy --no-deps --all-targets --all-features -- -D warnings -.PHONY: clippyfix -clippyfix: -> cargo clippy --fix --lib -p organic --all-features - .PHONY: test test: > cargo test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS) diff --git a/docker/organic_clippy/Makefile b/docker/organic_clippy/Makefile index 9546365..6e9fb21 100644 --- a/docker/organic_clippy/Makefile +++ b/docker/organic_clippy/Makefile @@ -25,13 +25,13 @@ ifdef REMOTE_REPO else @echo "REMOTE_REPO not defined, not removing from remote repo." endif - docker volume rm cargo-cache + docker volume rm rust-cache cargo-cache # NOTE: This target will write to folders underneath the git-root .PHONY: run run: build - docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME) + docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) .PHONY: shell shell: build - docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME) + docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 1632da5..3d40dd9 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -655,7 +655,7 @@ pub(crate) fn compare_property_number_lines< (Some(number_lines), Some(rust_number_lines)) => { let token_list = number_lines.as_list()?; let number_type = token_list - .get(0) + .first() .map(Token::as_atom) .map_or(Ok(None), |r| r.map(Some))? .ok_or(":number-lines should have a type.")?; diff --git a/src/compare/diff.rs b/src/compare/diff.rs index b5cc269..e6a6506 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2153,7 +2153,7 @@ fn compare_plain_text<'b, 's>( let text = emacs.as_text()?; let start_ind: usize = text .properties - .get(0) + .first() .expect("Should have start index.") .as_atom()? .parse()?; diff --git a/src/parser/bullshitium.rs b/src/parser/bullshitium.rs index 4e562d7..1757fcb 100644 --- a/src/parser/bullshitium.rs +++ b/src/parser/bullshitium.rs @@ -15,10 +15,8 @@ use crate::context::RefContext; use crate::error::CustomError; use crate::error::Res; use crate::parser::macros::element; -use crate::types::AffiliatedKeywords; use crate::types::Object; use crate::types::Paragraph; -use crate::types::PlainText; #[cfg_attr( feature = "tracing", @@ -80,13 +78,10 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>( Ok(( remaining, - Paragraph { - source: input.get_until(remaining).into(), - affiliated_keywords: AffiliatedKeywords::default(), - children: vec![Object::PlainText(PlainText { - source: input.get_until(lead_in_remaining).into(), - })], - }, + Paragraph::of_text( + input.get_until(remaining).into(), + input.get_until(lead_in_remaining).into(), + ), )) } } @@ -139,13 +134,10 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>( Ok(( remaining, - Paragraph { - source: input.get_until(remaining).into(), - affiliated_keywords: AffiliatedKeywords::default(), - children: vec![Object::PlainText(PlainText { - source: input.get_until(lead_in_remaining).into(), - })], - }, + Paragraph::of_text( + input.get_until(remaining).into(), + input.get_until(lead_in_remaining).into(), + ), )) } } diff --git a/src/parser/citation.rs b/src/parser/citation.rs index cf562fb..ffccb20 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -235,7 +235,7 @@ mod tests { assert_eq!( first_paragraph .children - .get(0) + .first() .expect("Len already asserted to be 1"), &Object::Citation(Citation { source: "[cite:@foo]", diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index d440f54..ecbc618 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -31,7 +31,6 @@ use crate::types::Drawer; use crate::types::Element; use crate::types::Keyword; use crate::types::Paragraph; -use crate::types::SetSource; #[cfg_attr( feature = "tracing", @@ -81,9 +80,8 @@ where ))(remaining) { Ok((remain, (_not_immediate_exit, first_line, (_trailing_whitespace, _exit_contents)))) => { - let mut element = Element::Paragraph(Paragraph::of_text(first_line.into())); let source = get_consumed(remaining, remain); - element.set_source(source.into()); + let element = Element::Paragraph(Paragraph::of_text(source.into(), first_line.into())); (remain, vec![element]) } Err(_) => { diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 9a8e1cb..e1eb68b 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -37,7 +37,6 @@ use crate::types::DynamicBlock; use crate::types::Element; use crate::types::Keyword; use crate::types::Paragraph; -use crate::types::SetSource; #[cfg_attr( feature = "tracing", @@ -88,9 +87,7 @@ where ))))(remaining)?; let leading_blank_lines = leading_blank_lines.map(|(source, (first_line, _remaining_lines))| { - let mut element = Element::Paragraph(Paragraph::of_text(first_line.into())); - element.set_source(source.into()); - element + Element::Paragraph(Paragraph::of_text(source.into(), first_line.into())) }); let (remaining, (mut children, _exit_contents)) = many_till(element_matcher, exit_matcher)(remaining)?; diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 8fe1182..c8b8d77 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -39,7 +39,6 @@ use crate::types::Element; use crate::types::Keyword; use crate::types::Paragraph; use crate::types::QuoteBlock; -use crate::types::SetSource; use crate::types::SpecialBlock; #[cfg_attr( @@ -257,9 +256,7 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>( ))))(remaining)?; let leading_blank_lines = leading_blank_lines.map(|(source, (first_line, _remaining_lines))| { - let mut element = Element::Paragraph(Paragraph::of_text(first_line.into())); - element.set_source(source.into()); - element + Element::Paragraph(Paragraph::of_text(source.into(), first_line.into())) }); let (remaining, (mut children, _exit_contents)) = many_till(element_matcher, exit_matcher)(remaining)?; diff --git a/src/types/element.rs b/src/types/element.rs index ab5d655..19e7ca9 100644 --- a/src/types/element.rs +++ b/src/types/element.rs @@ -22,7 +22,6 @@ use super::CenterBlock; use super::Drawer; use super::GetStandardProperties; use super::QuoteBlock; -use super::SetSource; use super::SpecialBlock; use super::StandardProperties; @@ -55,38 +54,6 @@ pub enum Element<'s> { LatexEnvironment(LatexEnvironment<'s>), } -impl<'s> SetSource<'s> for Element<'s> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] - fn set_source(&mut self, source: &'s str) { - match self { - Element::Paragraph(obj) => obj.source = source, - Element::PlainList(obj) => obj.source = source, - Element::CenterBlock(obj) => obj.source = source, - Element::QuoteBlock(obj) => obj.source = source, - Element::SpecialBlock(obj) => obj.source = source, - Element::DynamicBlock(obj) => obj.source = source, - Element::FootnoteDefinition(obj) => obj.source = source, - Element::Comment(obj) => obj.source = source, - Element::Drawer(obj) => obj.source = source, - Element::PropertyDrawer(obj) => obj.source = source, - Element::Table(obj) => obj.source = source, - Element::VerseBlock(obj) => obj.source = source, - Element::CommentBlock(obj) => obj.source = source, - Element::ExampleBlock(obj) => obj.source = source, - Element::ExportBlock(obj) => obj.source = source, - Element::SrcBlock(obj) => obj.source = source, - Element::Clock(obj) => obj.source = source, - Element::DiarySexp(obj) => obj.source = source, - Element::Planning(obj) => obj.source = source, - Element::FixedWidthArea(obj) => obj.source = source, - Element::HorizontalRule(obj) => obj.source = source, - Element::Keyword(obj) => obj.source = source, - Element::BabelCall(obj) => obj.source = source, - Element::LatexEnvironment(obj) => obj.source = source, - } - } -} - impl<'s> GetStandardProperties<'s> for Element<'s> { fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> { match self { diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 83badc5..5eea3b5 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -169,11 +169,11 @@ impl<'s> Paragraph<'s> { /// Generate a paragraph of the passed in text with no additional properties. /// /// This is used for elements that support an "empty" content like greater blocks. - pub(crate) fn of_text(input: &'s str) -> Self { + pub(crate) fn of_text(source: &'s str, body: &'s str) -> Self { Paragraph { - source: input, + source, affiliated_keywords: AffiliatedKeywords::default(), - children: vec![Object::PlainText(PlainText { source: input })], + children: vec![Object::PlainText(PlainText { source: body })], } } } diff --git a/src/types/mod.rs b/src/types/mod.rs index dbce299..d42ce25 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -7,7 +7,6 @@ mod greater_element; mod lesser_element; mod macros; mod object; -mod source; mod standard_properties; mod util; pub use affiliated_keyword::AffiliatedKeyword; @@ -113,5 +112,4 @@ pub use object::WarningDelay; pub use object::WarningDelayType; pub use object::Year; pub use object::YearInner; -pub(crate) use source::SetSource; pub use standard_properties::StandardProperties; diff --git a/src/types/source.rs b/src/types/source.rs deleted file mode 100644 index d953c45..0000000 --- a/src/types/source.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub(crate) trait SetSource<'s> { - fn set_source(&mut self, source: &'s str); -}