Skip to content

Commit

Permalink
refac: Implemented reviewed changes to maintain
Browse files Browse the repository at this point in the history
consistency and improve error message ergonomics.
  • Loading branch information
Abeeujah committed Nov 4, 2024
1 parent 97da96d commit 1e89703
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

pub mod headings_only;
pub mod heading_first;
pub mod headings_space;
pub mod html_comments;
pub mod json_schema;
Expand All @@ -17,7 +17,7 @@ pub mod relative_links;
pub mod section_order;
pub mod section_required;

pub use self::headings_only::HeadingsOnly;
pub use self::heading_first::HeadingFirst;
pub use self::headings_space::HeadingsSpace;
pub use self::html_comments::HtmlComments;
pub use self::json_schema::JsonSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@
*/

use comrak::nodes::NodeValue;
use eipw_snippets::Level;

use crate::lints::{Error, Lint};

#[derive(Debug)]
pub struct HeadingsOnly;
pub struct HeadingFirst;

impl Lint for HeadingsOnly {
impl Lint for HeadingFirst {
fn lint<'a>(&self, slug: &'a str, ctx: &crate::lints::Context<'a, '_>) -> Result<(), Error> {
let annotation_type = Level::Error;
let second = match ctx.body().descendants().nth(1) {
Some(el) => el.data.borrow().to_owned().value,
None => return ctx.report(annotation_type.title("Cannot submit an empty proposal")),
None => {
return ctx.report(
ctx.annotation_level()
.title("Cannot submit an empty proposal")
.id(slug),
)
}
};
match second {
NodeValue::Heading(_) => Ok(()),
_ => {
let annotation_type = Level::Error;
ctx.report(annotation_type.title("Only Heading is allowed after FrontMatter"))
}
_ => ctx.report(
ctx.annotation_level()
.title("Nothing is permitted between the preamble and the first heading")
.id(slug),
),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use eipw_lint::{lints::markdown::HeadingsOnly, reporters::Text, Linter};
use eipw_lint::{lints::markdown::HeadingFirst, reporters::Text, Linter};

#[tokio::test]
async fn invalid_eip() {
Expand All @@ -22,7 +22,7 @@ After the "Abstract" heading is the first place we want to allow text."#;

let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-headings-only", HeadingsOnly {})
.deny("markdown-headings-only", HeadingFirst {})
.check_slice(None, src)
.run()
.await
Expand All @@ -31,7 +31,7 @@ After the "Abstract" heading is the first place we want to allow text."#;

assert_eq!(
reports.trim(),
"error: Only Heading is allowed after FrontMatter"
"error[markdown-headings-only]: Nothing is permitted between the preamble and the first heading"
);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ Changing the denominator from 10 to 9 ensures that the block time remains roughl

let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-headings-only", HeadingsOnly {})
.deny("markdown-headings-only", HeadingFirst {})
.check_slice(None, src)
.run()
.await
Expand Down

0 comments on commit 1e89703

Please sign in to comment.