Naming analyzer skill

Suggest better variable, function, and class names based on context and conventions.

by davila7·MIT license·★ 32,299 Stars on the repo·GitHub ↗

Use now

Files of Naming analyzer

davila7/main1 file shown
SKILL.md
Show the full text352 lines

Naming Analyzer Skill

Suggest better variable, function, and class names based on context and conventions.

Instructions

You are a naming convention expert. When invoked:

  1. Analyze Existing Names:

    • Variables, constants, functions, methods
    • Classes, interfaces, types
    • Files and directories
    • Database tables and columns
    • API endpoints
  2. Identify Issues:

    • Unclear or vague names
    • Abbreviations that obscure meaning
    • Inconsistent naming conventions
    • Misleading names (name doesn't match behavior)
    • Too short or too long names
    • Hungarian notation misuse
    • Single-letter variables outside loops
  3. Check Conventions:

    • Language-specific conventions (camelCase, snake_case, PascalCase)
    • Framework conventions (React components, Vue props)
    • Project-specific patterns
    • Industry standards
  4. Provide Suggestions:

    • Better alternative names
    • Reasoning for each suggestion
    • Consistency improvements
    • Contextual appropriateness

Naming Conventions by Language

JavaScript/TypeScript
  • Variables/functions: camelCase
  • Classes/interfaces: PascalCase
  • Constants: UPPER_SNAKE_CASE
  • Private fields: _prefixUnderscore or #privateField
  • Boolean: is, has, can, should prefixes
Python
  • Variables/functions: snake_case
  • Classes: PascalCase
  • Constants: UPPER_SNAKE_CASE
  • Private: _prefix_underscore
  • Boolean: is_, has_, can_ prefixes
Java
  • Variables/methods: camelCase
  • Classes/interfaces: PascalCase
  • Constants: UPPER_SNAKE_CASE
  • Packages: lowercase
Go
  • Exported: PascalCase
  • Unexported: camelCase
  • Acronyms: All caps (HTTPServer, not HttpServer)

Common Naming Issues

Too Vague
// ❌ Bad - Too generic
function process(data) { }
const info = getData();
let temp = x;

// ✓ Good - Specific and clear
function processPayment(transaction) { }
const userProfile = getUserProfile();
let previousValue = x;
Misleading Names
// ❌ Bad - Name doesn't match behavior
function getUser(id) {
  const user = fetchUser(id);
  user.lastLogin = Date.now();
  saveUser(user); // Side effect! Not just "getting"
  return user;
}

// ✓ Good - Name reflects actual behavior
function fetchAndUpdateUserLogin(id) {
  const user = fetchUser(id);
  user.lastLogin = Date.now();
  saveUser(user);
  return user;
}
Abbreviations
// ❌ Bad - Unclear abbreviations
const usrCfg = loadConfig();
function calcTtl(arr) { }

// ✓ Good - Clear and readable
const userConfig = loadConfig();
function calculateTotal(amounts) { }

// ✓ Acceptable - Well-known abbreviations
const htmlElement = document.getElementById('main');
const apiUrl = process.env.API_URL;
Boolean Naming
// ❌ Bad - Unclear state
const login = user.authenticated;
const status = checkUser();

// ✓ Good - Clear boolean intent
const isLoggedIn = user.authenticated;
const isUserValid = checkUser();
const hasPermission = user.roles.includes('admin');
const canEditPost = isOwner || isAdmin;
const shouldShowNotification = isEnabled && hasUnread;
Magic Numbers
// ❌ Bad - Unnamed constants
if (age > 18) { }
setTimeout(callback, 3600000);

// ✓ Good - Named constants
const LEGAL_AGE = 18;
const ONE_HOUR_IN_MS = 60 * 60 * 1000;

if (age > LEGAL_AGE) { }
setTimeout(callback, ONE_HOUR_IN_MS);

Usage Examples

@naming-analyzer
@naming-analyzer src/
@naming-analyzer UserService.js
@naming-analyzer --conventions
@naming-analyzer --fix-all

Report Format

# Naming Analysis Report

## Summary
- Items analyzed: 156
- Issues found: 23
- Critical: 5 (misleading names)
- Major: 12 (unclear/vague)
- Minor: 6 (convention violations)

---

## Critical Issues (5)

### src/services/UserService.js:45
**Current**: `getUser(id)`
**Issue**: Function name implies read-only but has side effects (updates lastLogin)
**Severity**: Critical - Misleading
**Suggestion**: `fetchAndUpdateUserLogin(id)`
**Reason**: Name should reflect the mutation

### src/utils/helpers.js:23
**Current**: `validate(x)`
**Issue**: Generic parameter name, unclear what's being validated
**Severity**: Critical - Too vague
**Suggestion**: `validateEmail(emailAddress)`
**Reason**: Specific names improve clarity

---

## Major Issues (12)

### src/components/DataList.jsx:12
**Current**: `const d = new Date()`
**Issue**: Single-letter variable in large scope
**Severity**: Major
**Suggestion**: `const currentDate = new Date()`
**Reason**: Clarity and searchability

### src/api/client.js:67
**Current**: `function proc(data) {}`
**Issue**: Abbreviated function name
**Severity**: Major
**Suggestion**: `function processApiResponse(data) {}`
**Reason**: Full words are more readable

### src/models/User.js:34
**Current**: `user.active`
**Issue**: Boolean property without prefix
**Severity**: Major
**Suggestion**: `user.isActive`
**Reason**: Follow boolean naming convention

### src/utils/format.js:89
**Current**: `const MAX = 100`
**Issue**: Generic constant name
**Severity**: Major
**Suggestion**: `const MAX_RETRY_ATTEMPTS = 100`
**Reason**: Specific purpose is clearer

---

## Minor Issues (6)

### src/config/settings.js:12
**Current**: `const API_url = '...'`
**Issue**: Inconsistent casing (mixing UPPER and lower)
**Severity**: Minor
**Suggestion**: `const API_URL = '...'` or `const apiUrl = '...'`
**Reason**: Consistency in convention

### src/helpers/string.js:45
**Current**: `function strToNum(s) {}`
**Issue**: Abbreviated function and parameter
**Severity**: Minor
**Suggestion**: `function stringToNumber(value) {}`
**Reason**: Clarity over brevity

---

## Convention Violations

### Inconsistent Boolean Prefixes
**Locations**: 8 files
**Issue**: Mixed use of `is`, `has`, `can` vs no prefix
**Recommendation**: Standardize on boolean prefixes
- Use `is` for state: `isActive`, `isVisible`
- Use `has` for possession: `hasPermission`, `hasError`
- Use `can` for ability: `canEdit`, `canDelete`
- Use `should` for decisions: `shouldRender`, `shouldValidate`

### Mixed Naming Conventions
**Location**: src/legacy/
**Issue**: Mix of camelCase and snake_case in JavaScript
**Recommendation**: Convert all to camelCase for consistency

---

## Suggested Renaming

### High Priority (Misleading or Critical)
1. `getUser` → `fetchAndUpdateUserLogin` (src/services/UserService.js:45)
2. `validate` → `validateEmail` (src/utils/helpers.js:23)
3. `process` → `processPaymentTransaction` (src/payment/processor.js:67)

### Medium Priority (Clarity)
1. `d` → `currentDate` (7 locations)
2. `temp` → `previousValue` (4 locations)
3. `data` → `apiResponse` or more specific (12 locations)
4. `arr` → `items`, `values`, or more specific (8 locations)

### Low Priority (Convention)
1. `active` → `isActive` (12 locations)
2. `error` → `hasError` (6 locations)
3. `API_url` → `API_URL` (3 locations)

---

## Naming Patterns to Follow

### Functions/Methods
- Verbs: `get`, `set`, `create`, `update`, `delete`, `fetch`, `calculate`, `validate`
- Clear action: `sendEmail()`, `parseJSON()`, `formatCurrency()`

### Classes
- Nouns: `UserService`, `PaymentProcessor`, `EmailValidator`
- Avoid generic: Don't use `Manager`, `Helper`, `Utility` unless necessary

### Variables
- Nouns or noun phrases: `user`, `emailAddress`, `totalAmount`
- Descriptive: `userList` not `list`, `activeUsers` not `users2`

### Constants
- All caps with underscores: `MAX_RETRY_ATTEMPTS`, `DEFAULT_TIMEOUT`
- Include units: `CACHE_DURATION_MS`, `MAX_FILE_SIZE_MB`

### Booleans
- Question form: `isValid`, `hasPermission`, `canEdit`
- Affirmative: `isEnabled` not `isDisabled` (prefer positive)

---

## Refactoring Script

Would you like me to create a refactoring script to apply these changes?
This will:
1. Rename all suggested items
2. Update all references
3. Maintain git history
4. Generate migration guide

---

## Best Practices

✓ **DO**:
- Use full words over abbreviations
- Be specific and descriptive
- Follow language conventions
- Use consistent patterns
- Make booleans obvious
- Include units in constants

✗ **DON'T**:
- Use single letters (except in loops: i, j, k)
- Use vague names (data, info, temp, x)
- Mix naming conventions
- Use misleading names
- Over-abbreviate
- Use Hungarian notation in modern code

Naming Decision Tree

Is it a boolean?
├─ Yes → Use is/has/can/should prefix
└─ No → Is it a function?
    ├─ Yes → Use verb phrase (action)
    └─ No → Is it a class?
        ├─ Yes → Use noun (PascalCase)
        └─ No → Is it a constant?
            ├─ Yes → Use UPPER_SNAKE_CASE
            └─ No → Use descriptive noun (camelCase/snake_case)

Notes

  • Prioritize clarity over brevity
  • Context matters (loop counters can be i, j)
  • Well-known abbreviations are okay (html, api, url, id)
  • Consistency within a project is more important than perfect naming
  • Refactor names as understanding improves
  • Use IDE rename refactoring to safely update all references
1---
2name: naming-analyzer
3description: Suggest better variable, function, and class names based on context and conventions.
4---
5 
6# Naming Analyzer Skill
7 
8Suggest better variable, function, and class names based on context and conventions.
9 
10## Instructions
11 
12You are a naming convention expert. When invoked:
13 
141. **Analyze Existing Names**:
15 - Variables, constants, functions, methods
16 - Classes, interfaces, types
17 - Files and directories
18 - Database tables and columns
19 - API endpoints
20 
212. **Identify Issues**:
22 - Unclear or vague names
23 - Abbreviations that obscure meaning
24 - Inconsistent naming conventions
25 - Misleading names (name doesn't match behavior)
26 - Too short or too long names
27 - Hungarian notation misuse
28 - Single-letter variables outside loops
29 
303. **Check Conventions**:
31 - Language-specific conventions (camelCase, snake_case, PascalCase)
32 - Framework conventions (React components, Vue props)
33 - Project-specific patterns
34 - Industry standards
35 
364. **Provide Suggestions**:
37 - Better alternative names
38 - Reasoning for each suggestion
39 - Consistency improvements
40 - Contextual appropriateness
41 
42## Naming Conventions by Language
43 
44### JavaScript/TypeScript
45- Variables/functions: `camelCase`
46- Classes/interfaces: `PascalCase`
47- Constants: `UPPER_SNAKE_CASE`
48- Private fields: `_prefixUnderscore` or `#privateField`
49- Boolean: `is`, `has`, `can`, `should` prefixes
50 
51### Python
52- Variables/functions: `snake_case`
53- Classes: `PascalCase`
54- Constants: `UPPER_SNAKE_CASE`
55- Private: `_prefix_underscore`
56- Boolean: `is_`, `has_`, `can_` prefixes
57 
58### Java
59- Variables/methods: `camelCase`
60- Classes/interfaces: `PascalCase`
61- Constants: `UPPER_SNAKE_CASE`
62- Packages: `lowercase`
63 
64### Go
65- Exported: `PascalCase`
66- Unexported: `camelCase`
67- Acronyms: All caps (`HTTPServer`, not `HttpServer`)
68 
69## Common Naming Issues
70 
71### Too Vague
72```javascript
73// ❌ Bad - Too generic
74function process(data) { }
75const info = getData();
76let temp = x;
77 
78// ✓ Good - Specific and clear
79function processPayment(transaction) { }
80const userProfile = getUserProfile();
81let previousValue = x;
82```
83 
84### Misleading Names
85```javascript
86// ❌ Bad - Name doesn't match behavior
87function getUser(id) {
88 const user = fetchUser(id);
89 user.lastLogin = Date.now();
90 saveUser(user); // Side effect! Not just "getting"
91 return user;
92}
93 
94// ✓ Good - Name reflects actual behavior
95function fetchAndUpdateUserLogin(id) {
96 const user = fetchUser(id);
97 user.lastLogin = Date.now();
98 saveUser(user);
99 return user;
100}
101```
102 
103### Abbreviations
104```javascript
105// ❌ Bad - Unclear abbreviations
106const usrCfg = loadConfig();
107function calcTtl(arr) { }
108 
109// ✓ Good - Clear and readable
110const userConfig = loadConfig();
111function calculateTotal(amounts) { }
112 
113// ✓ Acceptable - Well-known abbreviations
114const htmlElement = document.getElementById('main');
115const apiUrl = process.env.API_URL;
116```
117 
118### Boolean Naming
119```javascript
120// ❌ Bad - Unclear state
121const login = user.authenticated;
122const status = checkUser();
123 
124// ✓ Good - Clear boolean intent
125const isLoggedIn = user.authenticated;
126const isUserValid = checkUser();
127const hasPermission = user.roles.includes('admin');
128const canEditPost = isOwner || isAdmin;
129const shouldShowNotification = isEnabled && hasUnread;
130```
131 
132### Magic Numbers
133```javascript
134// ❌ Bad - Unnamed constants
135if (age > 18) { }
136setTimeout(callback, 3600000);
137 
138// ✓ Good - Named constants
139const LEGAL_AGE = 18;
140const ONE_HOUR_IN_MS = 60 * 60 * 1000;
141 
142if (age > LEGAL_AGE) { }
143setTimeout(callback, ONE_HOUR_IN_MS);
144```
145 
146## Usage Examples
147 
148```
149@naming-analyzer
150@naming-analyzer src/
151@naming-analyzer UserService.js
152@naming-analyzer --conventions
153@naming-analyzer --fix-all
154```
155 
156## Report Format
157 
158```markdown
159# Naming Analysis Report
160 
161## Summary
162- Items analyzed: 156
163- Issues found: 23
164- Critical: 5 (misleading names)
165- Major: 12 (unclear/vague)
166- Minor: 6 (convention violations)
167 
168---
169 
170## Critical Issues (5)
171 
172### src/services/UserService.js:45
173**Current**: `getUser(id)`
174**Issue**: Function name implies read-only but has side effects (updates lastLogin)
175**Severity**: Critical - Misleading
176**Suggestion**: `fetchAndUpdateUserLogin(id)`
177**Reason**: Name should reflect the mutation
178 
179### src/utils/helpers.js:23
180**Current**: `validate(x)`
181**Issue**: Generic parameter name, unclear what's being validated
182**Severity**: Critical - Too vague
183**Suggestion**: `validateEmail(emailAddress)`
184**Reason**: Specific names improve clarity
185 
186---
187 
188## Major Issues (12)
189 
190### src/components/DataList.jsx:12
191**Current**: `const d = new Date()`
192**Issue**: Single-letter variable in large scope
193**Severity**: Major
194**Suggestion**: `const currentDate = new Date()`
195**Reason**: Clarity and searchability
196 
197### src/api/client.js:67
198**Current**: `function proc(data) {}`
199**Issue**: Abbreviated function name
200**Severity**: Major
201**Suggestion**: `function processApiResponse(data) {}`
202**Reason**: Full words are more readable
203 
204### src/models/User.js:34
205**Current**: `user.active`
206**Issue**: Boolean property without prefix
207**Severity**: Major
208**Suggestion**: `user.isActive`
209**Reason**: Follow boolean naming convention
210 
211### src/utils/format.js:89
212**Current**: `const MAX = 100`
213**Issue**: Generic constant name
214**Severity**: Major
215**Suggestion**: `const MAX_RETRY_ATTEMPTS = 100`
216**Reason**: Specific purpose is clearer
217 
218---
219 
220## Minor Issues (6)
221 
222### src/config/settings.js:12
223**Current**: `const API_url = '...'`
224**Issue**: Inconsistent casing (mixing UPPER and lower)
225**Severity**: Minor
226**Suggestion**: `const API_URL = '...'` or `const apiUrl = '...'`
227**Reason**: Consistency in convention
228 
229### src/helpers/string.js:45
230**Current**: `function strToNum(s) {}`
231**Issue**: Abbreviated function and parameter
232**Severity**: Minor
233**Suggestion**: `function stringToNumber(value) {}`
234**Reason**: Clarity over brevity
235 
236---
237 
238## Convention Violations
239 
240### Inconsistent Boolean Prefixes
241**Locations**: 8 files
242**Issue**: Mixed use of `is`, `has`, `can` vs no prefix
243**Recommendation**: Standardize on boolean prefixes
244- Use `is` for state: `isActive`, `isVisible`
245- Use `has` for possession: `hasPermission`, `hasError`
246- Use `can` for ability: `canEdit`, `canDelete`
247- Use `should` for decisions: `shouldRender`, `shouldValidate`
248 
249### Mixed Naming Conventions
250**Location**: src/legacy/
251**Issue**: Mix of camelCase and snake_case in JavaScript
252**Recommendation**: Convert all to camelCase for consistency
253 
254---
255 
256## Suggested Renaming
257 
258### High Priority (Misleading or Critical)
2591. `getUser` → `fetchAndUpdateUserLogin` (src/services/UserService.js:45)
2602. `validate` → `validateEmail` (src/utils/helpers.js:23)
2613. `process` → `processPaymentTransaction` (src/payment/processor.js:67)
262 
263### Medium Priority (Clarity)
2641. `d` → `currentDate` (7 locations)
2652. `temp` → `previousValue` (4 locations)
2663. `data` → `apiResponse` or more specific (12 locations)
2674. `arr` → `items`, `values`, or more specific (8 locations)
268 
269### Low Priority (Convention)
2701. `active` → `isActive` (12 locations)
2712. `error` → `hasError` (6 locations)
2723. `API_url` → `API_URL` (3 locations)
273 
274---
275 
276## Naming Patterns to Follow
277 
278### Functions/Methods
279- Verbs: `get`, `set`, `create`, `update`, `delete`, `fetch`, `calculate`, `validate`
280- Clear action: `sendEmail()`, `parseJSON()`, `formatCurrency()`
281 
282### Classes
283- Nouns: `UserService`, `PaymentProcessor`, `EmailValidator`
284- Avoid generic: Don't use `Manager`, `Helper`, `Utility` unless necessary
285 
286### Variables
287- Nouns or noun phrases: `user`, `emailAddress`, `totalAmount`
288- Descriptive: `userList` not `list`, `activeUsers` not `users2`
289 
290### Constants
291- All caps with underscores: `MAX_RETRY_ATTEMPTS`, `DEFAULT_TIMEOUT`
292- Include units: `CACHE_DURATION_MS`, `MAX_FILE_SIZE_MB`
293 
294### Booleans
295- Question form: `isValid`, `hasPermission`, `canEdit`
296- Affirmative: `isEnabled` not `isDisabled` (prefer positive)
297 
298---
299 
300## Refactoring Script
301 
302Would you like me to create a refactoring script to apply these changes?
303This will:
3041. Rename all suggested items
3052. Update all references
3063. Maintain git history
3074. Generate migration guide
308 
309---
310 
311## Best Practices
312 
313✓ **DO**:
314- Use full words over abbreviations
315- Be specific and descriptive
316- Follow language conventions
317- Use consistent patterns
318- Make booleans obvious
319- Include units in constants
320 
321✗ **DON'T**:
322- Use single letters (except in loops: i, j, k)
323- Use vague names (data, info, temp, x)
324- Mix naming conventions
325- Use misleading names
326- Over-abbreviate
327- Use Hungarian notation in modern code
328```
329 
330## Naming Decision Tree
331 
332```
333Is it a boolean?
334├─ Yes → Use is/has/can/should prefix
335└─ No → Is it a function?
336 ├─ Yes → Use verb phrase (action)
337 └─ No → Is it a class?
338 ├─ Yes → Use noun (PascalCase)
339 └─ No → Is it a constant?
340 ├─ Yes → Use UPPER_SNAKE_CASE
341 └─ No → Use descriptive noun (camelCase/snake_case)
342```
343 
344## Notes
345 
346- Prioritize clarity over brevity
347- Context matters (loop counters can be `i`, `j`)
348- Well-known abbreviations are okay (`html`, `api`, `url`, `id`)
349- Consistency within a project is more important than perfect naming
350- Refactor names as understanding improves
351- Use IDE rename refactoring to safely update all references
352 

Discussion