Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(gci/import): improve golangci.yml and add gci linter #4010

Merged
merged 5 commits into from
Dec 7, 2024
Merged

Conversation

houseme
Copy link
Member

@houseme houseme commented Dec 5, 2024

ci: add gci.yml and improve golangci.yml

  1. Added gci.yml for GCI, a tool to control Go package import order and ensure determinism.
  2. Improved golangci.yml by adding the goimports linter.
  3. Optimized some import statements in the code.

1. Added `gci.yml` for GCI, a tool to control Go package import order and ensure determinism.
2. Improved `golangci.yml` by adding the `goimports` linter.
3. Optimized some import statements in the code.
@houseme houseme changed the title ci(gci/import): add gci.yml and improve golangci.yml ci(gci/import): improve golangci.yml and add gci linter Dec 5, 2024
@gqcn
Copy link
Member

gqcn commented Dec 5, 2024

如果我本地想要检测怎么做呢,直接make lint吗,还是说一定要安装gci这个包?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


What if I want to detect it locally? Should I directly make lint, or do I have to install the gci package?

@houseme
Copy link
Member Author

houseme commented Dec 5, 2024

如果我本地想要检测怎么做呢,直接make lint吗,还是说一定要安装gci这个包?

如果安装了 golangci-lint ,直接运行: golangci-lint run -c .golangci.yml 检测。

下面命令是按照规则直接修改代码:

gci write --custom-order --skip-generated --skip-vendor -s blank -s standard -s default -s dot -s localmodule -s "prefix(github.com/gogf/gf)" ./

按照 自定义的排序顺序,忽略生成的代码以及 vendor 目录,自定义顺序为:blank > standard > default > dot > localmodule > custom

gci: https://github.com/daixiang0/gci

@houseme houseme requested review from gqcn and hailaz December 5, 2024 13:06
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


What if I want to detect it locally? Should I directly make lint, or do I have to install the gci package?

If golangci-lint is installed, run directly: golangci-lint run -c .golangci.yml to detect.

The following commands directly modify the code according to the rules:

gci write --custom-order --skip-generated --skip-vendor -s blank -s standard -s default -s dot -s localmodule -s "prefix(github.com/gogf/gf)" ./

According to the custom sort order, ignoring the generated code and vendor directory, the custom order is: blank>standard>default>dot>localmodule>custom.

@niluan304
Copy link
Contributor

个人觉得标准库的优先级,应该最高,以及 localmodule 应该最低

gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard  \
-s blank  \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf)" \
-s localmodule  \
./

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Personally, I think the standard library should have the highest priority, and localmodule should have the lowest priority.

gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard \
-s blank \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf)" \
-s localmodule \
./

@houseme
Copy link
Member Author

houseme commented Dec 6, 2024

个人觉得标准库的优先级,应该最高,以及 localmodule 应该最低

gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard  \
-s blank  \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf)" \
-s localmodule  \
./

如果里面没有嵌套cmd这些,可以按照这个处理
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Personally, I think the standard library should have the highest priority, and localmodule should have the lowest priority.

gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard \
-s blank \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf)" \
-s localmodule \
./

If there are no nested cmds in it, you can handle it according to this
image

@houseme
Copy link
Member Author

houseme commented Dec 6, 2024

gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard  \
-s blank  \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf/v2)" \
-s "prefix(github.com/gogf/gf/cmd)" \
-s "prefix(github.com/gogf/gf/contrib)" \
-s "prefix(github.com/gogf/gf/example)" \
./

目前建议这样使用,来修复出现的提示

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


gci write --custom-order \
--skip-generated \
--skip-vendor \
-s standard \
-s blank \
-s default \
-s dot \
-s "prefix(github.com/gogf/gf/v2)" \
-s "prefix(github.com/gogf/gf/cmd)" \
-s "prefix(github.com/gogf/gf/contrib)" \
-s "prefix(github.com/gogf/gf/example)" \
./

It is currently recommended to use this method to fix the prompts that appear.

@gqcn gqcn merged commit b0b84a3 into master Dec 7, 2024
40 checks passed
@gqcn gqcn deleted the feature/gci branch December 7, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants