-
Notifications
You must be signed in to change notification settings - Fork 0
Implement dynamic AST validation suite with adaptive pattern discovery for code standardization #24
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@copilot let's work on develop branch instead of the main. |
Switched to develop branch! I've created a new branch |
Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
|
@copilot we don't have manager classes anymore. Also, we should not hardcode the class names. Let's do an overhaul to address this. |
…amic discovery - Replace hardcoded manager class validation with dynamic pattern discovery - Categorize managers by type (Workspace, Storage, Other) for context-aware validation - Discover actual patterns used (cleanup vs dispose) instead of enforcing rigid rules - Reduce false positives from 6 errors to 2 legitimate issues - Add comprehensive documentation of the overhaul approach - Validation now adapts to actual codebase architecture instead of enforcing outdated assumptions Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
Addressed the hardcoded manager class assumptions with a comprehensive overhaul (commit 03d176a). Key changes:
Results:
The validation now discovers and adapts to your actual architecture instead of enforcing rigid, outdated rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot We are using pnpm instead of npm. Please update
Updated all documentation to use pnpm instead of npm commands (commit 5b8d7c2). Changed references in:
All validation commands now consistently show |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive AST-based validation suite that discovers and validates actual architectural patterns in the codebase, replacing hardcoded assumptions with adaptive pattern recognition. The system now dynamically analyzes the codebase to understand existing patterns and validates consistency rather than enforcing rigid rules.
Key changes:
- Dynamic Pattern Discovery: Replaced hardcoded validation rules with pattern discovery that learns from the actual codebase
- Context-Aware Validation: Different validation rules for different component types (workspace, storage, service managers)
- Comprehensive AST Analysis: New validation scripts for TypeScript best practices, testing standards, and security/performance patterns
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/validate-typescript-best-practices-ast.js |
New AST-based TypeScript validation checking type safety, async patterns, and documentation |
scripts/validate-testing-standards-ast.js |
New test validation script enforcing test structure, isolation, and assertion patterns |
scripts/validate-security-performance-ast.js |
New security and performance validation detecting vulnerabilities and anti-patterns |
scripts/validate-architecture-patterns-ast.js |
Completely rewritten architecture validation with dynamic pattern discovery |
scripts/validate-all-ast.js |
New orchestrator script coordinating all validation scripts with CLI options |
package.json |
Updated scripts to use new AST-based validation suite |
docs/DYNAMIC_VALIDATION_OVERHAUL.md |
Documentation explaining the overhaul from hardcoded to dynamic validation |
docs/AST_VALIDATION_GUIDE.md |
Comprehensive guide for using the new AST validation suite |
| const lineNum = getLineNumber(sourceFile, node); | ||
|
|
||
| // Check for 'any' type usage - use safer checking | ||
| if (isTypeReferenceSafe(node) && isAnyType(node)) { |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for detecting 'any' type usage is incorrect. isTypeReferenceSafe checks if a node is a TypeReferenceNode, but isAnyType checks for AnyKeyword. These are mutually exclusive - an AnyKeyword is not a TypeReferenceNode.
| if (isTypeReferenceSafe(node) && isAnyType(node)) { | |
| if (isAnyType(node)) { |
| const lineNum = getLineNumber(sourceFile, node); | ||
|
|
||
| // Check type parameters for proper constraints | ||
| if (ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)) { |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition 'ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)' is redundant. The first part checks if the function exists, but since TypeScript compiler API is being used, this check is unnecessary and the second condition is sufficient.
| if (ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)) { | |
| if (ts.isTypeParameterDeclaration(node)) { |
| }); | ||
| } | ||
|
|
||
| if ((hasFileSystemOperations || hasProcessCwdUsage || hasEnvVarChanges) && !hasProperCleanup) { |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hasProperCleanup variable only checks for afterEach calls but doesn't verify if they actually contain cleanup code. This could lead to false negatives where afterEach exists but doesn't perform the necessary cleanup.
| const parent = node.parent; | ||
| while (parent) { |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This while loop traverses up the parent chain without a termination condition other than reaching null. This could potentially cause an infinite loop if there's a circular reference in the AST (though unlikely with TypeScript AST).
| const parent = node.parent; | |
| while (parent) { | |
| const parent = node.parent; | |
| const visitedNodes = new Set(); | |
| while (parent) { | |
| if (visitedNodes.has(parent)) { | |
| break; // Break the loop if a circular reference is detected | |
| } | |
| visitedNodes.add(parent); |
| }); | ||
| break; | ||
| } | ||
| parent = parent.parent; |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parent traversal should have a safety check to prevent potential infinite loops. While TypeScript AST shouldn't have circular references, it's a defensive programming practice.
| "tsx": "^4.0.0" | ||
| }, | ||
| "packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad" | ||
| } |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The packageManager field was removed from package.json, which could cause issues with package manager version consistency across different environments.
| } | |
| }, | |
| "packageManager": "pnpm@8.6.0" |
This PR implements a comprehensive AST-based validation suite that discovers and validates actual architectural patterns in the codebase, replacing hardcoded assumptions with adaptive pattern recognition.
🔄 Major Overhaul: Dynamic Pattern Discovery
The validation system now discovers actual patterns used in the codebase instead of enforcing rigid, hardcoded rules that don't match the current architecture.
Key Innovation: Context-Aware Validation
Before (Hardcoded):
After (Dynamic Discovery):
🎯 Real-World Impact
Validation Results Comparison
Before: 6 false positive errors
After: 2 legitimate issues + useful insights
🔍 Validation Suite Components
Dynamic Architecture Patterns (
validate-architecture-patterns-ast.js) - COMPLETELY REWRITTENTypeScript Best Practices (
validate-typescript-best-practices-ast.js)anyusage, unsafe assertions)Testing Standards (
validate-testing-standards-ast.js)Security & Performance (
validate-security-performance-ast.js)Import Patterns (
validate-imports.js)🚀 Usage
📊 Benefits for AI Development
The validation suite now works with your architecture instead of against it, providing meaningful guidance that helps maintain code quality while respecting legitimate architectural choices.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.