This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch chore/code-style in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 2c218d693a11f3d1fdca3bb9d32c3ba3f29cb1a3 Author: kezhenxu94 <[email protected]> AuthorDate: Sun Feb 9 21:00:15 2020 +0800 Review code styles automatically ### Motivation: Review code styles with some bots automatically. ### Modifications: - Set up ReviewDog in GitHub Action to review code style. - Add more check rules to checkstyle plugin. ### Result: - Obvious code styles can be reviewed and commented automatically. --- .github/workflows/code-style.yaml | 42 ++++++++++++++++++ .reviewdog.yml | 22 ++++++++++ apm-checkstyle/checkStyle.xml | 50 +++++++++++++++------- .../skywalking/apm/agent/SkyWalkingAgent.java | 8 ++++ .../telemetry/api/TelemetryRelatedContext.java | 2 +- pom.xml | 3 +- 6 files changed, 109 insertions(+), 18 deletions(-) diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml new file mode 100644 index 0000000..9aa8764 --- /dev/null +++ b/.github/workflows/code-style.yaml @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +name: reviewdog + +on: + pull_request: + +jobs: + reviewdog: + name: reviewdog + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Setup reviewdog + run: | + mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin + echo ::add-path::$HOME/bin + echo ::add-path::$(go env GOPATH)/bin # for Go projects + - name: Generate checkstyle report + run: ./mvnw clean -Dcheckstyle.fails.on.error=false checkstyle:checkstyle-aggregate + - name: Run reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.reviewdog.yml b/.reviewdog.yml new file mode 100644 index 0000000..f7c1edf --- /dev/null +++ b/.reviewdog.yml @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +runner: + maven-checkstyle: + cmd: cat target/checkstyle-result.xml + format: checkstyle + level: warning diff --git a/apm-checkstyle/checkStyle.xml b/apm-checkstyle/checkStyle.xml index 00b501b..beec2a9 100755 --- a/apm-checkstyle/checkStyle.xml +++ b/apm-checkstyle/checkStyle.xml @@ -20,13 +20,13 @@ <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://checkstyle.org/dtds/configuration_1_3.dtd"> -<!--Refer http://checkstyle.sourceforge.net/reports/google-java-style.html#s2.2-file-encoding --> <module name="Checker"> <property name="localeLanguage" value="en"/> - <!--To configure the check to report on the first instance in each file--> - <module name="FileTabCharacter"/> + <module name="FileTabCharacter"> + <property name="eachLine" value="true"/> + </module> <module name="RegexpSingleline"> <property name="format" value="System\.out\.println"/> @@ -34,6 +34,14 @@ </module> <module name="RegexpSingleline"> + <property name="severity" value="warning"/> + <property name="format" value="^\s*\*\s*@author"/> + <property name="minimum" value="0"/> + <property name="maximum" value="0"/> + <property name="message" value="ASF project doesn't allow @author copyright."/> + </module> + + <module name="RegexpSingleline"> <property name="format" value=".*[\u3400-\u4DB5\u4E00-\u9FA5\u9FA6-\u9FBB\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9\uFF00-\uFFEF\u2E80-\u2EFF\u3000-\u303F\u31C0-\u31EF]+.*"/> <property name="message" value="Not allow chinese character !"/> @@ -45,9 +53,7 @@ <module name="TreeWalker"> - <module name="UnusedImports"> - <property name="processJavadoc" value="true"/> - </module> + <module name="UnusedImports"/> <module name="RedundantImport"/> <!--Checks that classes that override equals() also override hashCode()--> @@ -97,24 +103,19 @@ <module name="GenericWhitespace"/> <module name="NoWhitespaceBefore"/> <module name="NoWhitespaceAfter"/> - <module name="WhitespaceAround"> - <property name="allowEmptyConstructors" value="true"/> - <property name="allowEmptyMethods" value="true"/> - </module> + <module name="WhitespaceAround"/> <module name="Indentation"/> <module name="MethodParamPad"/> <module name="ParenPad"/> - <module name="TypecastParenPad"/> - <module name="TypecastParenPad"/> <module name="ImportControl"> - <property name="file" value="apm-checkstyle/importControl.xml" /> - <property name="path" value="apm-sniffer/(apm-sdk-plugin|bootstrap-plugins|optional-plugins)/.+/src/main/.+Instrumentation.java$" /> + <property name="file" value="apm-checkstyle/importControl.xml"/> + <property name="path" value="apm-sniffer/(apm-sdk-plugin|bootstrap-plugins|optional-plugins)/.+/src/main/.+Instrumentation.java$"/> </module> <module name="ImportControl"> - <property name="file" value="apm-checkstyle/importControl.xml" /> - <property name="path" value="apm-sniffer/apm-toolkit-activation/.+/src/main/.+Activation.java$" /> + <property name="file" value="apm-checkstyle/importControl.xml"/> + <property name="path" value="apm-sniffer/apm-toolkit-activation/.+/src/main/.+Activation.java$"/> </module> </module> @@ -123,4 +124,21 @@ <property name="multiLines" value="1, 2, 3, 18"/> </module> + <module name="TreeWalker"> + <property name="severity" value="warning"/> + + <module name="AvoidStarImport"/> + + <module name="TypecastParenPad"> + <property name="option" value="space"/> + </module> + + <module name="NonEmptyAtclauseDescription"/> + + <module name="EmptyLineSeparator"> + <property name="allowNoEmptyLineBetweenFields" value="true"/> + <property name="allowMultipleEmptyLines" value="false"/> + <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/> + </module> + </module> </module> diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java index e25256d..e3b4fe6 100644 --- a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java +++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java @@ -184,6 +184,14 @@ public class SkyWalkingAgent { logger.error("Enhance class " + typeName + " error.", throwable); } + /** + * TODO: just to test reviewdog + * + * @param typeName + * @param classLoader + * @param module + * @param loaded + */ @Override public void onComplete(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) { } diff --git a/oap-server/server-telemetry/telemetry-api/src/main/java/org/apache/skywalking/oap/server/telemetry/api/TelemetryRelatedContext.java b/oap-server/server-telemetry/telemetry-api/src/main/java/org/apache/skywalking/oap/server/telemetry/api/TelemetryRelatedContext.java index 3bcecca..9c3d25c 100644 --- a/oap-server/server-telemetry/telemetry-api/src/main/java/org/apache/skywalking/oap/server/telemetry/api/TelemetryRelatedContext.java +++ b/oap-server/server-telemetry/telemetry-api/src/main/java/org/apache/skywalking/oap/server/telemetry/api/TelemetryRelatedContext.java @@ -26,7 +26,7 @@ public enum TelemetryRelatedContext { INSTANCE; private volatile String id = null; - TelemetryRelatedContext(){} + TelemetryRelatedContext() { } /** * Set a global ID to represent the current oap instance diff --git a/pom.xml b/pom.xml index 23ce627..4a5af50 100755 --- a/pom.xml +++ b/pom.xml @@ -218,6 +218,7 @@ <jmh.version>1.21</jmh.version> <gmaven-plugin.version>1.5</gmaven-plugin.version> <cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version> + <checkstyle.fails.on.error>true</checkstyle.fails.on.error> </properties> <dependencies> @@ -531,7 +532,7 @@ <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <includeTestSourceDirectory>true</includeTestSourceDirectory> - <failsOnError>true</failsOnError> + <failOnViolation>${checkstyle.fails.on.error}</failOnViolation> <sourceDirectories> <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
