Skip to content

feat: add auto detection of module name for goimport #3504

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

Closed
wants to merge 1 commit into from

Conversation

bosix
Copy link
Contributor

@bosix bosix commented Jan 26, 2023

Hi :),

we manage the .golanglint-ci.yml inside a central repo for several projects at our company. The ci/cd-pipeline fetches the current config when the linter is executed (e.g. on branch push).

The problem now is that repo-specific settings like the module name are not possible that way. Currently, golanglint-ci already supports auto-detection of the go version which is determinated via go.mod.

This pr introduces auto detection of the module name for goimport if the user enables it via config. I've thought about setting it be default if local-prefixes is empty but this would lead to a breacking change in linting behaviour. I created this pr as work-in-progress since I want to gather some feedback about this idea before fixing pipeline etc.

@bosix bosix added enhancement New feature or improvement feedback required Requires additional feedback labels Jan 26, 2023
@bosix bosix requested a review from ldez January 26, 2023 11:58
@ldez ldez changed the title WIP: feat: add auto detection of module name for goimport feat: add auto detection of module name for goimport Jan 26, 2023
@ldez ldez added blocked Need's direct action from maintainer and removed feedback required Requires additional feedback labels Jan 26, 2023
@ldez ldez marked this pull request as draft January 26, 2023 12:09
@ldez
Copy link
Member

ldez commented Jan 26, 2023

Kind of duplicate of #2363

@bosix
Copy link
Contributor Author

bosix commented Jan 26, 2023

@ldez I agree. It's almost the same.

Do you have changed your mind about the feature? As in #2363 (comment) you wrote that you think the feature has no valid use case.

If you think, it's a valid case, I'll help to make the implementation of sagikazarmark ready to merge.

@ldez
Copy link
Member

ldez commented Jan 26, 2023

Do you have changed your mind about the feature? As in #2363 (comment) you wrote that you think the feature has no valid use case.

I still think the same thing

@bosix
Copy link
Contributor Author

bosix commented Jan 26, 2023

@ldez So the best solution for our centrally managed configuration file would be for the pipeline to determine the module name and inject it into the configuration file, right?
Of course, we could also keep a copy of the configuration file in each repository, but this way changes to the linter rules would not be applied to all repositories immediately.

@ldez
Copy link
Member

ldez commented Jan 26, 2023

I have a question: why do you split the module imports and the other imports?
Just to understand the use-case.

@bosix
Copy link
Contributor Author

bosix commented Jan 26, 2023

@ldez the goal is to make the list of imported modules more cleary. For that reason it's useful to have 3 seperated blocks: one for std-libs, one for 3rd party libs and one for all project internal sub-modules.

@ldez
Copy link
Member

ldez commented Jan 26, 2023

Sorry I will deep a bit into the use case: why it's important to show the imported modules more clearly?

@bosix
Copy link
Contributor Author

bosix commented Jan 30, 2023

@ldez it's most about faster recognizing if we control an importet module or not. Further, we want to make linter rules as strict as possible since we are many developers and want to prevent different formatting which micht be caused by different ides or ide settings.

Theoretically, it would be an option as well if we could enforce that everything has to be in one block but since there is no linter out there which does this our solution is to enforce multiple groups which is stricter than one group.

Allow me one question according to this: why is it ok to auto-detect the go version but not the local go module name? I just want to unterstand the background.

@bosix
Copy link
Contributor Author

bosix commented Feb 13, 2023

Hi @ldez,

can you give any further information or a notice if there is any chance for this feature to get merged? If not, you can close this pr.

@ldez
Copy link
Member

ldez commented Feb 13, 2023

why is it ok to auto-detect the go version but not the local go module name?

I can see several problems related to Go module name: multi-module repo, Go workspaces, runs outside of the root folder, etc.
The Go version is much less problematic, and a "wrong" detection will not change all your code or create a lot of reports.

Also, you are focused on go-import but there is also gci on the same topic.

@bosix
Copy link
Contributor Author

bosix commented Feb 13, 2023

I therefore assume that the impact of the function, especially if the module detection does not work properly, is too large and therefore not merged.

Thank you for your feedback.

@bosix bosix closed this Feb 13, 2023
@ldez ldez added declined and removed blocked Need's direct action from maintainer labels Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants