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 #7

Merged
merged 1 commit 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 @@ -19,7 +19,7 @@ public class CheckovCodeAnalyzer implements CodeAnalyzerInterface {
private static final String checkov = "checkov";
@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {
CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
ArrayList<CodeAnalysisResultDto> list = new ArrayList();

String[] command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CppcheckCodeAnalyzer implements CodeAnalyzerInterface {
private static final String INFO_failedToRunCppcheck = "Failed to run cpp analyzer due to error: ";
@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {
CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
File file = runnerConfiguration.getFile();
//cppcheck . --suppressions-list=suppression.txt --xml 2>error1.txt
ArrayList<CodeAnalysisResultDto> list = new ArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class EslintCodeAnalyzer implements CodeAnalyzerInterface {
String aTrue = "true";
@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {
CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getPluginCode()+"...");
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getPluginCode()+"...");
List<CodeAnalysisResultDto> result = new ArrayList<>();

CodetyConsoleLogger.debug(infoStartProcessing + runnerConfiguration.getLanguage() + " " + runnerConfiguration.getPluginCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private List<CodeAnalysisIssueDto> parsePmdResult(String pmdCsvResult, String ba

@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {
CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
String baseSourcePath = request.getLocalGitRepoPath();
CodeAnalyzerSettingGroupDto codeAnalyzerSettingGroupDto = sourceCodeDirectoryLayoutAnalyzer.analyzeSourceDirectory(baseSourcePath);
List<CodeAnalysisResultDto> resultSetDto = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PylintCodeAnalyzer implements CodeAnalyzerInterface {
String message = "Cannot get any unmaterialized rules.";
@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {
CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
List<CodeAnalysisResultDto> result = new ArrayList<>();

CodetyConsoleLogger.debug(infoStartProcessing + runnerConfiguration.getLanguage() + " " + runnerConfiguration.getPluginCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.codety.scanner.analyzer.scalastyle;

import io.codety.scanner.analyzer.CodeAnalyzerInterface;
import io.codety.scanner.analyzer.dto.AnalyzerConfigurationDetailDto;
import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto;
import io.codety.scanner.reporter.dto.CodeAnalysisResultDto;
import io.codety.scanner.service.dto.AnalyzerRequest;
import io.codety.scanner.util.CodetyConsoleLogger;
import io.codety.scanner.util.RuntimeExecUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class ScalastyleCodeAnalyzer implements CodeAnalyzerInterface {


@Value("${codety.base.path}")
String scalaStyleJarPath;

@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) {

//cmd example:
// java -jar ~/dev/scalastyle.jar --config analyzer-scalastyle/src/test/resources/default-config.xml --xmlOutput ~/dev/tmp.xml code-issue-examples/scala
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"...");
File file = runnerConfiguration.getFile();
ArrayList<CodeAnalysisResultDto> list = new ArrayList();

String[] command;
String jarPath = scalaStyleJarPath + "/scalastyle.jar";
runnerConfiguration.getFile();
File tmpConfigDownloadFolder = new File("/tmp/scala_output_" + System.currentTimeMillis() + ".xml");
String absoluteFile = tmpConfigDownloadFolder.getAbsolutePath();

if(runnerConfiguration.getPayload() == null || runnerConfiguration.getPayload().isEmpty()){
command = new String[]{"java", "-jar", scalaStyleJarPath, "--config", request.getLocalGitRepoPath(), "--xmlOutput", absoluteFile, request.getLocalGitRepoPath()};
}else{
command = new String[]{"java", "-jar", scalaStyleJarPath, "--config", request.getLocalGitRepoPath(), "--xmlOutput", absoluteFile, request.getLocalGitRepoPath()};
}
try {

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

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

// List<CodeAnalysisIssueDto> codeAnalysisIssueDtoList = CppcheckResultConverter.convertResult(errorOutput);
// if(codeAnalysisIssueDtoList == null || codeAnalysisIssueDtoList.isEmpty()){
// return list;
// }
//
// CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType());
//
// resultDto.setDisplayTitle(cppTitle);
// resultDto.addIssues(codeAnalysisIssueDtoList);
//
//
// list.add(resultDto);

} catch (Exception e) {

CodetyConsoleLogger.debug("Failed to run scalastyle due to error " + e.getMessage(), e);
}

return list;
}

@Override
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerRequest request) {
return null;
}
}

This file was deleted.

142 changes: 142 additions & 0 deletions scanner/tools/scalastyle-default-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<scalastyle commentFilter="enabled">
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<parameters>
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
// See the LICENCE.txt file distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLineLengthChecker" enabled="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
<parameter name="tabSize"><![CDATA[4]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.WhileChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.VarFieldChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.VarLocalChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.RedundantIfChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.TokenChecker" enabled="false">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.DeprecatedJavaChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.EmptyClassChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ClassTypeParameterChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[A-Z_]$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UnderscoreImportChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.LowercasePatternMatchChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.MultipleStringLiteralsChecker" enabled="true">
<parameters>
<parameter name="allowed"><![CDATA[2]]></parameter>
<parameter name="ignoreRegex"><![CDATA[^""$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ImportGroupingChecker" enabled="true"></check>
</scalastyle>
Binary file added scanner/tools/scalastyle.jar
Binary file not shown.