Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

How to disable [exported method should have comment or be unexported #186

Closed
douglarek opened this issue Jan 13, 2016 · 35 comments
Closed

Comments

@douglarek
Copy link

I find lots of codes in golang source are not commented, how can I disable it ?

@douglarek douglarek changed the title How to disable [exported type should have comment or be unexported] How to disable [exported method should have comment or be unexported Jan 13, 2016
@dsymonds
Copy link
Contributor

See the README. There are deliberately no ways to selectively enable or disable specific messages. Ignore them if they don't seem relevant.

@douglarek
Copy link
Author

@dsymonds OK. i know this issue closed; but btw: any plan for "enable or disable specific messages. " ?

@dsymonds
Copy link
Contributor

No, there are no plans to change that.

@mgood
Copy link

mgood commented Nov 29, 2016

Users that want more configurability may want to try gometalinter which wraps golint and a bunch of other tools that do static analysis of Go code. It has a bunch of options to control which tools you want to use, and can filter out warnings you find too noisy. There are also extensions for a bunch of popular editors to integrate with it.

I think it's reasonable for golint to keep things simple and not support lots of configuration options, but gometalinter offers that configurability if you want it.

@mh-cbon
Copy link

mh-cbon commented May 24, 2017

I can t quiet find the precise option to disable only that warning in gometalinter. All or nothing, for instance the balance is in favor of All, thus keeps being annoyed by undesired messages. Bad experience.

If you know how to disable that specific warning, even better, on portion of code only, drop a message here to explain that.

@mgood
Copy link

mgood commented May 24, 2017

This option allows you to filter out any messages you want to disable:

-e, --exclude=REGEXP ...  Exclude messages matching these regular expressions.

See gometalinter --help for a list of other options. If you have other questions about using gometalinter please file an issue on that project instead.

@hitxiebing
Copy link

how do it?

@tqwewe
Copy link

tqwewe commented Oct 14, 2017

For command line:

gometalinter --exclude="\bexported \w+ (\S*['.]*)([a-zA-Z'.*]*) should have comment or be unexported\b"

For VSCode settings.json:

"go.lintTool": "gometalinter",
"go.lintFlags": [
	"--exclude=\"\bexported \\w+ (\\S*['.]*)([a-zA-Z'.*]*) should have comment or be unexported\b\""
],

@targence
Copy link

targence commented Jan 5, 2018

@acidic9

This is not working for me in VS Code 1.19.1
Instead I use this method:

    "go.lintFlags": [
        "--disable-all",
        "--enable=golint",
        "--config=~/.gometalinter"
    ]

cat ~/.gometalinter

{
  "Exclude": ["exported type (\\w+) should have comment or be unexported"]
}

@mgood
Copy link

mgood commented Jan 5, 2018

@targence that's more of a question for the VSCode Go project, or gometalinter, so it would be better to ask on one of those project instead.

@jiverson
Copy link

jiverson commented Feb 9, 2018

@targence

This worked for me:

"go.lintTool": "gometalinter",
"go.lintFlags": [
	"--config=${workspaceRoot}/.gometalinter"
]

cat .gometalinter

{
  "Exclude": ["exported \\w+ (\\S*['.]*)([a-zA-Z'.*]*) should have comment or be unexported"]
}

@PeterIttner
Copy link

gometalinter seems to disable all linting hints by default or has some other startup problems.
What worked for me is to just use golangci-lint in the settings

.vscode/settings.json:

{
    "go.lintTool": "golangci-lint"
}

@chetanyakan
Copy link

chetanyakan commented Dec 15, 2018

Depending on your usage, you might as well just use | grep -v "should have comment or be unexported" after golint command.

EDIT: You could have a makefile command.

TMPFILEGOLINT=golint.tmp

.PHONY: golint
golint:
	@echo Running GOLINT
	@cd server
	$(eval PKGS := $(shell go list ./... | grep -v /vendor/))
	@touch $(TMPFILEGOLINT)
	-@for pkg in $(PKGS) ; do \
		echo `golint $$pkg | grep -v "have comment" | grep -v "comment on exported" | grep -v "lint suggestions"` >> $(TMPFILEGOLINT) ; \
	done
	@grep -Ev "^$$" $(TMPFILEGOLINT) || true
	@if [ "$$(grep -Ev "^$$" $(TMPFILEGOLINT) | wc -l)" -gt "0" ]; then \
		rm -f $(TMPFILEGOLINT); echo "golint failure\n"; exit 1; else \
		rm -f $(TMPFILEGOLINT); echo "golint success\n"; \
	fi

@wwjue
Copy link

wwjue commented Jan 20, 2019

cat ~/.gometalinter.json
{
"Exclude": ["exported \w+ (\S*['.])([a-zA-Z'.]*) should have comment or be unexported"]
}

@larytet
Copy link

larytet commented Mar 7, 2019

lint_filters=( "receiver name should be a reflection of its identity" \
	"should have comment or be unexported"  \
	"comment on exported function" \
	"comment on exported method" "should have comment" \
	"rewrite if-else to switch statement" \
	"if block ends with a return statement, so drop this else and outdent its block" \
	"comment on exported type" "struct field \S+ should be" "method \S+ should be \S+"\
	"method parameter \S+ should be \S+" "func parameter \S+ should be \S+" )
	command=""$GOPATH/bin/golint"  ./..."
for filter in "${lint_filters[@]}"
do
	command="$command | grep -v -E \"$filter\"" 
done

eval "$command"  

@sgehrman
Copy link

@larytet where do you put this?

@win-t
Copy link

win-t commented Mar 18, 2019

Hi, I know this issue is closed.
I think this lint should be disabled on internal packages (https://golang.org/cmd/go/#hdr-Internal_Directories), internal packages are not publicly available, so forcing everyone to document it is a bit cumbersome.

@win-t
Copy link

win-t commented Mar 18, 2019

what do you think @dsymonds ?

@dzrw
Copy link

dzrw commented Mar 24, 2019

// Hello should have a comment.
func Hello() string {
  return "Hello"
}

To disable this rule selectively, this passive aggressive comment works for me while providing some small relief at the constant interruptions caused by this rule. When in the middle of writing a lot of code this rule is awful, and I wish it could be disabled until I'm done getting my thoughts out into the editor without resorting to wrapping it with another linter.

Unfortunately, this lint rule doesn't detect my snarky comments, so eventually the codebase fills up with exports with useless comments.

@RoestVrijStaal
Copy link

For all the ones who ended up here via their internet search machine like me:

gometalinter is dead, use revive

RoestVrijStaal added a commit to RoestVrijStaal/awesome-go that referenced this issue Oct 3, 2019
Because tl;dr (the devs of) golang/lint suck: golang/lint#186 (comment)

Yes, I've rewritten the description of the revive project to one sentence. Also "fast" & "beautiful" is relative to the moment they're stated. They could be invalid in the future.

Any suggestions to get this PR though are very welcome
@srics
Copy link

srics commented Nov 22, 2019

For the someone trying to whack this annoyance using revive here are the specific steps:

  1. Create a custom config.toml with [rule.exported] line commented out,
$ diff -C 1  defaults.toml .golint_revive_config.toml
...
*** 13,15 ****
  [rule.error-naming]
! [rule.exported]
  [rule.if-return]
--- 13,15 ----
  [rule.error-naming]
! # [rule.exported]
  [rule.if-return]
  1. VS Code setting as in,
{
    "go.lintTool": "revive",
    "go.lintFlags": ["--config=~/.golint_revive_config.toml"]
}

@meustrus
Copy link

I'd like to give a +1 to @PeterIttner's suggestion of using golangci-lint instead. The instructions above are not the recommended way to install it in VS Code however. See golangci-lint: Editor Integration for the supported installation method.

I personally disagree that documentation comments for all exports always improve code - they quickly lose touch with reality due to developers ignoring them and IDEs actively hiding them, so I prefer to write LongMethodNamesThatSuccinctlyDescribeTheFunction and refactor into smaller methods when I get sick of how long the method name has to be to reflect reality. The assertion that documentation comments are good is made in Effective Go, however, which makes me wonder what other assertions I will surely disagree with. But I respect golint's dedication to enforcing Effective Go, so rather than request changes here, the real solution here is to look elsewhere for a linter that I can agree with.

@ncruces
Copy link

ncruces commented Jan 29, 2020

@win-t I agree that should be the rule.

The lack of support from these tools for internal packages is staggering. godoc.org is another (I don't want dozens of internal packages listed).

Internal packages solve a real problem: avoiding code duplication without adding to the API surface.

Meanwhile I'll do a @dzrw and add a passive-agressive:

// Hello is internal. DO NOT USE.
func Hello() string {
  return "Hello"
}

@hans-fischer
Copy link

In Germany we call tools that try to dominate the developer like go-lint: Schmutz
I installed the tool into my VSCode but after some seconds I knew... I made a mistake by installing it. So how can I remove Schmutz from my VSCode?

@RoestVrijStaal
Copy link

RoestVrijStaal commented May 12, 2020

@hans-fischer
Learn to disguish the tools first.

go-lint is not a part of Visual Studio Code nor an VSCode extension. It is installed by you via a (bash/cmd/PowerShell) terminal embedded within VSCode (or an Visual Studio Code extension).

In contrast with PHP's composer, Node.js' npm and yarn, Ruby's gem and Python's pip, there isn't such a convenient thing like go uninstall or go remove for undoing a go install. Sadly.

You have to remove the go-lint package by hand.

@virgilm
Copy link

virgilm commented Jun 3, 2020

I find the go community as the most self-righteous one ever. Basic functionality that is simply missing and dismissed as 'not needed', no 'community sanctioned' tools, an so on.

For what it's worth, golint is suggested as a default tool by VSCode and the noise it generates makes a useful tool unusable, and people will just disable it to avoid the noise.

@ianlancetaylor
Copy link
Member

@virgilm Please stay polite. Please follow the code of conduct, which can be seen at https://golang.org/conduct. Thanks.

That said, see https://golang.org/issue/38968.

@virgilm
Copy link

virgilm commented Jun 4, 2020

Good to see that, it took a while. It's good to have a pointer to that issue here, since this is one of the first hits in google.

I did not mean to be rude, but that is exactly the issue: for new go programmers (even experienced programmers in other languages), it is hard to get up to speed fast, and the reason is not the language, but the ecosystem. The issue you pointed out addresses that, glad to see it's been accepted.

@shopee-jin
Copy link

shopee-jin commented Jul 13, 2020

golint ./... | grep -v 'should have comment.*be unexported'

@pratikpc
Copy link

pratikpc commented Oct 20, 2020

I have a question

What's the reason for not adding support to disable lint warnings the way ESLint or even Clang-Tidy would provide as a comparison?

Is it very difficult to achieve for technical reasons?

Something like the linter was not designed with support to disable linter warnings in mind, so adding support would be difficult or is it a Won't Fix thing?

@aleferri
Copy link

aleferri commented Dec 6, 2020

@pratikpc can't say for sure, but this look like a political stance from the go mantainers.

@ianlancetaylor
Copy link
Member

See golang/go#38968.

@CodeForcer
Copy link

The lack of ability to disable linting messages is a really poor design choice. There is no logical rationale that should lead the maintainers of this package to conclude our lives would be better without basic control over linting rules. You are not the almighty gods of Go, there are various reasons people may wish to respect one linting rule and not others.

This is a default linter in Visual Studio, and most developers like to use the default linters in a new language, without having to peruse from that point into eternity through code with a bunch of distracted yellow warning messages. It makes files of code less readable and makes it harder to find the things we do care about.

@ianlancetaylor
Copy link
Member

@CodeForcer See golang/go#38968.

@virgilm
Copy link

virgilm commented Dec 15, 2020

I'm seeing (and watching) https://golang.org/issue/38968 for 6 months now. Not clear what it means. Go ahead, deprecate it, archive this repo. Propose a replacement linter.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests