From cef9ef93919e85eb265851e024e3031d1bc9b071 Mon Sep 17 00:00:00 2001 From: euclidstellar Date: Fri, 27 Jun 2025 11:57:31 +0530 Subject: [PATCH] test PR: for static checks on sample apps --- static-code-go/static.go | 2 +- static-code-go/test/test.go | 37 +++++++++++++++++++++++++++++++++++++ static-code-js/static.js | 2 +- static-code-js/test/test.js | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 static-code-go/test/test.go create mode 100644 static-code-js/test/test.js diff --git a/static-code-go/static.go b/static-code-go/static.go index 97a243f5..2056dbba 100644 --- a/static-code-go/static.go +++ b/static-code-go/static.go @@ -12,5 +12,5 @@ func main() { // Generate a random number between 1000 and 9999 otp := rand.Int() // Print the generated OTP - fmt.Printf("Generated OTP: %d\n", otp) + fmt.Printf("Generated OTP: %d\n", otp } \ No newline at end of file diff --git a/static-code-go/test/test.go b/static-code-go/test/test.go new file mode 100644 index 00000000..d7afd8d0 --- /dev/null +++ b/static-code-go/test/test.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "math" +) + +func unusedFunc(x int) int { + return x * 2 +} + +func calculateArea(radius float64) float64 { + return math.Pi * radius * radius +} + +func main() { + var result = calculateArea(10) + + fmt.Println("Area is: ", result) + + var a int + var b int = 5 + a = 5 + + if b == 5 { + fmt.Println("B is five" + } + + if a == 5 { + + } + + a := 10 + fmt.Println("Shadowed a:", a + + fmt.Println("This is a very very very very very very very very very very very very long line which most linters will flag as exceeding the line length") +} diff --git a/static-code-js/static.js b/static-code-js/static.js index 9f2b0504..385b7f9d 100644 --- a/static-code-js/static.js +++ b/static-code-js/static.js @@ -19,7 +19,7 @@ app.get('/user', (req, res) => { return res.status(400).json({ error: 'Invalid or missing user ID' }); } - const user = fetchUser(Number(id)); + const user = fetchUser(Number(id); return res.json({ message: `Hello, ${user.name}! Your email is ${user.email}.`, user, diff --git a/static-code-js/test/test.js b/static-code-js/test/test.js new file mode 100644 index 00000000..997a8d28 --- /dev/null +++ b/static-code-js/test/test.js @@ -0,0 +1,32 @@ +function add(x, y) { + return x + y +} + +const unusedVar = 42; + +function greet(name) { + if(name == "Admin"){ + console.log("Hello Admin") + } else if(name = "Guest"){ + console.log("Hello Guest") + } + else{ + console.log("Hello " + name); + } +} + +function main(){ + let result = add(2, 3) + console.log('Sum is: ' + result) + + if (true) { + console.log('This is a block with a true condition' + } + + let result = 10; // variable redeclaration + console.log('New result is: ' + result) + + console.log('This is a very very very very very very very very very very very very very very very very very very very long line that should be flagged by linters') +} + +main();