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
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
4 changes: 3 additions & 1 deletion eipw-lint/src/lints/markdown/relative_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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(r"^https://(www\.)?github\.com/ethereum/consensus-specs(/|$)").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the additional requirement that links to consensus specs include a specific commit, so this should only match URLs like:

https://github.com/ethereum/consensus-specs/blob/26695a9fdb747ecbe4f0bb9812fedbc402e5e18c/...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware, sorry about that. I will add it, just let me verify - it should point to a version of a file at some commit, therefore it has to be ../blob/.. or the commit itself, which would be .../commit/..?

Are there any other rules to follow? For example prefix, currently it allows all combinations with https:// or www or without

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've mentioned earlier! It's entirely my bad.

I suppose the best option would be https only, allow both with and without the www.

Links should go to specific files at a specific commit, so I think .../blob/... is what we want.


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