Skip to content

Commit

Permalink
Allow self reference without link
Browse files Browse the repository at this point in the history
  • Loading branch information
aslikaya committed Jul 13, 2024
1 parent 97e667a commit e7bb430
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.vscode
19 changes: 18 additions & 1 deletion eipw-lint/src/lints/markdown/link_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,25 @@ struct Visitor<'a, 'b, 'c> {

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
fn check(&self, ast: &Ast, text: &str) -> Result<Next, Error> {
let self_reference = {
let name = self
.ctx
.preamble()
.by_index(0)
.map(|field| field.name().trim())
.unwrap_or("");
let number = self
.ctx
.preamble()
.by_index(0)
.map(|field| field.value().trim())
.unwrap_or("");
let pattern = format!(r"(?i){}-{}$", name, number);
Regex::new(&pattern).unwrap().is_match(text)
};

for matched in self.re.find_iter(text) {
if self.linked.contains(matched.as_str()) {
if self.linked.contains(matched.as_str()) || self_reference {
continue;
}

Expand Down
23 changes: 23 additions & 0 deletions eipw-lint/tests/lint_markdown_link_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,26 @@ header: value1

assert_eq!(reports, "");
}

#[tokio::test]
async fn self_reference_unlinked() {
let src = r#"---
eip: 1234
---
EIP-1234
EIP-1234
"#;

let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-link-first", LinkFirst("EIP-1234"))
.check_slice(None, src)
.run()
.await
.unwrap()
.into_inner();

assert_eq!(reports, "");
}

0 comments on commit e7bb430

Please sign in to comment.