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

Allow external links for consensus-specs repo #52

Merged
merged 4 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion eipw-lint/src/lints/markdown/relative_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ pub struct RelativeLinks;
impl Lint for RelativeLinks {
fn lint<'a, 'b>(&self, slug: &'a str, ctx: &Context<'a, 'b>) -> Result<(), Error> {
let re = Regex::new("(^/)|(://)").unwrap();
let cs_re = Regex::new(
"^https://(www\\.)?github\\.com/ethereum/consensus-specs/blob/[a-f0-9]{40}/.+$",
)
.unwrap();

let mut visitor = Visitor::default();
ctx.body().traverse().visit(&mut visitor)?;

let links = visitor
.links
.into_iter()
.filter(|l| re.is_match(&l.address));
.filter(|l| re.is_match(&l.address) && !cs_re.is_match(&l.address));

for Link { line_start, .. } in links {
ctx.report(Snippet {
Expand Down
21 changes: 21 additions & 0 deletions eipw-lint/tests/lint_markdown_relative_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ use eipw_lint::lints::markdown::RelativeLinks;
use eipw_lint::reporters::Text;
use eipw_lint::Linter;

#[tokio::test]
async fn inline_link_to_consensus_specs() {
let src = r#"---
header: value1
---

[hi](https://github.com/ethereum/consensus-specs/blob/6c2b46ae3248760e0f6e52d61077d8b31e43ad1d/specs/eip4844/validator.md#compute_aggregated_poly_and_commitment)
"#;

let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-rel", RelativeLinks)
.check_slice(None, src)
.run()
.await
.unwrap()
.into_inner();

assert_eq!(reports, "");
}

#[tokio::test]
async fn inline_link_with_scheme() {
let src = r#"---
Expand Down