Skip to content

docs: fix pattern of forbidigo in example config yaml #2000

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

Merged
merged 3 commits into from
May 19, 2021

Conversation

ytakaya
Copy link
Contributor

@ytakaya ytakaya commented May 19, 2021

The pattern of forbidigo in .golangci.example.yaml was not the correct pattern so I fixed.
It has been modified with reference to the original usage.

ginkgo\\.F.* in the pattern before modification does not behave as expected.

@boring-cyborg
Copy link

boring-cyborg bot commented May 19, 2021

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented May 19, 2021

CLA assistant check
All committers have signed the CLA.

@ldez ldez changed the title doc: fix pattern of forbidigo in example config yaml docs: fix pattern of forbidigo in example config yaml May 19, 2021
@butuzov
Copy link
Member

butuzov commented May 19, 2021

Can we leave in place simpler patterns (which are the working ones?)

@butuzov
Copy link
Member

butuzov commented May 19, 2021

Maybe it just worth mentioning that pattern should be a valid regular expression?

@ytakaya
Copy link
Contributor Author

ytakaya commented May 19, 2021

I think that we need to encourage user to use valid regular expression because regexp package is used in forbidigo.
https://github.com/ashanbrown/forbidigo/blob/f30240a5170c8f6a62cf603ea541c0ff2008a6be/forbidigo/forbidigo.go#L70
But simplicity is also important, so using symbols like ^ and $ may be excessive.

I think the biggest problem is that there are patterns in the documentation that don't work.
ginkgo\\.F.* does not match an identifier like ginkgo.FContext() or ginkgo.FDescribe(), so it needs to be fixed to ginkgo\.F.* or "ginkgo\\.F.*".
By using double quotation marks, \ is escaped and becomes the valid regular expression.

Based on the above, here's what I think is a good example.

- fmt\.Errorf
- fmt\.Print.*
- ginkgo\.F.*

@butuzov
Copy link
Member

butuzov commented May 19, 2021

Absolutely agree! How about:

  • we list the same package/function with various interpretations
  • mention that forbidigo require valid regexp
  • will use single quotes for YAML string (so we don't have double quoting \\)
- fmt.Print
- 'fmt\.Print.*'
- '^fmt.Print.*$'

@ldez
Copy link
Member

ldez commented May 19, 2021

@butuzov I understand the idea, but it can be confusing for users to use 3 variations of the same expression.

I would prefer:

  forbidigo:
    # Forbid the following identifiers
    forbid:
      - ^print.*$
      - 'fmt\.Print.*'

@butuzov
Copy link
Member

butuzov commented May 19, 2021

Can we leave at least one simplified pattern?

@ldez
Copy link
Member

ldez commented May 19, 2021

There no real simplified pattern: a dot in a regex doesn't mean dot but every character.

ex: fmt.Print matches fmtaPrint(), afmtaPrint(), afmtaPrintExample(), and samfmt.Print()

@butuzov
Copy link
Member

butuzov commented May 19, 2021

... and fmt.Print, and afmtaPrint()... and after it matches last one - user will return to example config and read that value require to be valid regexp (which is missing in your example and initial author's PR ). Note about regexp is important, and can help users in the future.

@butuzov
Copy link
Member

butuzov commented May 19, 2021

Compare it to the exhaustivestruct struct patterns which I was initially sure are regexp (and they are not).

@ldez
Copy link
Member

ldez commented May 19, 2021

I agree with adding a comment about the regex syntax requirement. 👍

@ytakaya
Copy link
Contributor Author

ytakaya commented May 19, 2021

I've modified it based on your opinions.
Does this make any difference to your recognition?

@butuzov
Copy link
Member

butuzov commented May 19, 2021

my suggestion deleted, As pointed @ldez it wasn't based on right commit. Here is what I was suggesting (to move test to main linter block above forbid setting).

+ # Forbid the following identifiers (identifiers are written using regexp):
- # Forbid the following identifiers    
  forbid:

@ldez ldez merged commit b73972f into golangci:master May 19, 2021
@golangci-automator
Copy link

Hey, @ytakaya — 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!

Copy link
Contributor

@ashanbrown ashanbrown left a comment

Choose a reason for hiding this comment

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

👍

SeigeC pushed a commit to SeigeC/golangci-lint that referenced this pull request Apr 4, 2023
@ldez ldez added this to the v1.41 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants