Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lints to ensure link text for EIPs should match the EIP's number #99

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
initial markdown-link-eip
  • Loading branch information
KatyaRyazantseva committed May 30, 2024
commit fd7cebb36b6c8ff1c62172191bcd6a5c06baa4c9
4 changes: 4 additions & 0 deletions eipw-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ pub fn default_lints_enum() -> impl Iterator<Item = (&'static str, DefaultLint<&
message: "proposals must be referenced with the form `EIP-N` (not `EIPN` or `EIP N`)",
}),
),
(
"markdown-link-eip",
MarkdownLinkEip(markdown::LinkEip(r"(?i)(?:eip|erc)-[0-9]+"))
),
(
"markdown-link-first",
MarkdownLinkFirst {
Expand Down
6 changes: 6 additions & 0 deletions eipw-lint/src/lints/known_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum DefaultLint<S> {

MarkdownHtmlComments(markdown::HtmlComments<S>),
MarkdownJsonSchema(markdown::JsonSchema<S>),
MarkdownLinkEip(markdown::LinkEip<S>),
MarkdownLinkFirst {
pattern: markdown::LinkFirst<S>,
},
Expand Down Expand Up @@ -102,6 +103,7 @@ where

Self::MarkdownHtmlComments(l) => Box::new(l),
Self::MarkdownJsonSchema(l) => Box::new(l),
Self::MarkdownLinkEip(l) => Box::new(l),
Self::MarkdownLinkFirst { pattern } => Box::new(pattern),
Self::MarkdownLinkStatus(l) => Box::new(l),
Self::MarkdownProposalRef(l) => Box::new(l),
Expand Down Expand Up @@ -141,6 +143,7 @@ where

Self::MarkdownHtmlComments(l) => l,
Self::MarkdownJsonSchema(l) => l,
Self::MarkdownLinkEip(l) => l,
Self::MarkdownLinkFirst { pattern } => pattern,
Self::MarkdownLinkStatus(l) => l,
Self::MarkdownProposalRef(l) => l,
Expand Down Expand Up @@ -257,6 +260,9 @@ where
.map(|(a, b)| (a.as_ref(), b.as_ref()))
.collect(),
}),
Self::MarkdownLinkEip (l) => DefaultLint::MarkdownLinkEip(markdown::LinkEip (
l.as_ref(),
)),
Self::MarkdownLinkFirst { pattern } => DefaultLint::MarkdownLinkFirst {
pattern: markdown::LinkFirst(pattern.0.as_ref()),
},
Expand Down
2 changes: 2 additions & 0 deletions eipw-lint/src/lints/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pub mod headings_space;
pub mod html_comments;
pub mod json_schema;
pub mod link_eip;
pub mod link_first;
pub mod link_status;
pub mod proposal_ref;
Expand All @@ -18,6 +19,7 @@ pub mod section_required;
pub use self::headings_space::HeadingsSpace;
pub use self::html_comments::HtmlComments;
pub use self::json_schema::JsonSchema;
pub use self::link_eip::LinkEip;
pub use self::link_first::LinkFirst;
pub use self::link_status::LinkStatus;
pub use self::proposal_ref::ProposalRef;
Expand Down
32 changes: 32 additions & 0 deletions eipw-lint/src/lints/markdown/link_eip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

// use annotate_snippets::snippet::{Annotation, Slice, Snippet};

// use comrak::nodes::{Ast, AstNode, NodeCode, NodeCodeBlock, NodeHtmlBlock};

use crate::lints::{Context, Error, Lint}; // FetchContext
// use crate::tree::{self, Next, TraverseExt};

// use regex::Regex;

use serde::{Deserialize, Serialize};

// use std::collections::HashSet;
use std::fmt::{Debug, Display};
// use std::path::PathBuf;

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct LinkEip<S>(pub S);

impl<S> Lint for LinkEip<S>
where
S: Display + Debug + AsRef<str>,
{
fn lint<'a>(&self, slug: &'a str, ctx: &Context<'a, '_>) -> Result<(), Error> {
Ok(())
}
}
28 changes: 28 additions & 0 deletions eipw-lint/tests/lint_markdown_link_eip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use eipw_lint::lints::markdown::LinkEip;
use eipw_lint::reporters::Text;
use eipw_lint::Linter;

#[tokio::test]
async fn link_matches_the_pattern() {
let src = r#"---
header: value1
---
[EIP-1](./eip-2.md)
"#;
let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-link-eip", LinkEip("EIP-1"))
.check_slice(None, src)
.run()
.await
.unwrap()
.into_inner();

// assert_eq!(reports, "");
}