Skip to content
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

fix_golangcilint_empty_result_error #4

Merged
merged 4 commits into from
Aug 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto ru
if(codeAnalysisIssueDtoList == null || codeAnalysisIssueDtoList.isEmpty()){
return list;
}

CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType());
resultDto.setDisplayTitle("IaC issues");
resultDto.setDisplayTitle("IaC");
resultDto.addIssues(codeAnalysisIssueDtoList);
list.add(resultDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,50 @@ public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto ru
try {
List<File> goModules = GolangcilintModuleUtil.findGoModules(request.getLocalGitRepoPath());

List<String> cmdList = new ArrayList<>();
cmdList.add("golangci-lint");
cmdList.add("run");
cmdList.add("--no-config");
cmdList.add("--out-format");
cmdList.add("json");
for(File file : goModules) {
List<String> cmdList = new ArrayList<>();
cmdList.add("golangci-lint");
cmdList.add("run");
cmdList.add("--no-config");
cmdList.add("--out-format");
cmdList.add("json");

if (runnerConfiguration.getPayload() == null || runnerConfiguration.getPayload().isEmpty()) {
cmdList.add("--enable-all");

if(runnerConfiguration.getPayload() == null || runnerConfiguration.getPayload().isEmpty()){
cmdList.add("--enable-all");
} else {
cmdList.add("--enable-all");
}

}else{
cmdList.add("--enable-all");
}
for(File file : goModules){
cmdList.add(file.getName() + "/...");
}
cmdList.add( "./...");

String[] command = cmdList.toArray(new String[0]);
String[] command = cmdList.toArray(new String[0]);


RuntimeExecUtil.RuntimeExecResult runtimeExecResult = RuntimeExecUtil.exec(command, null, 60, false, null);
RuntimeExecUtil.RuntimeExecResult runtimeExecResult = RuntimeExecUtil.exec(command, file.getAbsolutePath(), 60, false, null);

String errorOutput = runtimeExecResult.getErrorOutput();
String successOutput = runtimeExecResult.getSuccessOutput();
String errorOutput = runtimeExecResult.getErrorOutput();
String successOutput = runtimeExecResult.getSuccessOutput();

if(errorOutput!=null && errorOutput.length() > 0){
CodetyConsoleLogger.debug("Error output from golangci-lint " + errorOutput);
}
if(successOutput == null || successOutput.isEmpty()){
return list;
}
if (errorOutput != null && errorOutput.length() > 0) {
CodetyConsoleLogger.debug("Error output from golangci-lint " + errorOutput);
}
if (successOutput == null || successOutput.isEmpty()) {
return list;
}

List<CodeAnalysisIssueDto> codeAnalysisIssueDtoList = GolangcilintResultConverter.convertResult(successOutput);
if(codeAnalysisIssueDtoList == null || codeAnalysisIssueDtoList.isEmpty()){
return list;
}
List<CodeAnalysisIssueDto> codeAnalysisIssueDtoList = GolangcilintResultConverter.convertResult(successOutput);
if (codeAnalysisIssueDtoList == null || codeAnalysisIssueDtoList.isEmpty()) {
return list;
}

CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType());
CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType());

resultDto.setDisplayTitle("Golang");
resultDto.addIssues(codeAnalysisIssueDtoList);
resultDto.setDisplayTitle("Golang");
resultDto.addIssues(codeAnalysisIssueDtoList);

list.add(resultDto);
list.add(resultDto);
}

} catch (Exception e) {

Expand Down
41 changes: 14 additions & 27 deletions code-issue-examples/go/module-with-mod/cgo-issue.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
package cgoexample
package mymodule

/*
#include <stdio.h>
#include <stdlib.h>
import "fmt"

void myprint(char* s) {
printf("%s\n", s);
}
*/
import "C"
func MyModule() {

import (
"fmt"
"unsafe"
)
var u1 = "initial"
var u2 = "initial"

func Example() {
cs := C.CString("Hello from stdio\n")
C.myprint(cs)
fmt.Printf("bad format %t", cs)
C.free(unsafe.Pointer(cs))
}
var b, c int = 1, 2
fmt.Println(b, c)

func notFormattedForGofmt() {
}
var d = true
fmt.Println(d)

func errorForRevive(p *int) error {
if p == nil {
return nil
} else {
return nil
}
var e int
fmt.Println(e)

f := "apple"
fmt.Println(f)
}
4 changes: 2 additions & 2 deletions code-issue-examples/go/module-with-mod/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module mymodule
module hello

go 1.23.0
go 1.22.0
7 changes: 7 additions & 0 deletions code-issue-examples/go/module-with-mod/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hello

func Hello() string {
var u3 = "initial"
var u4 = "initial"
return "Hello, world."
}
21 changes: 21 additions & 0 deletions code-issue-examples/go/module-with-mod/mymodule/unused-var.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mymodule

import "fmt"

func MyModule() {

var u1 = "initial"
var u2 = "initial"

var b, c int = 1, 2
fmt.Println(b, c)

var d = true
fmt.Println(d)

var e int
fmt.Println(e)

f := "apple"
fmt.Println(f)
}
6 changes: 5 additions & 1 deletion image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM amazoncorretto:17-alpine-jdk

RUN apk add --no-cache python3 py3-pip
RUN apk add --no-cache python3 py3-pip go
RUN apk add --no-cache bash openssl ca-certificates git libc6-compat libstdc++ curl cppcheck nodejs npm py3-pylint

RUN npm install --prefix /usr/local/eslint9/ eslint@9.x eslint-plugin-jsdoc eslint-plugin-react eslint-plugin-vue @html-eslint/parser @html-eslint/eslint-plugin
Expand All @@ -9,6 +9,10 @@ RUN npm install --prefix /usr/local/eslint8/ eslint@8.x typescript @typescript-
# !!!!!!checkov build will be failed in arm64 environment, you need to append `--platform=linux/amd64` during docker build or run if you use ARM64 environment(e.g. M1+ chips MacBook)
RUN pip3 install checkov --break-system-packages

# install golang
# COPY --from=golang:1.17-alpine /usr/local/go/ /usr/local/go/
# ENV PATH="/usr/local/go/bin:${PATH}"

#golang lint
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.60.3
RUN golangci-lint --version
Expand Down