Skip to content

Commit 04983a6

Browse files
authored
exported: ignore exported symbols from the main package (#1398)
1 parent 426a27a commit 04983a6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

‎rule/exported.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ func (r *ExportedRule) Configure(arguments lint.Arguments) error {
110110

111111
// Apply applies the rule to given file.
112112
func (r *ExportedRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
113-
var failures []lint.Failure
114-
if file.IsTest() {
115-
return failures
113+
if !file.IsImportable() {
114+
return nil
116115
}
117116

117+
var failures []lint.Failure
118118
walker := lintExported{
119119
file: file,
120120
onFailure: func(failure lint.Failure) {

‎test/exported_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ func TestCheckDirectiveComment(t *testing.T) {
4747
func TestCheckDeprecationComment(t *testing.T) {
4848
testRule(t, "exported_issue_1231", &rule.ExportedRule{}, &lint.RuleConfig{})
4949
}
50+
51+
func TestExportedMainPackage(t *testing.T) {
52+
testRule(t, "exported_main", &rule.ExportedRule{}, &lint.RuleConfig{})
53+
}

‎testdata/exported_main.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Symbols declared in main package cannot be imported.
2+
package main
3+
4+
type Foo struct{}

0 commit comments

Comments
 (0)