feat: add revert-useless-changes tool with functional programming design#2268
feat: add revert-useless-changes tool with functional programming design#2268
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 <noreply@anthropic.com>
chore: update lock
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, '')); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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: