- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.5k
 
feat: add revert-useless-changes tool with functional programming design #2268
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
base: main
Are you sure you want to change the base?
Conversation
…programming design Implement a comprehensive tool to automatically detect and revert files with only cosmetic changes (whitespace or comments) in Git repositories. Features: - Functional programming architecture with pure functions - Rule-based analysis system (whitespace and AST comment detection) - Commander.js CLI with comprehensive options - ESM module system throughout - Proper handling of new/added files - TypeScript with strict typing - Comprehensive documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
chore: update lock
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 adds a comprehensive "revert-useless-changes" tool designed with functional programming principles to automatically detect and revert files with only cosmetic changes (whitespace or comments) in Git repositories.
- Implements a rule-based analysis system with two built-in rules: whitespace-only changes and comment-only changes using AST comparison
 - Provides both CLI and programmatic API with TypeScript support and comprehensive error handling
 - Features extensible architecture allowing easy addition of new analysis rules and output formats
 
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description | 
|---|---|
revert-useless-changes/utils/git.ts | 
Core Git operations for file analysis and reversion | 
revert-useless-changes/utils/file.ts | 
File system utilities for reading, pattern matching, and path operations | 
revert-useless-changes/types.ts | 
Complete type definitions for configuration, analysis results, and rule interfaces | 
revert-useless-changes/rules/whitespace-rule.ts | 
Rule implementation for detecting whitespace-only changes using Git diff | 
revert-useless-changes/rules/ast-comment-rule.ts | 
Rule implementation for detecting comment-only changes via AST parsing | 
revert-useless-changes/rules/index.ts | 
Rule registry and pattern matching system | 
revert-useless-changes/reporter.ts | 
Console and JSON output formatting with progress logging | 
revert-useless-changes/orchestrator.ts | 
Main workflow coordination and file analysis orchestration | 
revert-useless-changes/index.ts | 
Public API exports and programmatic interface | 
revert-useless-changes/config.ts | 
Configuration constants and default values | 
revert-useless-changes/cli.ts | 
Command-line interface implementation using Commander.js | 
revert-useless-changes/README.md | 
Comprehensive documentation of architecture and usage | 
revert-useless-changes.js | 
Entry point script using Sucrase for TypeScript compilation | 
package.json | 
Updated dependencies and build scripts for the new tool | 
.gitignore | 
Build output directory exclusions | 
Files not reviewed (1)
- common/autoinstallers/rush-commands/pnpm-lock.yaml: Language not supported
 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| loc: true, | ||
| range: true, | ||
| comment: true, | ||
| ecmaVersion: 'latest' as any, | 
    
      
    
      Copilot
AI
    
    
    
      Sep 25, 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.
Using 'as any' defeats TypeScript's type safety. Consider using a specific ECMAScript version number like 2022 or checking the @typescript-eslint/parser documentation for valid ecmaVersion values.
| ecmaVersion: 'latest' as any, | |
| ecmaVersion: 2022, | 
| }); | ||
| allMatches.push(...matches); | ||
| } catch (error) { | ||
| console.warn(`Warning: Failed to match pattern ${pattern}:`, error); | 
    
      
    
      Copilot
AI
    
    
    
      Sep 25, 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.
Direct console.warn usage bypasses the centralized logging system. Consider using a logger parameter or the reporter module's logWarning function for consistent error handling.
| 
               | 
          ||
| // More complex pattern matching could be implemented here | ||
| // For now, we'll use simple string matching | ||
| return filePath.includes(pattern.replace(/\*\*/g, '').replace(/\*/g, '')); | 
    
      
    
      Copilot
AI
    
    
    
      Sep 25, 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 pattern matching implementation is incorrect. Removing all wildcards and using string.includes() will produce false matches. For example, pattern '*.txt' would match 'file.txt.backup' incorrectly.
| // More complex pattern matching could be implemented here | ||
| return false; | 
    
      
    
      Copilot
AI
    
    
    
      Sep 25, 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 matchesPattern function is incomplete - it only handles '**/*' and simple extension patterns but returns false for all other cases. This could cause rules to not apply to files they should match.
What type of PR is this?
Check the PR title.
(Optional) Translate the PR title into Chinese.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
zh(optional):
(Optional) Which issue(s) this PR fixes: