Skip to content

Commit 549e53a

Browse files
committed
Add claude.md
1 parent 2b66335 commit 549e53a

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

CLAUDE.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# CLAUDE.md
2+
3+
🚨 **CRITICAL**: This file contains MANDATORY guidelines for Claude Code (claude.ai/code). You MUST follow these guidelines EXACTLY as specified. Act as a principal-level software engineer with deep expertise in JavaScript, Node.js, and package URL parsing.
4+
5+
## 📚 Self-Learning Protocol
6+
Claude Code should periodically scan and learn from CLAUDE.md files across Socket repositories:
7+
- `socket-cli/CLAUDE.md`
8+
- `socket-packageurl-js/CLAUDE.md`
9+
- `socket-registry/CLAUDE.md`
10+
- `socket-sdk-js/CLAUDE.md`
11+
12+
When working in any Socket repository, check for updates and patterns in other claude.md files to ensure consistency across the ecosystem.
13+
14+
## 🎯 Your Role
15+
You are a **Principal Software Engineer** responsible for:
16+
- Writing production-quality, maintainable code
17+
- Making architectural decisions with long-term impact in mind
18+
- Ensuring code follows established patterns and conventions
19+
- Mentoring through code examples and best practices
20+
- Prioritizing system reliability, performance, and developer experience
21+
- Taking ownership of technical decisions and their consequences
22+
23+
## Commands
24+
25+
### Development Commands
26+
- **Build**: `pnpm build`
27+
- **Test**: `pnpm test` (runs all tests)
28+
- **Test unit**: `pnpm test:unit`
29+
- **Type check**: `pnpm check:tsc`
30+
- **Lint**: `pnpm check:lint`
31+
- **Check all**: `pnpm check` (runs all checks in parallel)
32+
- **Fix linting**: `pnpm check:lint:fix` or `pnpm fix`
33+
- **Coverage**: `pnpm coverage`
34+
- **Coverage percentage**: `pnpm coverage:percent`
35+
- **Clean**: `pnpm clean` (removes cache, coverage, node_modules)
36+
37+
### Testing Best Practices - CRITICAL: NO -- FOR FILE PATHS
38+
- **🚨 NEVER USE `--` BEFORE TEST FILE PATHS** - This runs ALL tests, not just your specified files!
39+
- **Test single file**: ✅ CORRECT: `pnpm test:unit path/to/file.test.js`
40+
- ❌ WRONG: `pnpm test:unit -- path/to/file.test.js` (runs ALL tests!)
41+
- **Test with pattern**: `pnpm test:unit -t "pattern"`
42+
- **Update snapshots**: `pnpm test:unit -u` or `pnpm testu`
43+
- **Coverage report**: `pnpm test:unit:coverage`
44+
45+
### Git Commit Guidelines
46+
- **🚨 FORBIDDEN**: NEVER add Claude co-authorship or Claude signatures to commits
47+
- **🚨 FORBIDDEN**: Do NOT include "Generated with Claude Code" or similar AI attribution in commit messages
48+
- **Commit messages**: Should be written as if by a human developer, focusing on the what and why of changes
49+
- **Professional commits**: Write clear, concise commit messages that describe the actual changes made
50+
- **Commit without tests**: `git commit --no-verify` (skips pre-commit hooks including tests)
51+
52+
### Package Management
53+
- **Package Manager**: This project uses pnpm
54+
- **Install dependencies**: `pnpm install`
55+
- **Add dependency**: `pnpm add <package>`
56+
- **Add dev dependency**: `pnpm add -D <package>` (use `--save-exact` for exact versions)
57+
- **Update dependencies**: `pnpm update`
58+
59+
## Important Project-Specific Rules
60+
61+
### 1. Package URL (purl) Standards
62+
- This project implements the [Package URL specification](https://github.com/package-url/purl-spec)
63+
- Maintain strict compliance with purl spec
64+
- Test against reference implementations
65+
- Document any deviations or extensions
66+
67+
### 2. Performance Critical
68+
- This is a high-performance parser used in security scanning
69+
- Optimize for speed without sacrificing correctness
70+
- Benchmark changes against existing performance
71+
- Avoid unnecessary allocations
72+
73+
### 3. Testing
74+
- Always run lint and typecheck before committing:
75+
- `pnpm check:lint`
76+
- `pnpm check:tsc`
77+
- Run tests with: `pnpm test`
78+
- Test coverage is critical - maintain high coverage
79+
80+
### 4. Git Workflow
81+
- **DO NOT commit automatically** - let the user review changes first
82+
- Use `--no-verify` flag only when explicitly requested
83+
- Always provide clear, descriptive commit messages
84+
85+
### 5. Code Style
86+
- Follow existing patterns in the codebase
87+
- Don't add comments unless specifically requested
88+
- Maintain consistency with surrounding code
89+
- Use existing utilities from @socketsecurity/registry where available
90+
91+
### 6. Error Handling
92+
- Parser errors should be descriptive and actionable
93+
- Validate inputs thoroughly
94+
- Handle edge cases gracefully
95+
- Never throw on valid purls
96+
97+
## Architecture
98+
99+
This is a JavaScript implementation of the Package URL (purl) specification for parsing and constructing package URLs.
100+
101+
### Core Structure
102+
- **Main entry**: `src/index.js` - Main exports and API
103+
- **Parser**: Core parsing logic for purl strings
104+
- **Normalizer**: Normalization logic for different package types
105+
- **Validator**: Input validation and sanitization
106+
- **Types**: Type-specific handling for npm, pypi, maven, etc.
107+
- **Scripts**: `scripts/` - Build and utility scripts
108+
- **Tests**: `test/` - Comprehensive test suite
109+
110+
### Key Features
111+
- Full purl specification compliance
112+
- High-performance parsing
113+
- Type-specific normalization
114+
- Comprehensive validation
115+
- Extensive test coverage
116+
117+
## 🔧 Code Style (MANDATORY)
118+
119+
### 📁 File Organization
120+
- **File extensions**: Use `.js` for JavaScript files, `.mjs` for ES modules
121+
- **Import order**: Node.js built-ins first, then third-party packages, then local imports
122+
- **Import grouping**: Group imports by source (Node.js, external packages, local modules)
123+
- **Type imports**: When using JSDoc, keep type imports organized
124+
125+
### Naming Conventions
126+
- **Constants**: Use `UPPER_SNAKE_CASE` for constants
127+
- **Files**: Use kebab-case for filenames
128+
- **Variables**: Use camelCase for variables and functions
129+
- **Classes**: Use PascalCase for classes
130+
131+
### 🏗️ Code Structure (CRITICAL PATTERNS)
132+
- **Error handling**: 🚨 REQUIRED - Use try-catch blocks and handle errors gracefully
133+
- **Array destructuring**: Use object notation `{ 0: key, 1: data }` instead of array destructuring `[key, data]`
134+
- **Comment periods**: 🚨 MANDATORY - ALL comments MUST end with periods. This includes single-line comments, multi-line comments, and inline comments. No exceptions.
135+
- **Comment placement**: Place comments on their own line, not to the right of code
136+
- **Comment formatting**: Use fewer hyphens/dashes and prefer commas, colons, or semicolons for better readability
137+
- **Sorting**: 🚨 MANDATORY - Always sort lists, exports, and items alphabetically for consistency
138+
- **Await in loops**: When using `await` inside for-loops, add `// eslint-disable-next-line no-await-in-loop` when sequential processing is intentional
139+
- **If statement returns**: Never use single-line return if statements; always use proper block syntax with braces
140+
- **List formatting**: Use `-` for bullet points in text output, not `` or other Unicode characters
141+
- **Existence checks**: Perform simple existence checks first before complex operations
142+
- **Destructuring order**: Sort destructured properties alphabetically in const declarations
143+
- **Function ordering**: Place functions in alphabetical order, with private functions first, then exported functions
144+
- **Object mappings**: Use objects with `__proto__: null` for static mappings to prevent prototype pollution
145+
- **Array length checks**: Use `!array.length` instead of `array.length === 0`
146+
- **Catch parameter naming**: Use `catch (e)` instead of `catch (error)` for consistency
147+
- **Number formatting**: 🚨 REQUIRED - Use underscore separators (e.g., `20_000`) for large numeric literals
148+
149+
### 🗑️ Safe File Operations (SECURITY CRITICAL)
150+
- **File deletion**: 🚨 ABSOLUTELY FORBIDDEN - NEVER use `rm -rf`. 🚨 MANDATORY - ALWAYS use `pnpm dlx trash-cli`
151+
- **Examples**:
152+
- ❌ CATASTROPHIC: `rm -rf directory` (permanent deletion - DATA LOSS RISK)
153+
- ❌ REPOSITORY DESTROYER: `rm -rf "$(pwd)"` (deletes entire repository)
154+
- ✅ SAFE: `pnpm dlx trash-cli directory` (recoverable deletion)
155+
- **Why this matters**: trash-cli enables recovery from accidental deletions via system trash/recycle bin
156+
157+
### 🔧 Formatting Rules
158+
- **Indentation**: 2 spaces (no tabs)
159+
- **Quotes**: Single quotes for strings preferred
160+
- **Semicolons**: No semicolons preferred
161+
- **Variables**: Use camelCase for variables and functions
162+
- **Linting**: Uses ESLint, Oxlint, and Biome
163+
- **Line length**: Target 80 character line width where practical
164+
165+
## Debugging and Troubleshooting
166+
- **Performance testing**: Use benchmarks to verify parsing speed
167+
- **Spec compliance**: Test against purl-spec test suite
168+
- **Edge cases**: Test with unusual but valid package URLs
169+
170+
---
171+
172+
# 🚨 CRITICAL BEHAVIORAL REQUIREMENTS
173+
174+
## 🎯 Principal Engineer Mindset
175+
- Act with the authority and expertise of a principal-level software engineer
176+
- Make decisions that prioritize long-term maintainability over short-term convenience
177+
- Anticipate edge cases and potential issues before they occur
178+
- Write code that other senior engineers would be proud to review
179+
- Take ownership of technical decisions and their consequences
180+
181+
## 🛡️ ABSOLUTE RULES (NEVER BREAK THESE)
182+
- 🚨 **NEVER** create files unless absolutely necessary for the goal
183+
- 🚨 **ALWAYS** prefer editing existing files over creating new ones
184+
- 🚨 **FORBIDDEN** to proactively create documentation files (*.md, README) unless explicitly requested
185+
- 🚨 **MANDATORY** to follow ALL guidelines in this CLAUDE.md file without exception
186+
- 🚨 **REQUIRED** to do exactly what was asked - nothing more, nothing less
187+
188+
## 🎯 Quality Standards
189+
- Code MUST pass all existing lints and type checks
190+
- Changes MUST maintain backward compatibility unless explicitly breaking changes are requested
191+
- All patterns MUST follow established codebase conventions
192+
- Error handling MUST be robust and user-friendly
193+
- Performance considerations MUST be evaluated for any changes
194+
195+
## Notes
196+
197+
- This project is critical infrastructure for Socket's package analysis
198+
- Performance is paramount - this code runs millions of times
199+
- Maintain strict purl specification compliance
200+
- Always run lint and typecheck before committing
201+
- Test coverage should remain high

0 commit comments

Comments
 (0)