lintgpt
1.0.0
lintgpt使用AI掃描您的代碼中的錯誤。
狀態:alpha⚡
--fix選項自動解決問題。npm install lintgpt進行安裝。$OPENAI_API_KEY環境變量,您可以在此處生成。 以下是打字稿中的示例用戶類。它通過類型檢查,並且沒有ESLINT樣式錯誤。但是,該程序仍然包含一些錯誤:
export class User {
constructor ( readonly firstName : string , readonly lastName : string , readonly age : number ) {
}
getFirstName ( ) : string {
return this . firstName
}
getLastName ( ) : string {
return this . firstName
}
getFullName ( ) : string {
return this . firstName + this . lastName
}
isLegalDrinkingAge ( ) : boolean {
return this . age > 10
}
}使用lintgpt可以理解意圖並捕獲難以通過其他工具檢測到的邏輯錯誤:
$ npx lintgpt user.ts
✘ getLastName method returns firstName instead of lastName
user.ts:10:12
10 │ return this.firstName
│ ~~~~~~~~~~~~~~
✘ getFullName method does not include a space between firstName and lastName
user.ts:14:12
14 │ return this.firstName + this.lastName
│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
✘ isLegalDrinkingAge method checks if age is greater than 10, not the legal drinking age in most countries
user.ts:18:23
18 │ return this.age > 10
│ ~~
Found 3 problems in user.ts.
您甚至可以通過--fix修訂 - 以自動將建議的更改應用於文件。
$ npx lintgpt user.ts --fix
✔ getLastName method returns firstName instead of lastName
user.ts:10:12
10 │ return this.firstName
│ ~~~~~~~~~~~~~~
Fixed:
│ return this.lastName
✔ getFullName method does not include a space between firstName and lastName
user.ts:14:12
14 │ return this.firstName + this.lastName
│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixed:
│ return this.firstName + ' ' + this.lastName
✔ isLegalDrinkingAge method checks if age is greater than 10, not the legal drinking age in most countries
user.ts:18:23
18 │ return this.age > 10
│ ~~
Fixed:
│ return this.age > 21
有關更多選項,請參見lintgpt --help 。
GPT並不完美,並且經常報告不是錯誤或建議修復錯誤的事情。使用--fix選項查看任何更改時要注意。
考慮Lintgpt的一個好方法是作為一個高中實習生團隊,他們剛剛完成了第一屆計算機科學課程。讓他們查看您的代碼,他們可能會發現一些東西,但是用一粒鹽來將輸出付出。
還請注意,Lintgpt將其傳遞給OpenAI的文件發送。不要在包含敏感信息的文件中使用它。