1
0
mirror of https://github.com/mgechev/revive.git synced 2025-10-30 23:37:49 +02:00

exported: ignore exported symbols from the main package (#1398)

This commit is contained in:
Oleksandr Redko
2025-06-16 15:23:47 +03:00
committed by GitHub
parent 426a27ac0d
commit 04983a692f
3 changed files with 11 additions and 3 deletions

View File

@@ -110,11 +110,11 @@ func (r *ExportedRule) Configure(arguments lint.Arguments) error {
// Apply applies the rule to given file.
func (r *ExportedRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
if file.IsTest() {
return failures
if !file.IsImportable() {
return nil
}
var failures []lint.Failure
walker := lintExported{
file: file,
onFailure: func(failure lint.Failure) {

View File

@@ -47,3 +47,7 @@ func TestCheckDirectiveComment(t *testing.T) {
func TestCheckDeprecationComment(t *testing.T) {
testRule(t, "exported_issue_1231", &rule.ExportedRule{}, &lint.RuleConfig{})
}
func TestExportedMainPackage(t *testing.T) {
testRule(t, "exported_main", &rule.ExportedRule{}, &lint.RuleConfig{})
}

4
testdata/exported_main.go vendored Normal file
View File

@@ -0,0 +1,4 @@
// Symbols declared in main package cannot be imported.
package main
type Foo struct{}