Skip to content

Replace fragile string matching with robust configuration-based code example generation#28

Merged
BorDevTech merged 2 commits into
mainfrom
copilot/fix-27
Sep 21, 2025
Merged

Replace fragile string matching with robust configuration-based code example generation#28
BorDevTech merged 2 commits into
mainfrom
copilot/fix-27

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 21, 2025

The code example generation in the lint automation system was using fragile string matching against error messages, which could break if ESLint message formats change. This PR refactors the system to use a more robust, configuration-based approach.

Problem

The generateCodeExample method in scripts/lint-automation/github-issue-creator.ts relied on hardcoded string matching like:

if (issue.message.includes('VetRecord') || unusedName.includes('VetRecord')) {
  // Hardcoded example for VetRecord
} else if (issue.message.includes('searchParams') || unusedName.includes('searchParams')) {
  // Hardcoded example for searchParams  
} else if (issue.message.includes('parseBlob')) {
  // Hardcoded example for parseBlob
}

This approach was brittle because:

  • It would break if ESLint changed error message formats
  • Required exact string matches for specific identifiers
  • Was difficult to maintain and extend
  • Only worked for hardcoded identifier names

Solution

Replaced the fragile string matching with a robust configuration-based system:

1. Regex-based Identifier Extraction

identifierPattern: /'([^']+)' is (defined but never used|assigned a value but never used)/

2. Context-Aware Pattern Detection

contextPatterns: [
  { pattern: /interface\s+\w+/i, exampleType: 'interface' },
  { pattern: /const\s+{\s*\w+\s*}\s*=.*URL/i, exampleType: 'url-destructuring' },
  { pattern: /const\s+\w+\s*=.*["']\w+["']/i, exampleType: 'string-constant' }
]

3. Generic Example Generators

Examples now work with any identifier name and adapt based on detected context, not hardcoded strings.

Benefits

  • Resilient: No longer breaks if ESLint message formats change
  • Maintainable: Clear configuration structure for adding new rules
  • Flexible: Works with any identifier names, not just specific hardcoded ones
  • Context-Aware: Generates appropriate examples based on code patterns
  • Extensible: Easy to add support for new ESLint rules

Testing

Comprehensive testing confirmed:

  • All fragile string matching patterns successfully removed
  • System works with arbitrary identifier names (e.g., DatabaseConfig, mySpecialVariable)
  • Context detection properly identifies interfaces, URL destructuring, etc.
  • End-to-end lint automation process continues working correctly

Fixes #27.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clear-view Error Error Sep 21, 2025 11:03pm

…example generation

Co-authored-by: BorDevTech <73800053+BorDevTech@users.noreply.github.com>
Copilot AI changed the title [WIP] The code example generation relies on string matching against error messages, which is fragile and could break if error message formats change. Consider using more robust pattern matching or a configuration-based approach to map rule patterns to examples. Replace fragile string matching with robust configuration-based code example generation Sep 21, 2025
Copilot AI requested a review from BorDevTech September 21, 2025 23:03
@BorDevTech BorDevTech marked this pull request as ready for review September 21, 2025 23:06
Copilot AI review requested due to automatic review settings September 21, 2025 23:06
@BorDevTech BorDevTech merged commit bb42572 into main Sep 21, 2025
1 of 2 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors lint automation code example generation from fragile string checks to a configuration-driven, context-aware approach to improve resilience and maintainability.

  • Introduces ExampleConfig with identifierPattern and contextPatterns to extract identifiers and infer context from source.
  • Updates exampleGenerator signature to accept context and adds new generators for several rules (e.g., no-unused-vars, no-explicit-any, no-unused-imports).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread scripts/lint-automation/github-issue-creator.ts
Comment thread scripts/lint-automation/github-issue-creator.ts
Comment thread scripts/lint-automation/github-issue-creator.ts
Comment thread scripts/lint-automation/github-issue-creator.ts
Comment thread scripts/lint-automation/github-issue-creator.ts
@BorDevTech BorDevTech deleted the copilot/fix-27 branch September 21, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants