Skip to content

Commit 3309d8d

Browse files
committed
Refactor project structure and update build configuration
- Update main entry points from package-url.js to index.js in package.json - Remove obsolete root-level index.d.ts file (superseded by dist/index.d.ts) - Improve TypeScript compilation with optimized tsconfig.json settings - Add comprehensive JSDoc comment formatting guidelines to CLAUDE.md - Enhance code style documentation with function documentation patterns
1 parent 9fb89a6 commit 3309d8d

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

CLAUDE.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ This is a TypeScript implementation of the Package URL (purl) specification for
240240
- **Array destructuring**: Use object notation `{ 0: key, 1: data }` instead of array destructuring `[key, data]`
241241
- **Dynamic imports**: 🚨 FORBIDDEN - Never use dynamic imports (`await import()`). Always use static imports at the top of the file
242242
- **Comment formatting**: 🚨 MANDATORY - ALL comments MUST follow these rules:
243+
- **Single-line preference**: Prefer single-line comments (`//`) over multiline comments (`/* */`) unless for method headers, module headers, or copyright notices. Use single-line comments for property descriptions, inline explanations, and general code comments.
243244
- **Periods required**: Every comment MUST end with a period, except ESLint disable comments and URLs which are directives/references. This includes single-line, multi-line, inline, and c8 ignore comments.
244245
- **Sentence structure**: Comments should be complete sentences with proper capitalization and grammar.
245246
- **Placement**: Place comments on their own line above the code they describe, not trailing to the right of code.
246247
- **Style**: Use fewer hyphens/dashes and prefer commas, colons, or semicolons for better readability.
247248
- **Examples**:
248-
- ✅ CORRECT: `// This function validates user input.`
249-
- ✅ CORRECT: `/* This is a multi-line comment that explains the complex logic below. */`
249+
- ✅ CORRECT: `// This function validates user input.` (single-line preferred)
250+
- ✅ CORRECT: `// Custom GitHub host (default: github.com).` (property description)
251+
- ✅ CORRECT: `/* This is a method header JSDoc comment. */` (method/module headers only)
250252
- ✅ CORRECT: `// eslint-disable-next-line no-await-in-loop` (directive, no period)
251253
- ✅ CORRECT: `// See https://example.com/docs` (URL reference, no period)
252254
- ✅ CORRECT: `// c8 ignore start - Reason for ignoring.` (explanation has period)
255+
- ❌ WRONG: `/** Custom GitHub host (default: github.com). */` (multiline for simple property)
253256
- ❌ WRONG: `// this validates input` (no period, not capitalized)
254257
- ❌ WRONG: `const x = 5 // some value` (trailing comment)
255258
- **JSDoc comments**: 🚨 SIMPLIFIED - Only use @throws for error documentation. Avoid @param and @returns tags - function signatures and good function names should be self-documenting.
@@ -268,6 +271,28 @@ This is a TypeScript implementation of the Package URL (purl) specification for
268271
- **Number formatting**: 🚨 REQUIRED - Use underscore separators (e.g., `20_000`) for large numeric literals. 🚨 FORBIDDEN - Do NOT modify number values inside strings
269272
- **Node.js fs imports**: 🚨 MANDATORY pattern - `import { someSyncThing, promises as fs } from 'node:fs'`
270273
- **Process spawning**: 🚨 FORBIDDEN to use Node.js built-in `child_process.spawn` - MUST use `spawn` from `@socketsecurity/registry/lib/spawn`
274+
- **JSDoc function documentation**: 🚨 MANDATORY - Function JSDoc comments MUST follow this exact pattern:
275+
- **Format**: Description only, with optional `@throws` - NO `@param` or `@returns` tags
276+
- **Order**: Description paragraph, then `@throws` tag (if needed)
277+
- **Closure**: End with `*/` immediately after the last JSDoc tag
278+
- **Examples**:
279+
- ✅ CORRECT:
280+
```javascript
281+
/**
282+
* Check if a string contains a trusted domain using proper URL parsing.
283+
*/
284+
```
285+
-CORRECT (with throws):
286+
```javascript
287+
/**
288+
* Parse a configuration file and validate its contents.
289+
* @throws {Error} When file cannot be read or parsed.
290+
*/
291+
```
292+
-FORBIDDEN: Adding `@param` or `@returns` tags
293+
-FORBIDDEN: Adding extra tags like `@author`, `@since`, `@example`, etc.
294+
-FORBIDDEN: Adding empty lines between JSDoc tags
295+
-FORBIDDEN: Adding extra content after the last JSDoc tag
271296

272297
### 🗑️ Safe File Operations (SECURITY CRITICAL)
273298
- **Script usage only**: Use `trash` package ONLY in scripts, build files, and utilities - NOT in `/src/` files

index.d.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"type": "git",
1313
"url": "git+https://github.com/SocketDev/socket-packageurl-js.git"
1414
},
15-
"main": "./dist/package-url.js",
16-
"types": "./dist/package-url.d.ts",
15+
"main": "./dist/index.js",
16+
"types": "./dist/index.d.ts",
1717
"exports": {
1818
".": {
19-
"types": "./dist/package-url.d.ts",
20-
"default": "./dist/package-url.js"
19+
"types": "./dist/index.d.ts",
20+
"default": "./dist/index.js"
2121
},
2222
"./data/npm/builtin-names.json": "./data/npm/builtin-names.json",
2323
"./data/npm/legacy-names.json": "./data/npm/legacy-names.json",

tsconfig.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
"outDir": "dist",
77
"rootDir": "src",
88
"verbatimModuleSyntax": false,
9-
"noEmit": false
9+
"noEmit": false,
10+
"noEmitOnError": false,
11+
"sourceMap": false,
12+
"declarationMap": false,
13+
"skipLibCheck": true
1014
},
11-
"include": ["src/**/*.ts"]
15+
"include": ["src/**/*.ts"],
16+
"exclude": ["node_modules", "dist", "coverage", "test"]
1217
}

0 commit comments

Comments
 (0)