Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 9bb1d62

Browse files
committed
style: Add Prettier config and format all JavaScript
- Added .prettierrc.json with consistent code style rules - Added .prettierignore to exclude non-source files - Formatted 267 JavaScript files with Prettier - Fixed 797 ESLint errors with auto-fix - Reduced total errors from 1100+ to 305 Code is now consistently formatted across the entire codebase
1 parent 9b99819 commit 9bb1d62

File tree

146 files changed

+4201
-3406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+4201
-3406
lines changed

.prettierignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dependencies
2+
node_modules/
3+
package-lock.json
4+
pnpm-lock.yaml
5+
yarn.lock
6+
7+
# Build outputs
8+
dist/
9+
build/
10+
coverage/
11+
.vitest/
12+
.nyc_output/
13+
14+
# IDE
15+
.obsidian/
16+
.vscode/
17+
.idea/
18+
19+
# Git
20+
.git/
21+
22+
# Misc
23+
*.min.js
24+
*.min.css
25+
test-results/
26+
junit.xml
27+
*.tap
28+
*.log
29+
30+
# Generated files
31+
migrations/
32+
.migration_archive/

.prettierrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "none",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"arrowParens": "always",
9+
"endOfLine": "lf",
10+
"bracketSpacing": true,
11+
"bracketSameLine": false,
12+
"proseWrap": "preserve",
13+
"htmlWhitespaceSensitivity": "css",
14+
"embeddedLanguageFormatting": "auto"
15+
}

bin/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ config();
2121
import { cli } from '../src/index.js';
2222

