-
Notifications
You must be signed in to change notification settings - Fork 6
Preview/ast grep #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preview/ast grep #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||
var foo = 123 | ||||||||||||||||||||
|
||||||||||||||||||||
function logStuff(input: any) { | ||||||||||||||||||||
console.log("Input is:", input) | ||||||||||||||||||||
debugger | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple red flags:
-function logStuff(input: any) {
- console.log("Input is:", input)
- debugger
+function logStuff<T>(input: T): void {
+ // TODO: inject a real logger here
+ console.debug("Input is:", input)
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
|
||||||||||||||||||||
function doNothing() {} | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove placeholder Empty functions add dead code and are explicitly banned by the static-analysis rules you just introduced. If this is truly a no-op, delete it; otherwise add behaviour or at least a TODO. 🤖 Prompt for AI Agents
|
||||||||||||||||||||
|
||||||||||||||||||||
const process = (value: any) => { | ||||||||||||||||||||
var temp = value | ||||||||||||||||||||
console.log("Processing:", temp) | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
-const process = (value: any) => {
- var temp = value
- console.log("Processing:", temp)
+const process = <T>(value: T): void => {
+ const temp = value
+ // TODO: replace with structured logger
+ console.debug("Processing:", temp)
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
rules: | ||
- id: no-console-log | ||
message: Avoid using console.log | ||
severity: warning | ||
language: ts | ||
pattern: console.log($$$) | ||
|
||
- id: no-any-type | ||
message: Avoid using `any` type | ||
severity: warning | ||
language: ts | ||
pattern: ($VAR:identifier): any | ||
|
||
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
The pattern only matches declarations with an explicit identifier wrapper, e.g.
Consider broadening the rule or adding companion rules so that the ban is comprehensive. 🤖 Prompt for AI Agents
|
||
- id: no-var | ||
message: Use `let` or `const` instead of `var` | ||
severity: warning | ||
language: ts | ||
pattern: var $VAR = $$$ | ||
|
||
- id: no-debugger | ||
message: Remove `debugger` statement | ||
severity: warning | ||
language: ts | ||
pattern: debugger | ||
|
||
- id: no-empty-function | ||
message: Avoid using empty functions | ||
severity: warning | ||
language: ts | ||
pattern: | | ||
function $NAME($$$) { | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace global
var
with a typed, immutable declaration.var
introduces function-scoped, hoisted globals and breaks block encapsulation. Useconst
(orlet
if mutation is required) and add an explicit type for clarity.📝 Committable suggestion
🤖 Prompt for AI Agents