Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var foo = 123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace global var with a typed, immutable declaration.

var introduces function-scoped, hoisted globals and breaks block encapsulation. Use const (or let if mutation is required) and add an explicit type for clarity.

-var foo = 123
+const foo: number = 123
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var foo = 123
const foo: number = 123
🤖 Prompt for AI Agents
In main.ts at line 1, replace the global var declaration with a typed, immutable
declaration by changing var to const and adding an explicit type annotation for
foo, such as const foo: number = 123, to ensure block scoping and type clarity.


function logStuff(input: any) {
console.log("Input is:", input)
debugger
}
Comment on lines +3 to +6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Multiple red flags: any, console.log, and a live debugger statement.

  1. any defeats type-safety; prefer unknown or a generic.
  2. console.log should be replaced with a proper logger or removed in production code.
  3. Shipping code with an active debugger will halt execution in dev-tools.
-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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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)
}
🤖 Prompt for AI Agents
In main.ts around lines 3 to 6, replace the use of `any` with a safer type like
`unknown` or a generic type parameter to improve type safety. Remove the
`console.log` statement or replace it with a proper logging mechanism suitable
for production. Also, remove the active `debugger` statement to prevent
execution from halting in developer tools.


function doNothing() {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove placeholder doNothing or document its intent.

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
In main.ts at line 8, the empty function doNothing is considered dead code and
violates static-analysis rules. Remove the doNothing function entirely if it
serves no purpose, or if it is intended as a placeholder, add a comment or TODO
explaining its purpose and why it is empty.


const process = (value: any) => {
var temp = value
console.log("Processing:", temp)
}
Comment on lines +10 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

process repeats the earlier issues and leaks block scope.

  • Two occurrences of any
  • var instead of const
  • console.log
-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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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)
}
🤖 Prompt for AI Agents
In main.ts around lines 10 to 13, replace the use of 'any' with a more specific
type for the 'value' parameter, change 'var temp' to 'const temp' to avoid block
scope leakage, and remove or replace the 'console.log' statement with proper
logging or error handling as per project standards.


33 changes: 33 additions & 0 deletions sgconfig.yml
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

no-any-type pattern is too specific – will miss several common cases.

The pattern only matches declarations with an explicit identifier wrapper, e.g. foo: any, but it will not flag:

  • Function return types: function f(): any { … }
  • Generic defaults: type X = Array<any>
  • as any casts

Consider broadening the rule or adding companion rules so that the ban is comprehensive.

🤖 Prompt for AI Agents
In sgconfig.yml around lines 12 to 13, the current pattern only matches explicit
identifier declarations with type 'any' and misses other common cases like
function return types, generic defaults, and 'as any' casts. Broaden the pattern
to cover these additional cases or add companion patterns to comprehensively ban
the use of 'any' in all relevant contexts.

- 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($$$) {
}