This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new a9f9f1d  [IOTDB-1156] Add IDE instructions for Code Formatting (#2686)
a9f9f1d is described below

commit a9f9f1d2d60b1c50a6c805e31839183a727b6cf4
Author: Jincheng Sun <[email protected]>
AuthorDate: Wed Feb 17 11:39:04 2021 +0800

    [IOTDB-1156] Add IDE instructions for Code Formatting (#2686)
    
    * [IOTDB-1156] Add IDE instructions for Code Formatting
---
 docs/Development/ContributeGuide.md    | 15 +++++++++++++++
 docs/zh/Development/ContributeGuide.md | 13 +++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/docs/Development/ContributeGuide.md 
b/docs/Development/ContributeGuide.md
index e825c84..1f98bba 100644
--- a/docs/Development/ContributeGuide.md
+++ b/docs/Development/ContributeGuide.md
@@ -83,6 +83,20 @@ Precautions:
 * Do not use special Unicode chars, e.g., U+FF1A 
 * Do not use the character of dollar (as we will use Latex to generate pdf 
files)
 
+### Code Formatting
+
+We use the [Spotless
+plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven) together 
with [google-java-format](https://github.com/google/google-java-format) to 
format our Java code. You can configure your IDE to automatically apply 
formatting on saving with these steps(Take idea as an example):
+
+1. Download the [google-java-format
+   plugin 
v1.7.0.5](https://plugins.jetbrains.com/plugin/8527-google-java-format/versions/stable/83169),
 it can be installed in IDEA (Preferences -> plugins -> search 
google-java-format), [More detailed setup 
manual](https://github.com/google/google-java-format#intellij-android-studio-and-other-jetbrains-ides)
+2. Install the plugin from disk (Plugins -> little gear icon -> "Install 
plugin from disk" -> Navigate to downloaded zip file)
+3. In the plugin settings, enable the plugin and keep the default Google code 
style (2-space indents)
+4. Remember to never update this plugin to a later version,until Spotless was 
upgraded to version 1.8+.
+5. Install the [Save Actions
+   plugin](https://plugins.jetbrains.com/plugin/7642-save-actions) , and 
enable the plugin, along with "Optimize imports" and "Reformat file"
+6. In the "Save Actions" settings page, setup a "File Path Inclusion" for 
`.*\.java`. Otherwise you will get unintended reformatting in other files you 
edit.
+
 ## Contributing code
 
 You can go to jira to pick up the existing issue or create your own issue and 
get it. The comment says that I can do this issue.
@@ -92,6 +106,7 @@ You can go to jira to pick up the existing issue or create 
your own issue and ge
 * Add code style as the root java-google-style.xml in the idea
 * Modify the code and add test cases (unit test, integration test)
   * Integration test 
reference:server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT
+* Use `mvn spotless:check` to check the code style and use `mvn 
spotless:apply` to correct the code style
 * Submit a PR, starting with [IOTDB-jira number]
 * Email to dev mailing list:(I've submitted a PR for issue IOTDB-xxx [link])
 * Make changes based on other people's reviews and continue to update until 
merged
diff --git a/docs/zh/Development/ContributeGuide.md 
b/docs/zh/Development/ContributeGuide.md
index 043929c..068a768 100644
--- a/docs/zh/Development/ContributeGuide.md
+++ b/docs/zh/Development/ContributeGuide.md
@@ -81,6 +81,18 @@ IoTDB 所有官网上的内容都在项目根目录的 docs 中:
 
 * Markdown 中的图片可上传至 https://github.com/thulab/iotdb/issues/543 获得 url
 
+## 代码格式化
+
+我们使用 [Spotless
+plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven) 和 
[google-java-format](https://github.com/google/google-java-format) 格式化Java代码. 
你可以通过以下步骤将IDE配置为在保存时自动应用格式以IDEA为例):
+
+1. 下载 [google-java-format-plugin 
v1.7.0.5](https://plugins.jetbrains.com/plugin/8527-google-java-format/versions/stable/83169),
 安装到IDEA(Preferences -> plugins -> search 
google-java-format),[更详细的操作手册](https://github.com/google/google-java-format#intellij-android-studio-and-other-jetbrains-ides)
                                                                                
                                                                                
             2. Install the plugin fro [...]
+2. 从磁盘安装 (Plugins -> little gear icon -> "Install plugin from disk" -> 
Navigate to downloaded zip file)
+3. 开启插件,并保持默认的GOOGLE格式 (2-space indents)
+4. 在Spotless没有升级到18+之前,不要升级google-java-format插件
+5. 安装 [Save Actions 
插件](https://plugins.jetbrains.com/plugin/7642-save-actions) , 并开启插件, 打开 
"Optimize imports" and "Reformat file" 选项.
+6. 在“Save Actions”设置页面中,将 "File Path Inclusion" 设置为.*\.java”, 
避免在编辑的其他文件时候发生意外的重新格式化
+
 ## 贡献代码
 
 可以到 jira 上领取现有 issue 或者自己创建 issue 再领取,评论说我要做这个 issue 就可以。
@@ -90,6 +102,7 @@ IoTDB 所有官网上的内容都在项目根目录的 docs 中:
 * 在 idea 中添加code style为 根目录的 java-google-style.xml
 * 修改代码,增加测试用例(单元测试、集成测试)
        * 集成测试参考: 
server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT
+* 用 `mvn spotless:check` 检查代码样式,并用`mvn spotless:apply`修复样式
 * 提交 PR, 以 [IOTDB-jira号] 开头
 * 发邮件到 dev 邮件列表:(I've submitted a PR for issue IOTDB-xxx [link])
 * 根据其他人的审阅意见进行修改,继续更新,直到合并

Reply via email to