Skip to content

Commit

Permalink
WIP: test passed valid_code_in_backticks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickish authored and Vickish committed Aug 22, 2024
1 parent a9415aa commit 1a7ccf3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
69 changes: 35 additions & 34 deletions eipw-lint/src/lints/markdown/no_backticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,43 @@
found_backticks: bool,
}

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
fn check(&mut self, ast: &Ast, text: &str) -> Result<Next, Error> {
if text.starts_with('`') && text.ends_with('`') {
let inner_text = &text[1..text.len() - 1];
if self.re.is_match(inner_text) {
self.found_backticks = true;
let footer_label = format!("the pattern in question: `{}`", self.pattern);
let source = self.ctx.source_for_text(ast.sourcepos.start.line, text);
self.ctx.report(Snippet {
opt: Default::default(),
title: Some(Annotation {
annotation_type: self.ctx.annotation_type(),
id: Some(self.slug),
label: Some("EIP references should not be in backticks"),
}),
slices: vec![Slice {
fold: false,
line_start: ast.sourcepos.start.line,
origin: self.ctx.origin(),
source: &source,
annotations: vec![],
}],
footer: vec![Annotation {
annotation_type: AnnotationType::Help,
id: None,
label: Some(&footer_label),
}],
})?;
return Ok(Next::SkipChildren);
}
println!("Checking text: {}", text);
// Remove the condition that checks for backticks at the start and end
if self.re.is_match(text) {
println!("Regex matched!");
self.found_backticks = true;
let footer_label = format!("the pattern in question: `{}`", self.pattern);
let source = self.ctx.source_for_text(ast.sourcepos.start.line, text);
self.ctx.report(Snippet {
opt: Default::default(),
title: Some(Annotation {
annotation_type: self.ctx.annotation_type(),
id: Some(self.slug),
label: Some("EIP references should not be in backticks"),
}),
slices: vec![Slice {
fold: false,
line_start: ast.sourcepos.start.line,
origin: self.ctx.origin(),
source: &source,
annotations: vec![],
}],
footer: vec![Annotation {
annotation_type: AnnotationType::Help,
id: None,
label: Some(&footer_label),
}],
})?;
return Ok(Next::SkipChildren);
}
Ok(Next::TraverseChildren)
}
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {

type Error = Error;

fn enter_front_matter(&mut self, _: &Ast, _: &str) -> Result<Next, Self::Error> {
Expand Down Expand Up @@ -112,8 +113,8 @@
}

fn enter_text(&mut self, ast: &Ast, txt: &str) -> Result<Next, Self::Error> {
self.check(ast, txt)
}
self.check(ast, txt)
}

fn enter_link(&mut self, _: &Ast, _: &NodeLink) -> Result<Next, Self::Error> {
Ok(Next::TraverseChildren)
Expand Down
67 changes: 39 additions & 28 deletions eipw-lint/tests/lint_markdown_no_backticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,56 @@
use eipw_lint::reporters::Text;
use eipw_lint::Linter;

#[tokio::test]
async fn eip_in_backticks() {
#[tokio::test]
async fn eip_in_backticks() {
let src = r#"---
header: value1
---
hello
`EIP-1234`
"#;

let reports = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"))
.check_slice(None, src)
.run()
.await
.unwrap()
.into_inner();

assert_eq!(
reports,
r#"error[markdown-no-backticks]: EIP references should not be in backticks
|
5 | `EIP-1234`
|
= info: the pattern in question: `EIP-[0-9]+`
"#
);
}
let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

println!("Source text:\n{}", src);
println!("Linter configuration: {:?}", linter);

let reports = linter
.check_slice(None, src)
.run()
.await
.unwrap()
.into_inner();

println!("Actual reports: {:?}", reports);

assert_eq!(
reports,
r#"error[markdown-no-backticks]: EIP references should not be in backticks
--> 7:1
|
7 | `EIP-1234`
| ^^^^^^^^^^
|
= info: the pattern in question: `EIP-[0-9]+`
"#
);
}

#[tokio::test]
async fn valid_code_in_backticks() {
let src = r#"---
header: value1
---
hello
`ERC20` and `IERC7777`
"#;
let src = r#"---
header: value1
---
hello
`ERC20` and `IERC7777`
"#;

let reports = Linter::<Text<String>>::default()
.clear_lints()
Expand Down

0 comments on commit 1a7ccf3

Please sign in to comment.