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

Add thelper linter #1541

Merged
merged 1 commit into from
Dec 13, 2020
Merged

Add thelper linter #1541

merged 1 commit into from
Dec 13, 2020

Conversation

kulti
Copy link
Contributor

@kulti kulti commented Dec 8, 2020

Hi, I'm the author of thelper linter.

Hope you find it useful and accept this PR.

@boring-cyborg
Copy link

boring-cyborg bot commented Dec 8, 2020

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Dec 8, 2020

CLA assistant check
All committers have signed the CLA.

@ldez ldez added the linter: new Support new linter label Dec 8, 2020
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

Thanks! Would you mind adding your linter and the available settings, even though default, to .golangci.example.yml? This will be used to generate documentation at golangci-lint.run.

Could you also add tests for the rules t_first and t_name in test/testdata/thelper.go?

@kulti
Copy link
Contributor Author

kulti commented Dec 9, 2020

@ldez, thank you for your suggestions.

I've added config examples and tests for all available checks.

@ldez
Copy link
Member

ldez commented Dec 9, 2020

I would like to suggest to you some changes to improve the configuration UX.
The value of the checks can be hard to find and it can be error-prone because it is a string.

I see 2 approaches:

  • a slice-based configuration
  • a boolean-based configuration

I would prefer a boolean-based configuration because I don't have to know the name of the options.

Slice based configuration

  # .golangci.example.yml

  thelper:
    checks:
      - t_first
      - t_name
      - t_begin
      - b_first
      - b_name
      - b_begin
// pkg/config/config.go


type ThelperSettings struct {
	Checks []string
}
	// pkg/golinters/thelper.go

	cfgMap := map[string]map[string]interface{}{}
	if cfg != nil {
		cfgMap[a.Name] = map[string]interface{}{
			"checks": strings.Join(cfg.Checks, ","),
		}
	}

Boolean based configuration

  thelper:
    test:
      first: true
      name: true
      begin: true
    benchmark:
      first: true
      name: true
      begin: true
type ThelperSettings struct {
	Test   struct {
		First bool `mapstructure:"first"`
		Name  bool `mapstructure:"name"`
		Begin bool `mapstructure:"begin"`
	} `mapstructure:"test"`
	Benchmark struct {
		First bool `mapstructure:"first"`
		Name  bool `mapstructure:"name"`
		Begin bool `mapstructure:"begin"`
	} `mapstructure:"benchmark"`
}
	var opts []string

	if cfg.Test.Name {
		opts = append(opts, "t_name")
	}
	if cfg.Test.Begin {
		opts = append(opts, "t_begin")
	}
	if cfg.Test.First {
		opts = append(opts, "t_first")
	}

	if cfg.Benchmark.Name {
		opts = append(opts, "b_name")
	}
	if cfg.Benchmark.Begin {
		opts = append(opts, "b_begin")
	}
	if cfg.Benchmark.First {
		opts = append(opts, "b_first")
	}

	cfgMap := map[string]map[string]interface{}{}
	if cfg != nil {
		cfgMap[a.Name] = map[string]interface{}{
			"checks": strings.Join(opts, ","),
		}
	}

WDYT?

@kulti
Copy link
Contributor Author

kulti commented Dec 12, 2020

I think boolean-based configuration looks great 👍 I've copy-pasted it with a few modifications.

@ldez
Copy link
Member

ldez commented Dec 12, 2020

have you thought about using tag/version?

There are several advantages:

  • it's more "Go module idiomatic"
  • that allow the dependabot to update automatically golangci-lint when you release a new version

@kulti
Copy link
Contributor Author

kulti commented Dec 13, 2020

Well, I thought about thelper project in rolling release model. But I never work with dependabot before. Now I see versioning has sense for simple project too.

PR is updated.

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@ldez ldez changed the title add thelper linter Add thelper linter Dec 13, 2020
@ldez ldez merged commit 0370d3a into golangci:master Dec 13, 2020
@golangci-automator
Copy link

Hey, @kulti — we just merged your PR to golangci-lint! 🔥🚀

golangci-lint is built by awesome people like you. Let us say “thanks”: we just invited you to join the GolangCI organization on GitHub.
This will add you to our team of maintainers. Accept the invite by visiting this link.

By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.
More information about contributing is here.

Thanks again!

@ldez ldez added this to the v1.34 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: new Support new linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants