Просмотр исходного кода

docs: add package import spec (#1878)

* docs: add package import spec

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

* add lint links

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

* add gofumpt guide

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

---------

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
Jason Lyu 1 год назад
Родитель
Сommit
a28705981b
2 измененных файлов с 46 добавлено и 0 удалено
  1. 25 0
      docs/en_US/CONTRIBUTING.md
  2. 21 0
      docs/zh_CN/CONTRIBUTING.md

+ 25 - 0
docs/en_US/CONTRIBUTING.md

@@ -33,10 +33,35 @@ $ git fetch upstream
 $ git checkout -b <my-branch> upstream/master
 $ git checkout -b <my-branch> upstream/master
 ```
 ```
 
 
+### Package Import Specification
+
+Reasonable package import order can enhance the cleanliness and standardization of the code.
+This project uses gci to automatically check the order of package imports, with priority given
+to `standard packages` > `third-party external packages` > `local project packages`, as follows:
+
+```go
+import (
+    "fmt"
+
+    "github.com/sirupsen/logrus"
+
+    "github.com/lf-edge/ekuiper/pkg/api"
+)
+```
+
+In the project root directory, you can run the command `gci write --skip-generated -s standard -s default -s "prefix(github.com/lf-edge/ekuiper)" .` to
+automatically reorder package imports.
+
+Alternatively, if you use GoLand, you can check `Group` and `Group stdlib imports` as well as their sub-options under
+`Settings > Editor > Code Style > Go > Imports` to enable automatic import sorting.
+
 ### Code conventions
 ### Code conventions
 
 
 - Use `go fmt` to format your code before commit code change. eKuiper Github Action CI pipeline reports error if it's
 - Use `go fmt` to format your code before commit code change. eKuiper Github Action CI pipeline reports error if it's
   not format by `go fmt`.
   not format by `go fmt`.
+- Run static code analysis with `make lint` to make sure there are no stylistic errors and common programming issues.
+  - If you encounter lint errors related to `gofumpt`, run `gofumpt -w .` in the project root directory to solve it.
+  - Check [golangci-lint](https://golangci-lint.run/) for more information on the corresponding lint errors.
 - Configuration key in config files uses camel case format.
 - Configuration key in config files uses camel case format.
 
 
 ### Debug your code
 ### Debug your code

+ 21 - 0
docs/zh_CN/CONTRIBUTING.md

@@ -33,9 +33,30 @@ $ git fetch upstream
 $ git checkout -b <my-branch> upstream/master
 $ git checkout -b <my-branch> upstream/master
 ```
 ```
 
 
+### 包引入规范
+
+合理的包引入顺序可以增强代码的整洁性和规范性。本项目使用 gci 自动检查包引入的顺序,优先级为 `标准包` > `第三方外部包` > `项目本地包`,如:
+
+```go
+import (
+    "fmt"
+
+    "github.com/sirupsen/logrus"
+
+    "github.com/lf-edge/ekuiper/pkg/api"
+)
+```
+
+在项目根目录下,可以运行 `gci write --skip-generated -s standard -s default -s "prefix(github.com/lf-edge/ekuiper)" .` 命令自动重新排序包引入顺序。
+
+或者如果你使用 GoLand,可以在 `Settings > Editor > Code Style > Go > Imports` 下勾选 `Group` 和 `Group stdlib imports` 以及相应的子选项来开启自动引入排序。
+
 ### 代码惯例
 ### 代码惯例
 
 
 - 在提交代码变更之前,使用 `go fmt` 来格式化你的代码。
 - 在提交代码变更之前,使用 `go fmt` 来格式化你的代码。
+- 使用 `make lint` 来运行静态代码分析以确保没有基本的格式或规范问题。
+  - 如果你遇到 `gofumpt` 相关的 lint 错误,直接在项目根目录运行 `gofumpt -w .` 即可解决。
+  - 其他 lint 相关的错误信息,请查看 [golangci-lint](https://golangci-lint.run/) 文档。
 - 配置文件中的配置键使用 camel 大小写格式。
 - 配置文件中的配置键使用 camel 大小写格式。
 
 
 ### 调试你的代码
 ### 调试你的代码