smart-renamer
v1.2.0
Published
π Intelligent file and code naming suggestions based on project-specific naming conventions. Interactive CLI tool with AST-based code analysis for variables, functions, components, and more.
Maintainers
Readme
Renamer
π Intelligent file and code naming suggestions based on project-specific naming conventions.
A TypeScript/Bun CLI tool that automatically detects, suggests, and validates naming patterns for both files and code. Analyzes variables, functions, components, constants, and more!
β¨ Features
File Operations
- π― Smart Convention Detection: Automatically detects naming patterns from existing files
- π Interactive Renaming: Ask yes/no for each file individually
- π« Smart Exclusions: Automatically skips config files, images, and declaration files
- π File Watcher: Monitor for new files and suggest names in real-time
Code Operations β NEW
- π» Code Analysis: Analyze variables, functions, components, constants in your codebase
- βοΈ React Component Detection: Automatically identifies React components
- π AST-Based Parsing: Deep code analysis using Babel parser
- β Code Validation: Validate naming conventions with detailed suggestions
General
- βοΈ Flexible Configuration: Store both file and code naming preferences
- π₯οΈ CLI Interface: Comprehensive command-line tool
- π Project Analysis: Analyze naming consistency across files and code
- π¨ Visual Feedback: Clear violation reports with suggestions
π¨ Supported Naming Conventions
File/Folder Conventions
camelCase: fileName.tssnake_case: file_name.tskebab-case: file-name.tsPascalCase: FileName.tsUPPER_SNAKE_CASE: FILE_NAME.ts
Code Conventions
- Variables:
camelCase(totalPrice, userName) - Functions:
camelCase(calculateShipping, processPayment) - Components:
PascalCase(UserCard, ProductList) - Constants:
UPPER_SNAKE_CASE(MAX_RETRY_COUNT, API_URL) - Classes:
PascalCase(PaymentProcessor, UserManager) - Interfaces:
PascalCase(UserProfile, ApiResponse) - Types:
PascalCase(PaymentStatus, OrderType) - Enums:
PascalCase(OrderStatus, UserRole)
π¦ Installation
npm install -g smart-renamer
# or
bun install -g smart-renamerπ Quick Start
# Initialize in your project (now includes code conventions!)
cd your-project
renamer init
# Analyze everything - files AND code patterns
renamer analyze
# Rename files interactively
renamer rename
# Validate code naming conventions
renamer validate-code --fixπ Commands
π― Core Commands
renamer analyze β Enhanced
Analyze both file and code naming patterns:
# Analyze everything (files + code)
renamer analyze
# Analyze only code naming patterns
renamer analyze --code-only
# Analyze only file naming patterns
renamer analyze --files-only
# Analyze specific file patterns
renamer analyze --patterns="src/**/*.ts,tests/*.ts"Example Output:
π Project Analysis
π File Naming Analysis
ββββββββββββββββββββββββββββββββββββββββ
π Total files: 45
π― Most common convention: kebab-case
π File consistency: 87.3%
π» Code Naming Analysis
ββββββββββββββββββββββββββββββββββββββββ
π» Total identifiers: 342
π Code consistency: 94.2%
π― Violations found: 8
π Code convention breakdown:
Variables (245 total):
β
camelCase 231 (94.3%)
snake_case 14 (5.7%)
Functions (58 total):
β
camelCase 58 (100.0%)
Components (23 total):
β
PascalCase 23 (100.0%)
π― Recommendations
ββββββββββββββββββββββββββββββββββββββββ
π» Code naming could be improved:
β’ Run `renamer validate-code --fix` to see code suggestionsrenamer init
Initialize with both file and code conventions:
renamer init
# Now asks about code conventions too!
# - Variables: camelCase, snake_case, etc.
# - Functions: camelCase, snake_case, etc.
# - Components: PascalCase (recommended)
# - Constants: UPPER_SNAKE_CASE, etc.π File Operations
renamer rename
Interactive file renaming:
# Interactive mode - asks yes/no for each file
renamer rename
# Preview what would be renamed
renamer rename --dry-run
# Rename all files without asking
renamer rename --force
# Keep specific files unchanged
renamer rename --keep "file1.js,file2.ts"renamer validate
Validate file names:
# Check all files
renamer validate
# Show suggested fixes
renamer validate --fixπ» Code Operations β NEW
renamer validate-code
Validate code naming conventions:
# Check code conventions
renamer validate-code
# Show detailed suggestions for violations
renamer validate-code --fix
# Check specific file patterns
renamer validate-code --patterns="src/**/*.ts"Example Output:
π Validating code conventions...
β Found 3 naming violations:
π src/components/user-card.tsx:
Line 15: variable "user_name" should be "userName"
π‘ Alternatives: PascalCase: UserName, kebab-case: user-name
π src/utils/payment.ts:
Line 8: function "process_payment" should be "processPayment"
π‘ Alternatives: PascalCase: ProcessPayment
π Total: 3 violations in 2 filesrenamer analyze-code
Detailed code analysis:
renamer analyze-codeπ§ Other Commands
renamer set-convention <convention>
renamer set-convention kebab-caserenamer suggest <filename>
renamer suggest "MyFileName.ts"renamer watch
renamer watchβοΈ Configuration
Create a naming.config file in your project root:
[naming]
convention=kebab-case
files=*.ts,*.js
folders=kebab-case
exceptions=index,main,app
[code]
variables=camelCase
functions=camelCase
components=PascalCase
constants=UPPER_SNAKE_CASE
classes=PascalCase
interfaces=PascalCase
types=PascalCase
enums=PascalCaseConfiguration Options
File Settings
convention: Primary file naming conventionfiles: File patterns to apply the convention tofolders: Naming convention for directoriesexceptions: Files that don't need to follow the convention
Code Settings β NEW
variables: Variable naming conventionfunctions: Function naming conventioncomponents: React component naming conventionconstants: Constant naming conventionclasses: Class naming conventioninterfaces: Interface naming conventiontypes: Type alias naming conventionenums: Enum naming convention
π« Smart Exclusions
The tool automatically skips these file types:
Automatically Excluded:
- Config files: Any file containing "config" (
next.config.mjs,webpack.config.js) - Image files:
.jpg,.png,.svg,.gif, etc. - Markdown files:
.md,.markdown - Declaration files (all languages):
- TypeScript:
.d.ts,.d.mts,.d.cts(likenext-env.d.ts,types.d.ts) - C/C++:
.h,.hpp,.hxx(header files) - Python:
.pyi(stub files) - And more:
.hi,.rbi,.rei,.mli,.sig,.fsi,.spec,.def
- TypeScript:
- System files:
package.json,tsconfig.json,.gitignore, etc. - Lock files:
package-lock.json,yarn.lock,bun.lockb
π Usage Examples
Typical Workflow
# 1. Initialize in your project (includes code conventions)
cd my-react-app
renamer init
# 2. Set up both file and code conventions
# Choose kebab-case for files, camelCase for variables, PascalCase for components
# 3. Analyze everything
renamer analyze
# Shows both file and code naming patterns
# 4. Fix file naming
renamer rename
# 5. Fix code naming
renamer validate-code --fix
# Shows exactly which variables/functions need renaming
# 6. Set up file watching for new files
renamer watchCode Analysis Example
$ renamer validate-code --fix
π Validating code conventions...
π Variables: camelCase
π§ Functions: camelCase
βοΈ Components: PascalCase
π Constants: UPPER_SNAKE_CASE
β Found 5 naming violations:
π src/components/user-profile.tsx:
Line 12: variable "user_data" should be "userData"
Line 25: function "render_avatar" should be "renderAvatar"
π‘ Alternatives: PascalCase: RenderAvatar
π src/utils/api-client.ts:
Line 8: constant "api_url" should be "API_URL"
Line 15: function "make_request" should be "makeRequest"
π Violation Summary:
variable: 2 violations
function: 2 violations
constant: 1 violations
π Total: 5 violations in 2 files
π‘ Use --fix to see suggested alternativesπ― Why Use Renamer?
- Consistency: Maintain consistent naming across files AND code
- Team Standards: Enforce team naming conventions for everything
- Code Quality: Improve codebase readability and maintainability
- React Support: Smart detection of React components
- Refactoring: Easily migrate from one naming style to another
- CI/CD Integration: Use in pipelines to ensure naming standards
π οΈ Tech Stack
- Runtime: Bun
- Language: TypeScript
- AST Parser: Babel Parser (for code analysis)
- CLI: Commander.js
- File Watching: Chokidar
- Interactive Prompts: Inquirer.js
π Package Update Instructions
To update your published package with the new code-level functionality:
1. Update Version
# Already done - version is now 1.1.0
npm version patch # or minor/major2. Build and Test
bun run build
bun test
bun run check # Test the new analyze command3. Publish to NPM
# Login if needed
npm login
# Publish the updated package
npm publish4. Verify Installation
# Test global installation
npm install -g smart-renamer@latest
# Test the new features
renamer --version # Should show 1.1.0
renamer analyze --help # Should show new options5. Update Documentation
The README is now updated with:
- β Code-level analysis features
- β
Enhanced
renamer analyzecommand - β New configuration options
- β Code validation examples
- β Complete usage workflows
Your package now offers comprehensive naming convention management for both files and code! π
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ for developers who care about consistent naming conventions in files AND code.
