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

Conversation

taxmeifyoucan
Copy link
Member

Adds exception in the lint for relative links. Quick solution with additional regex allows links pointing to github.com/ethereum/consensus-specs.

@@ -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.

@taxmeifyoucan
Copy link
Member Author

Added more restrictive rules and tested on all possible combinations. Now it only allows relative paths and URLs in format https://(www.)github.com/ethereum/consensus-specs/blob/commit_hash/something

@@ -23,15 +23,19 @@ 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 re = Regex::new(r"(^/)|(://)|(^www)|^(\w)+\.(\w)+").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this treat [hello](www) as a relative link?

Copy link
Member Author

@taxmeifyoucan taxmeifyoucan Nov 5, 2022

Choose a reason for hiding this comment

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

No, that is not allowed, should it work? I can specify it as www in front of a domain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think [hello](www) will turn into hello. On this particular PR that expands to https://github.com/ethereum/eipw/pull/www.

@SamWilsn SamWilsn merged commit 614fd8d into ethereum:master Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants