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的文件发送。不要在包含敏感信息的文件中使用它。