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

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
21 changes: 21 additions & 0 deletions analyzer-scalastyle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'java-library'
}

group = 'io.codety'
version = 'unspecified'

dependencies {
implementation project(':scanner-common')

}

test {
useJUnitPlatform()
}

jar {
enabled = true
archiveClassifier = '' //use empty string
version = null
}
3 changes: 3 additions & 0 deletions analyzer-scalastyle/doc/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Doc:
https://www.scalastyle.org/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.codety.scanner;

import io.codety.scanner.util.CodetyConstant;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(CodetyConstant.BASE_PACKAGE) //fixing the NoSuchBeanDefinitionException
//@Profile("!dev")
public class CodetyScannerTestMain implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.codety.scanner.analyzer.checkov;

import io.codety.common.dto.CodeAnalyzerType;
import io.codety.scanner.CodetyScannerTestMain;
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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootTest(classes = CodetyScannerTestMain.class)
public class CheckovCodeAnalyzerTest {

@Autowired
CheckovCodeAnalyzer checkovCodeAnalyzer;

@Test
void testAnalyze(){

String path = Paths.get("../","code-issue-examples", "iac").toFile().getAbsoluteFile().getPath();

String language = "java";
AnalyzerConfigurationDetailDto runnerConfiguration = new AnalyzerConfigurationDetailDto(language, CodeAnalyzerType.trivy);
Map<String, String> env = new HashMap<>();
AnalyzerRequest analyzerRequest = AnalyzerRequest.processSystemVariablesToRequest(env, new String[]{path});
List<CodeAnalysisResultDto> codeAnalysisResultDtos = checkovCodeAnalyzer.analyzeCode(runnerConfiguration, analyzerRequest);
Assertions.assertTrue(codeAnalysisResultDtos.size() > 0);

CodeAnalysisResultDto resultDto = codeAnalysisResultDtos.get(0);
Assertions.assertEquals(resultDto.getLanguage(), language);
Map<String, List<CodeAnalysisIssueDto>> issuesByFile = resultDto.getIssuesByFile();
Assertions.assertTrue(issuesByFile.size()>0);
for(String file : issuesByFile.keySet()) {
List<CodeAnalysisIssueDto> issues = issuesByFile.get(file);
Assertions.assertTrue(issues.size() > 0);
for (CodeAnalysisIssueDto issueDto : issues) {
Assertions.assertTrue(issueDto.getStartLineNumber() > 0);
Assertions.assertTrue(issueDto.getIssueCode().length() > 0);
Assertions.assertTrue(issueDto.getPriority() > 0);
Assertions.assertTrue(issueDto.getIssueCategory().length() > 0);
Assertions.assertTrue(issueDto.getDescription().length() > 10);
Assertions.assertTrue(issueDto.getFilePath().length() > 10);
}
}


}

}
142 changes: 142 additions & 0 deletions analyzer-scalastyle/src/test/resources/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>
2 changes: 2 additions & 0 deletions code-issue-examples/scala/emptyclass.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
object MyEmptyClass {
}
8 changes: 8 additions & 0 deletions code-issue-examples/scala/test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object OrderService {
def make (
userService: UserService,
discountForProuduct: DiscountService,
bonusForPurchase: BonusesService,
productIdIsValid: ProductService
): OrderService
}
1 change: 1 addition & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPY scanner/codety.sh /usr/bin/codety
COPY scanner/tools/ /tools/
COPY scanner/build/libs/app.jar /usr/app.jar
RUN chmod +x /usr/bin/codety
RUN curl -sfL https://oss.sonatype.org/content/repositories/releases/org/scalastyle/scalastyle_2.12/1.0.0/scalastyle_2.12-1.0.0-batch.jar > /tools/scalastyle.jar

WORKDIR /src
ENTRYPOINT ["codety"]
Expand Down
1 change: 1 addition & 0 deletions scanner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation project(':analyzer-trivy')
implementation project(':analyzer-golangcilint')
implementation project(':analyzer-codety')
implementation project(':analyzer-scalastyle')


}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ include 'analyzer-pmd'
include 'analyzer-pylint'
include 'analyzer-trivy'
include 'analyzer-golangcilint'
include 'analyzer-scalastyle'