Skip to content

Commit

Permalink
[Revert](code-style) revert FE code-format #25033 and #26488 (#26505)
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman authored Nov 7, 2023
1 parent 8da1a9a commit efd1aa3
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
with:
persist-credentials: false
submodules: recursive
fetch-depth: 0

- name: Paths Filter
uses: ./.github/actions/paths-filter
Expand All @@ -49,7 +48,8 @@ jobs:
with:
maven-version: 3.8.4

- name: Run java spotless & checkstyle
- name: Run java checkstyle
if: steps.filter.outputs.fe_changes == 'true'
run:
cd fe && mvn clean spotless:check checkstyle:check
cd fe && mvn clean checkstyle:check

12 changes: 3 additions & 9 deletions docs/en/community/developer-guide/java-format-code.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
{
"title": "Java Format Code",
"language": "en"
"title": "Java Format Code",
"language": "en"
}
---

Expand Down Expand Up @@ -89,17 +89,11 @@ After add the `build-support/IntelliJ-code-format.xml` file. Click `Code/Rearran

![](/images/idea-rearrange-code.png)

## Spotless Plugin

An error was found when checking the project code through `mvn spotless:check`, and then used `mvn spotless:apply` to format the code; when checking again, the formatting error disappeared.

Tip: We use incremental code formatting, spotless will apply only to files which have changed since `origin/master`. If a `No such reference` error is prompted, please calling `git fetch origin master` before you call Spotless.
Please refer to [how-can-i-enforce-formatting-gradually-aka-ratchet](https://github.com/diffplug/spotless/tree/main/plugin-maven#how-can-i-enforce-formatting-gradually-aka-ratchet) for details.

## Remove unused header

**CTRL + ALT + O --->** to remove the unused imports in windows.

Auto remove unused header and reorder according to configure xml:

Click `Preferences->Editor->Auto Import->Optimize Imports on the Fly`

20 changes: 10 additions & 10 deletions docs/zh-CN/community/developer-guide/java-format-code.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
{
"title": "Java 代码格式化",
"language": "zh-CN"
"title": "Java 代码格式化",
"language": "zh-CN"
}
---

Expand Down Expand Up @@ -42,6 +42,13 @@ standard java package
* 禁止使用 `import *`
* 禁止使用 `import static`

## 编译时检查

现在,在使用`maven`进行编译时,会默认进行`CheckStyle`检查。此检查会略微降低编译速度。如果想跳过此检查,请使用如下命令进行编译
```
mvn clean install -DskipTests -Dcheckstyle.skip
```

## Checkstyle 插件

现在的 `CI` 之中会有 `formatter-check` 进行代码格式化检测。
Expand Down Expand Up @@ -80,17 +87,10 @@ Checkstyle 会按照 [Class and Interface Declarations](https://www.oracle.com/j

![](/images/idea-rearrange-code.png)

## Spotless 插件

通过 mvn spotless:check 检查项目代码时发现错误,接着使用 mvn spotless:apply 进行代码格式化;再次检查时,格式化错误消失。

提示:我们使用增量代码格式,spotless 仅适用于自“origin/master”以来已更改的文件。如果提示“No such reference”错误,请在调用 Spotless 之前调用“git fetch origin master”。
请参考 [how-can-i-enforce-formatting-gradually-aka-ratchet](https://github.com/diffplug/spotless/tree/main/plugin-maven#how-can-i-enforce-formatting-gradually-aka-ratchet)

## Remove unused header

默认快捷键 **CTRL + ALT + O --->** 仅仅删除未使用的导入。

自动移除并且 Reorder :

点击 `Preferences->Editor->General->Auto Import->Optimize Imports on the Fly`
点击 `Preferences->Editor->General->Auto Import->Optimize Imports on the Fly`
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
// "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.

// under the License.
22 changes: 21 additions & 1 deletion fe/check/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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
Expand Down Expand Up @@ -42,9 +44,13 @@ under the License.
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="Header">
<property name="headerFile" value="check/checkstyle/checkstyle-apache-header.txt"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="150"/>
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="NewlineAtEndOfFile">
Expand Down Expand Up @@ -93,6 +99,14 @@ under the License.
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
</module>
<module name="LeftCurly">
<property name="tokens"
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT,
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens"
Expand Down Expand Up @@ -140,6 +154,12 @@ under the License.
<!-- Imports -->
<module name="AvoidStarImport"/>
<module name="AvoidStaticImport"/>
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
</module>
<module name="ImportControl">
<property name="file" value="check/checkstyle/import-control.xml"/>
</module>
Expand Down
5 changes: 4 additions & 1 deletion fe/check/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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
Expand Down Expand Up @@ -38,4 +40,5 @@ under the License.
<allow pkg="org.junit.jupiter"/>
<disallow pkg="org.junit"/>
</subpackage>
</import-control>
</import-control>

8 changes: 5 additions & 3 deletions fe/check/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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
Expand All @@ -17,8 +19,8 @@ under the License.
-->

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- Excludes test files from having Javadocs for classes and methods -->
Expand Down Expand Up @@ -61,4 +63,4 @@ under the License.
<suppress files="HiveMetaStoreClient\.java" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]com[\\/]amazonaws[\\/]glue[\\/]catalog[\\/]" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]com[\\/]aliyun[\\/]datalake[\\/]metastore[\\/]hive2[\\/]" checks="[a-zA-Z0-9]*"/>
</suppressions>
</suppressions>
Loading

0 comments on commit efd1aa3

Please sign in to comment.