Skip to content
New issue

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

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

Already on GitHub? # to your account

goheader: fix relative template path #3748

Closed
wants to merge 1 commit into from

Conversation

thejan2009
Copy link

go-header template-path setting is usually a relative filepath. As a result, the linter only worked when golangci-lint was invoked from that folder.

We detect if the template path is relative and prefix it with config path.

go-header_bad.go test case was modified because old files are not checked https://github.com/denis-tingaikin/go-header/blob/v0.4.3/analyzer.go#L59-L63

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 31, 2023

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Mar 31, 2023

CLA assistant check
All committers have signed the CLA.

@thejan2009 thejan2009 force-pushed the master branch 2 times, most recently from 2200503 to bf97e8d Compare March 31, 2023 08:16
@ldez ldez added linter: update Update the linter implementation inside golangci-lint blocked Need's direct action from maintainer labels Mar 31, 2023
@ldez ldez self-requested a review March 31, 2023 08:56
@thejan2009
Copy link
Author

Hi, is there anything I can help with to unblock this PR?

I saw #3682 related to denis-tingaikin/go-header#22. Should that issue be fixed first?

@thejan2009
Copy link
Author

@ldez bump

@@ -1,6 +1,6 @@
linters-settings:
goheader:
template: MY {{title}}
template-path: go-header-template
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep both tests
and template and template-path
(with better naming for config and test files)

@Antonboom Antonboom added feedback required Requires additional feedback and removed blocked Need's direct action from maintainer labels Oct 17, 2023
go-header template-path setting is usually a relative filepath. As a
result, the linter only worked when golangci-lint was invoked from that
folder.

We detect if the template path is relative and prefix it with config
path.

go-header_bad.go test case was modified because old files are not
checked as seen here
https://github.com/denis-tingaikin/go-header/blob/v0.4.3/analyzer.go#L59-L63
Copy link
Contributor

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@@ -1,4 +1,4 @@
/*MY TITLE!*/ // want `Expected:TITLE\., Actual: TITLE!`
/*MY TITLE?*/ // want `Expected:TITLE\., Actual: TITLE?`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra change?

@@ -0,0 +1,6 @@
/*MY TITLE.*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is go-header-template_bad?

/*MY TITLE.*/

//golangcitest:args -Egoheader
//golangcitest:config_path testdata/configs/go-header-template.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question – how it works without test/ prefix?
Looks like your filepath.Join is not covered 🤔

@@ -247,6 +247,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" {
stylecheckCfg.GoVersion = trimGoVersion(m.cfg.Run.Go)
}

if goheaderCfg != nil {
goheaderCfg.LintConfigDir = m.cfg.GetConfigDir()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant you can override goheaderCfg.TemplatePath at this level.
But I cannot decide which option is better

@@ -247,6 +247,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" {
stylecheckCfg.GoVersion = trimGoVersion(m.cfg.Run.Go)
}

if goheaderCfg != nil {
goheaderCfg.LintConfigDir = m.cfg.GetConfigDir()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try to run golangci-lint without config, it works as expected?

@ldez ldez added blocked Need's direct action from maintainer and removed feedback required Requires additional feedback labels Oct 18, 2023
@ldez ldez closed this in #5339 Jan 28, 2025
@ldez ldez added declined and removed blocked Need's direct action from maintainer labels Jan 28, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
declined linter: update Update the linter implementation inside golangci-lint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants