From 800c94d2cb52b6e35a057d8e9e94b5baeb919de6 Mon Sep 17 00:00:00 2001 From: catchcatchus Date: Sat, 7 Sep 2024 22:46:27 -0700 Subject: [PATCH] add analyzers --- analyzer-shellcheck/build.gradle | 21 ++++++++++++++ .../codety/scanner/CodetyScannerTestMain.java | 17 +++++++++++ analyzer-stylelint/build.gradle | 21 ++++++++++++++ .../codety/scanner/CodetyScannerTestMain.java | 17 +++++++++++ .../src/test/resources/test-output.json | 29 +++++++++++++++++++ code-issue-examples/css/bad-css.css | 4 +++ image/Dockerfile | 5 ++-- image/publish_image.sh | 8 +++-- .../codety/common/dto/CodeAnalyzerType.java | 1 + scanner/build.gradle | 2 ++ settings.gradle | 2 ++ 11 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 analyzer-shellcheck/build.gradle create mode 100644 analyzer-shellcheck/src/test/java/io/codety/scanner/CodetyScannerTestMain.java create mode 100644 analyzer-stylelint/build.gradle create mode 100644 analyzer-stylelint/src/test/java/io/codety/scanner/CodetyScannerTestMain.java create mode 100644 analyzer-stylelint/src/test/resources/test-output.json create mode 100644 code-issue-examples/css/bad-css.css diff --git a/analyzer-shellcheck/build.gradle b/analyzer-shellcheck/build.gradle new file mode 100644 index 0000000..423cc55 --- /dev/null +++ b/analyzer-shellcheck/build.gradle @@ -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 +} diff --git a/analyzer-shellcheck/src/test/java/io/codety/scanner/CodetyScannerTestMain.java b/analyzer-shellcheck/src/test/java/io/codety/scanner/CodetyScannerTestMain.java new file mode 100644 index 0000000..cf24031 --- /dev/null +++ b/analyzer-shellcheck/src/test/java/io/codety/scanner/CodetyScannerTestMain.java @@ -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 { + + } +} \ No newline at end of file diff --git a/analyzer-stylelint/build.gradle b/analyzer-stylelint/build.gradle new file mode 100644 index 0000000..423cc55 --- /dev/null +++ b/analyzer-stylelint/build.gradle @@ -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 +} diff --git a/analyzer-stylelint/src/test/java/io/codety/scanner/CodetyScannerTestMain.java b/analyzer-stylelint/src/test/java/io/codety/scanner/CodetyScannerTestMain.java new file mode 100644 index 0000000..cf24031 --- /dev/null +++ b/analyzer-stylelint/src/test/java/io/codety/scanner/CodetyScannerTestMain.java @@ -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 { + + } +} \ No newline at end of file diff --git a/analyzer-stylelint/src/test/resources/test-output.json b/analyzer-stylelint/src/test/resources/test-output.json new file mode 100644 index 0000000..9d89914 --- /dev/null +++ b/analyzer-stylelint/src/test/resources/test-output.json @@ -0,0 +1,29 @@ +[ + { + "source": "/Users/user/git/codety-scanner/code-issue-examples/css/bad-css.css", + "deprecations": [], + "invalidOptionWarnings": [], + "parseErrors": [], + "errored": true, + "warnings": [ + { + "line": 1, + "column": 6, + "endLine": 2, + "endColumn": 2, + "rule": "block-no-empty", + "severity": "error", + "text": "Unexpected empty block (block-no-empty)" + }, + { + "line": 4, + "column": 1, + "endLine": 4, + "endColumn": 5, + "rule": "comment-no-empty", + "severity": "error", + "text": "Unexpected empty comment (comment-no-empty)" + } + ] + } +] \ No newline at end of file diff --git a/code-issue-examples/css/bad-css.css b/code-issue-examples/css/bad-css.css new file mode 100644 index 0000000..01c04b4 --- /dev/null +++ b/code-issue-examples/css/bad-css.css @@ -0,0 +1,4 @@ +hello{ +} + +/**/ diff --git a/image/Dockerfile b/image/Dockerfile index 5f29f5e..ce8ee5d 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -2,11 +2,12 @@ FROM amazoncorretto:17-alpine-jdk RUN apk add --no-cache python3 py3-pip go +RUN apk add --no-cache shellcheck 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 RUN npm install --prefix /usr/local/eslint8/ eslint@8.x typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin - +RUN npm install --prefix /usr/local/stylelint/ stylelint # !!!!!!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 @@ -18,10 +19,10 @@ RUN pip3 install checkov --break-system-packages RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.60.3 RUN golangci-lint --version - RUN apk add --no-cache ruby-dev cmake clang build-base #RUN export CC=clang #RUN export CXX=clang++ +# the rubocop build is kinda slow in Alpine RUN gem install -V rubocop RUN rubocop --version diff --git a/image/publish_image.sh b/image/publish_image.sh index 8645946..5dac33b 100755 --- a/image/publish_image.sh +++ b/image/publish_image.sh @@ -18,9 +18,6 @@ fi echo " ========= Build application end ========": -git tag -a "$DOCKER_BUILD_VERSION" -m "tag version $DOCKER_BUILD_VERSION" -git push origin "$DOCKER_BUILD_VERSION" - #--platform=linux/amd64,linux/arm64 echo " ========= Build and publish images start ========": docker buildx build --platform=linux/amd64 -t "$DOCKER_IMG":$DOCKER_BUILD_VERSION -t "$DOCKER_IMG":latest -f image/Dockerfile . --push @@ -28,6 +25,11 @@ if [ $? -ne 0 ]; then echo "Failed to build multi-platform container, create a new builder may fix the issue: '$> docker buildx create --name mybuilder --use ' " exit 1; fi + + +git tag -a "$DOCKER_BUILD_VERSION" -m "tag version $DOCKER_BUILD_VERSION" +git push origin "$DOCKER_BUILD_VERSION" + echo " ========= Build and publish images end ========": echo "====User below command to test the container: =====" diff --git a/scanner-common/src/main/java/io/codety/common/dto/CodeAnalyzerType.java b/scanner-common/src/main/java/io/codety/common/dto/CodeAnalyzerType.java index 0411ba6..0aca543 100644 --- a/scanner-common/src/main/java/io/codety/common/dto/CodeAnalyzerType.java +++ b/scanner-common/src/main/java/io/codety/common/dto/CodeAnalyzerType.java @@ -14,6 +14,7 @@ public enum CodeAnalyzerType { , golangcilint(20) , scalastyle(30) , rubocop(40) + , stylelint(50) ; public final int codeAnalyzerType; diff --git a/scanner/build.gradle b/scanner/build.gradle index fd9ec38..1bd7eb5 100644 --- a/scanner/build.gradle +++ b/scanner/build.gradle @@ -36,6 +36,8 @@ dependencies { implementation project(':analyzer-golangcilint') implementation project(':analyzer-codety') implementation project(':analyzer-scalastyle') + implementation project(':analyzer-stylelint') + implementation project(':analyzer-shellcheck') implementation project(':analyzer-rubocop') diff --git a/settings.gradle b/settings.gradle index 349e2a6..7cb62c3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,4 +13,6 @@ include 'analyzer-pylint' include 'analyzer-trivy' include 'analyzer-golangcilint' include 'analyzer-scalastyle' +include 'analyzer-stylelint' +include 'analyzer-shellcheck' include 'analyzer-rubocop'