Skip to content

Commit

Permalink
test: Add comprehensive test cases for markdown-no-backticks
Browse files Browse the repository at this point in the history
- Add tests for image alt text handling
- Add tests for self-references
- Add tests for mixed contexts
- Add detailed documentation
  • Loading branch information
apeaircreative committed Jan 3, 2025
1 parent a1a616b commit 3535d72
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 0 deletions.
85 changes: 85 additions & 0 deletions docs/lints/markdown-no-backticks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# markdown-no-backticks

This lint ensures that EIP references (e.g., EIP-1234) are not wrapped in backticks. This helps maintain consistent formatting across all EIPs and follows the established community convention.

## Examples

### ❌ Invalid: Using backticks around EIP references

```markdown
This proposal builds on `EIP-1234` and `EIP-5678`.
```

### ✅ Valid: EIP references without backticks

```markdown
This proposal builds on EIP-1234 and EIP-5678.
```

## Behavior in Different Contexts

This lint enforces consistent behavior across all contexts. EIP references should never use backticks, regardless of where they appear:

1. Regular Text:
```markdown
// ❌ Incorrect
This implements `EIP-1234`.

// ✅ Correct
This implements EIP-1234.
```

2. Image Alt Text:
```markdown
// ❌ Incorrect
![Diagram of `EIP-1234` flow](diagram.png)

// ✅ Correct
![Diagram of EIP-1234 flow](diagram.png)
```

3. Self References:
```markdown
// ❌ Incorrect
This is `EIP-1234`, which defines...

// ✅ Correct
This is EIP-1234, which defines...
```

4. Technical Sections:
```markdown
// ❌ Incorrect
If `salt` is not provided, this EIP uses `EIP-6051` as default.

// ✅ Correct
If `salt` is not provided, this EIP uses EIP-6051 as default.
```

## Special Cases

1. Code Blocks: EIP references inside code blocks (``` ```) are allowed to use backticks, as they may be part of code examples:
```solidity
// This is fine
function implementEIP1234() {
// EIP-1234 implementation
}
```

2. Other Code References: Other technical references like function names, variables, or contract names should still use backticks:
```markdown
The function `implementERC20()` follows EIP-20.
```

## Rationale

EIP references are meant to be read as part of the text flow and are not code snippets. Using backticks around them:
1. Disrupts the reading flow
2. Incorrectly suggests they are code elements
3. Creates inconsistency in how EIPs are referenced across the documentation

This lint enforces the established community convention of treating EIP references as natural parts of the text, not as code elements. This convention is widely followed across the Ethereum ecosystem and helps maintain consistency in EIP documentation.

## Configuration

This lint uses a regular expression pattern to identify EIP references. By default, it matches the pattern `EIP-[0-9]+`.
168 changes: 168 additions & 0 deletions eipw-lint/tests/lint_markdown_no_backticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,171 @@ hello

assert_eq!(reports, "");
}

#[tokio::test]
async fn multiple_eip_references() {
let src = r#"---
header: value1
---
This document references `EIP-1234` and `EIP-5678` which should both be flagged.
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

assert!(reports.contains("EIP-1234"));
assert!(reports.contains("EIP-5678"));
}

#[tokio::test]
async fn eip_in_code_block() {
let src = r#"---
header: value1
---
Here's some code:
```solidity
// This is fine because it's in a code block
function implementEIP1234() {
// EIP-1234 implementation
}
```
But this `EIP-1234` should be flagged.
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

assert!(reports.contains("EIP-1234"));
assert_eq!(reports.matches("EIP-1234").count(), 1); // Only one instance should be flagged
}

#[tokio::test]
async fn eip_in_mixed_context() {
let src = r#"---
header: value1
---
| EIP | Description |
|-----|-------------|
| `EIP-1234` | Some description |
- Item 1: `EIP-5678`
- Item 2: Some `code` and `EIP-9012`
The function `doSomething()` implements `EIP-3456`.
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

assert!(reports.contains("EIP-1234"));
assert!(reports.contains("EIP-5678"));
assert!(reports.contains("EIP-9012"));
assert!(reports.contains("EIP-3456"));
}

#[tokio::test]
async fn mixed_code_and_eip_references() {
let src = r#"---
header: value1
---
The function `implementERC20()` follows `EIP-20` standard.
The class `MyToken` implements `EIP-721` for NFTs.
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

// Should flag EIP references in backticks
assert!(reports.contains("EIP-20"));
assert!(reports.contains("EIP-721"));

// The error message should mention backticks
assert!(reports.contains("proposal references should not be in backticks"));
}

#[tokio::test]
async fn eip_in_image_alt_text() {
let src = r#"---
header: value1
---
![This is `EIP-1234` in alt text](image.png)
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

// Should still flag EIP references in backticks, even in alt text
assert!(reports.contains("EIP-1234"));
}

#[tokio::test]
async fn self_reference_eip() {
let src = r#"---
eip: 1234
title: Test EIP
---
This is `EIP-1234` which is the current EIP.
"#;

let linter = Linter::<Text<String>>::default()
.clear_lints()
.deny("markdown-no-backticks", NoBackticks(r"EIP-[0-9]+"));

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

// Should flag EIP references in backticks, even for self-references
assert!(reports.contains("EIP-1234"));
}

0 comments on commit 3535d72

Please sign in to comment.