Skip to content

Commit 131d36e

Browse files
chore: ai lint fix
1 parent 5ac093d commit 131d36e

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

ai-lint-fix.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { OpenAI } = require('openai');
77
const yargs = require('yargs/yargs');
88
const { hideBin } = require('yargs/helpers');
99
const glob = require('glob');
10+
1011
// Initialize OpenAI client
1112
const openai = new OpenAI({
1213
apiKey: process.env.OPENAI_API_KEY,
@@ -68,21 +69,6 @@ async function processFile(filePath) {
6869
const lintedContent = await lintFileContent(fileContent);
6970
fs.writeFileSync(filePath, lintedContent, 'utf8');
7071
console.log(`File has been linted and updated successfully: ${filePath}`);
71-
const tsConfigPath = findTsConfig(filePath);
72-
try {
73-
const tscOutput = execFileSync(
74-
'tsc',
75-
['--noEmit', '--project', tsConfigPath],
76-
{
77-
stdio: 'pipe',
78-
},
79-
).toString();
80-
console.log(`TypeScript check passed for ${filePath}:\n${tscOutput}`);
81-
} catch (error) {
82-
console.error(
83-
`TypeScript check failed for ${filePath}:\n${error.stdout.toString()}`,
84-
);
85-
}
8672
} catch (error) {
8773
console.error(`Error performing linting on ${filePath}:`, error.message);
8874
process.exit(1);
@@ -101,17 +87,32 @@ function findTsConfig(filePath) {
10187
throw new Error('tsconfig.json not found');
10288
}
10389

90+
async function processFilesWithConcurrencyLimit(files, limit) {
91+
const results = [];
92+
const executing = [];
93+
94+
for (const file of files) {
95+
const p = processFile(file).then(() => {
96+
executing.splice(executing.indexOf(p), 1);
97+
});
98+
results.push(p);
99+
executing.push(p);
100+
if (executing.length >= limit) {
101+
await Promise.race(executing);
102+
}
103+
}
104+
105+
return Promise.all(results);
106+
}
107+
104108
async function main() {
105109
if (argv.path) {
106110
await processFile(argv.path);
107111
} else if (argv.pattern) {
108112
console.log('pattern', argv.pattern);
109113
try {
110114
const files = await glob.glob(argv.pattern);
111-
112-
for (const filePath of files) {
113-
await processFile(filePath);
114-
}
115+
await processFilesWithConcurrencyLimit(files, 3); // Process files with concurrency limit of 3
115116
} catch (err) {
116117
console.error('Error finding files:', err.message);
117118
process.exit(1);

0 commit comments

Comments
 (0)