2323
// Run the CLI with process arguments
24-
cli(process.argv).catch(error => {
24+
cli(process.argv).catch((error) => {
2525
console.error('Fatal error:', error.message);
2626
if (process.env.DEBUG) {
2727
console.error(error.stack);

eslint.config.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default [
3535
}
3636
},
3737
plugins: {
38-
'promise': promisePlugin
38+
promise: promisePlugin
3939
},
4040
rules: {
4141
// Promise-specific rules for proper async handling
@@ -56,23 +56,25 @@ export default [
5656
// ESM-specific rules
5757
'no-console': 'off',
5858
'no-undef': 'error',
59-
'no-unused-vars': ['error', {
60-
'argsIgnorePattern': '^_',
61-
'varsIgnorePattern': '^_'
62-
}],
59+
'no-unused-vars': [
60+
'error',
61+
{
62+
argsIgnorePattern: '^_',
63+
varsIgnorePattern: '^_'
64+
}
65+
],
6366

6467
// Modern JavaScript best practices
6568
'prefer-const': 'error',
6669
'prefer-arrow-callback': 'error',
6770
'no-var': 'error',
6871
'object-shorthand': 'error',
69-
'semi': ['error', 'always'],
70-
'quotes': ['error', 'single', { 'avoidEscape': true }],
72+
semi: ['error', 'always'],
73+
quotes: ['error', 'single', { avoidEscape: true }],
7174
'comma-dangle': ['error', 'never'],
72-
'indent': ['error', 2],
75+
indent: ['error', 2],
7376
'no-trailing-spaces': 'error',
7477
'eol-last': 'error'
7578
}
7679
}
7780
];
78-

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"eslint-plugin-promise": "^7.2.1",
5555
"husky": "^9.1.7",
5656
"jscodeshift": "^17.3.0",
57+
"prettier": "^3.6.2",
5758
"recast": "^0.23.11",
5859
"vitest": "^2.0.0"
5960
},

scripts/jsdoc-ai.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
/**
44
* @fileoverview AI-Powered JSDoc Generation Script
5-
*
5+
*
66
* Automatically generates comprehensive JSDoc comments for JavaScript files
77
* using AI analysis. Integrates with git pre-commit hooks for seamless
88
* developer experience.
9-
*
9+
*
1010
* @module JSDocAI
1111
* @since 1.0.0
1212
*/
@@ -25,15 +25,15 @@ const __dirname = dirname(__filename);
2525
*/
2626
function getStagedJSFiles() {
2727
try {
28-
const output = execSync('git diff --cached --name-only --diff-filter=ACM', {
28+
const output = execSync('git diff --cached --name-only --diff-filter=ACM', {
2929
encoding: 'utf8',
3030
cwd: join(__dirname, '..')
3131
});
32-
32+
3333
return output
3434
.split('\n')
35-
.filter(file => file.trim() && file.endsWith('.js'))
36-
.map(file => file.trim());
35+
.filter((file) => file.trim() && file.endsWith('.js'))
36+
.map((file) => file.trim());
3737
} catch (error) {
3838
console.log('No staged files found or not in git repository');
3939
return [];
@@ -54,35 +54,35 @@ function analyzeCodeStructure(code) {
5454
imports: /import\s+.*?from\s+['"`]([^'"`]+)['"`]/g
5555
};
5656

57-
let analysis = "Analyze this JavaScript code and generate comprehensive JSDoc comments:\n\n";
58-
57+
let analysis = 'Analyze this JavaScript code and generate comprehensive JSDoc comments:\n\n';
58+
5959
// Detect patterns
6060
const classes = [...code.matchAll(patterns.classes)];
6161
const functions = [...code.matchAll(patterns.functions)];
6262
const imports = [...code.matchAll(patterns.imports)];
63-
63+
6464
if (classes.length > 0) {
65-
analysis += `Classes found: ${classes.map(m => m[1]).join(', ')}\n`;
65+
analysis += `Classes found: ${classes.map((m) => m[1]).join(', ')}\n`;
6666
}
67-
67+
6868
if (functions.length > 0) {
69-
analysis += `Functions found: ${functions.map(m => m[1]).join(', ')}\n`;
69+
analysis += `Functions found: ${functions.map((m) => m[1]).join(', ')}\n`;
7070
}
71-
71+
7272
if (imports.length > 0) {
73-
analysis += `Dependencies: ${imports.map(m => m[1]).join(', ')}\n`;
73+
analysis += `Dependencies: ${imports.map((m) => m[1]).join(', ')}\n`;
7474
}
7575

76-
analysis += "\nGenerate JSDoc with:\n";
77-
analysis += "- @fileoverview for file header\n";
78-
analysis += "- @param with accurate types for all parameters\n";
79-
analysis += "- @returns with specific return types\n";
80-
analysis += "- @throws for error conditions\n";
81-
analysis += "- @example for complex functions\n";
82-
analysis += "- @since version tags\n";
83-
analysis += "- @module declarations\n\n";
84-
analysis += "IMPORTANT: Only add JSDoc where missing. Preserve existing JSDoc comments.\n";
85-
76+
analysis += '\nGenerate JSDoc with:\n';
77+
analysis += '- @fileoverview for file header\n';
78+
analysis += '- @param with accurate types for all parameters\n';
79+
analysis += '- @returns with specific return types\n';
80+
analysis += '- @throws for error conditions\n';
81+
analysis += '- @example for complex functions\n';
82+
analysis += '- @since version tags\n';
83+
analysis += '- @module declarations\n\n';
84+
analysis += 'IMPORTANT: Only add JSDoc where missing. Preserve existing JSDoc comments.\n';
85+
8686
return analysis;
8787
}
8888

@@ -95,11 +95,11 @@ async function generateJSDocForFile(filePath) {
9595
try {
9696
const absolutePath = join(process.cwd(), filePath);
9797
const code = readFileSync(absolutePath, 'utf8');
98-
98+
9999
// Skip if already has comprehensive JSDoc
100100
const jsdocCount = (code.match(/\/\*\*[\s\S]*?\*\//g) || []).length;
101101
const functionsCount = (code.match(/(?:function|class|\w+\s*\([^)]*\)\s*{)/g) || []).length;
102-
102+
103103
if (jsdocCount >= functionsCount * 0.8) {
104104
console.log(`✓ ${filePath} already has good JSDoc coverage`);
105105
return false;
@@ -108,19 +108,18 @@ async function generateJSDocForFile(filePath) {
108108
const prompt = analyzeCodeStructure(code);
109109
console.log(`📝 Analysis for ${filePath}:`);
110110
console.log(prompt);
111-
111+
112112
// For demo purposes, just indicate what would be done
113113
// In production, this would call Claude API or use local AI
114114
console.log(`\n🤖 AI JSDoc generation would be applied to ${filePath}`);
115115
console.log(` Found ${functionsCount} functions/classes, ${jsdocCount} have JSDoc`);
116-
console.log(` 📋 Prompt ready for AI processing`);
117-
116+
console.log(' 📋 Prompt ready for AI processing');
117+
118118
// For safety in demo, don't modify files
119119
// Uncomment below to enable actual file modification:
120120
// writeFileSync(absolutePath, enhancedCode);
121-
121+
122122
return false; // Return true when actually modifying files
123-
124123
} catch (error) {
125124
console.error(`✗ Error processing ${filePath}:`, error.message);
126125
return false;
@@ -134,16 +133,16 @@ async function generateJSDocForFile(filePath) {
134133
*/
135134
async function main(targetFiles = null) {
136135
const files = targetFiles || getStagedJSFiles();
137-
136+
138137
if (files.length === 0) {
139138
console.log('No JavaScript files to process');
140139
return;
141140
}
142141

143142
console.log(`🤖 Processing ${files.length} JavaScript files for JSDoc enhancement...`);
144-
143+
145144
let modifiedCount = 0;
146-
145+
147146
for (const file of files) {
148147
const wasModified = await generateJSDocForFile(file);
149148
if (wasModified) {
@@ -156,7 +155,7 @@ async function main(targetFiles = null) {
156155
}
157156
}
158157
}
159-
158+
160159
console.log(`🚀 Enhanced ${modifiedCount}/${files.length} files with AI-generated JSDoc`);
161160
}
162161

@@ -166,4 +165,4 @@ if (process.argv[1] === __filename) {
166165
main(targetFiles.length > 0 ? targetFiles : null).catch(console.error);
167166
}
168167

169-
export { main, generateJSDocForFile, analyzeCodeStructure, getStagedJSFiles };
168+
export { main, generateJSDocForFile, analyzeCodeStructure, getStagedJSFiles };

scripts/jsdoc/generate-jsdoc.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ Please return only the updated JavaScript code with JSDoc comments added.`;
105105
// Fallback to heuristic-based JSDoc generation
106106
return this.generateHeuristicJSDoc(originalContent, filePath);
107107
} catch (error) {
108-
console.warn(`⚠️ AI generation failed, falling back to heuristic approach: ${error.message}`);
108+
console.warn(
109+
`⚠️ AI generation failed, falling back to heuristic approach: ${error.message}`
110+
);
109111
return this.generateHeuristicJSDoc(originalContent, filePath);
110112
}
111113
}
@@ -200,17 +202,19 @@ Please return only the updated JavaScript code with JSDoc comments added.`;
200202
const line = lines[i];
201203

202204
// Check if this line defines a function and doesn't already have JSDoc
203-
const functionMatch = line.match(/^\s*(export\s+)?(async\s+)?function\s+(\w+)\s*\(([^)]*)\)|^\s*(\w+)\s*[:=]\s*(async\s+)?\(?([^)]*)\)?\s*=>/);
205+
const functionMatch = line.match(
206+
/^\s*(export\s+)?(async\s+)?function\s+(\w+)\s*\(([^)]*)\)|^\s*(\w+)\s*[:=]\s*(async\s+)?\(?([^)]*)\)?\s*=>/
207+
);
204208

205-
if (functionMatch && i > 0 && !lines[i-1].includes('/**')) {
209+
if (functionMatch && i > 0 && !lines[i - 1].includes('/**')) {
206210
const functionName = functionMatch[3] || functionMatch[5];
207-
const params = (functionMatch[4] || functionMatch[7] || '').split(',').map(p => p.trim()).filter(p => p);
211+
const params = (functionMatch[4] || functionMatch[7] || '')
212+
.split(',')
213+
.map((p) => p.trim())
214+
.filter((p) => p);
208215

209216
// Generate basic JSDoc
210-
const jsdocLines = [
211-
'/**',
212-
` * ${functionName} function`
213-
];
217+
const jsdocLines = ['/**', ` * ${functionName} function`];
214218

215219
// Add parameter documentation
216220
for (const param of params) {
@@ -251,16 +255,11 @@ Please return only the updated JavaScript code with JSDoc comments added.`;
251255
// Check if this line defines a class and doesn't already have JSDoc
252256
const classMatch = line.match(/^\s*(export\s+)?class\s+(\w+)/);
253257

254-
if (classMatch && i > 0 && !lines[i-1].includes('/**')) {
258+
if (classMatch && i > 0 && !lines[i - 1].includes('/**')) {
255259
const className = classMatch[2];
256260

257261
// Generate basic class JSDoc
258-
const jsdocLines = [
259-
'/**',
260-
` * ${className} class`,
261-
' * @class',
262-
' */'
263-
];
262+
const jsdocLines = ['/**', ` * ${className} class`, ' * @class', ' */'];
264263

265264
// Add JSDoc before the class
266265
for (const docLine of jsdocLines) {
@@ -281,12 +280,13 @@ Please return only the updated JavaScript code with JSDoc comments added.`;
281280
*/
282281
hasComprehensiveJSDoc(content) {
283282
const jsdocBlocks = (content.match(/\/\*\*[\s\S]*?\*\//g) || []).length;
284-
const functions = (content.match(/function\s+\w+|=>\s*{|\w+\s*[:=]\s*(?:async\s+)?\(/g) || []).length;
283+
const functions = (content.match(/function\s+\w+|=>\s*{|\w+\s*[:=]\s*(?:async\s+)?\(/g) || [])
284+
.length;
285285
const classes = (content.match(/class\s+\w+/g) || []).length;
286286

287287
// Consider comprehensive if we have JSDoc for most functions/classes
288288
const totalItems = functions + classes;
289-
return totalItems > 0 && (jsdocBlocks / totalItems) >= 0.5;
289+
return totalItems > 0 && jsdocBlocks / totalItems >= 0.5;
290290
}
291291

292292
/**
@@ -367,7 +367,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
367367
};
368368

369369
// Get file paths from arguments or stdin
370-
const filePaths = args.filter(arg => !arg.startsWith('--') && !arg.startsWith('-'));
370+
const filePaths = args.filter((arg) => !arg.startsWith('--') && !arg.startsWith('-'));
371371

372372
if (filePaths.length === 0) {
373373
console.error('Usage: generate-jsdoc.js [options] <file1.js> [file2.js] ...');
@@ -380,8 +380,9 @@ if (import.meta.url === `file://${process.argv[1]}`) {
380380

381381
const generator = new JSDocGenerator(options);
382382

383-
generator.processFiles(filePaths)
384-
.then(results => {
383+
generator
384+
.processFiles(filePaths)
385+
.then((results) => {
385386
console.log('\n📊 JSDoc Generation Summary:');
386387
console.log(` Updated: ${results.updated} files`);
387388
console.log(` Skipped: ${results.skipped} files`);
@@ -393,11 +394,10 @@ if (import.meta.url === `file://${process.argv[1]}`) {
393394

394395
return results;
395396
})
396-
.catch(error => {
397+
.catch((error) => {
397398
process.stderr.write(`❌ JSDoc generation failed: ${error.message}\n`);
398399
process.exit(1);
399400
});
400401
}
401402

402403
export { JSDocGenerator };
403-

0 commit comments

Comments
 (0)