-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integrate ImportAs linter * review: don't panic :) Co-authored-by: Fernandez Ludovic <[email protected]>
- Loading branch information
Showing
8 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package golinters | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/julz/importas" // nolint: misspell | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
"github.com/golangci/golangci-lint/pkg/lint/linter" | ||
) | ||
|
||
func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter { | ||
analyzer := importas.Analyzer | ||
|
||
return goanalysis.NewLinter( | ||
analyzer.Name, | ||
analyzer.Doc, | ||
[]*analysis.Analyzer{analyzer}, | ||
nil, | ||
).WithContextSetter(func(lintCtx *linter.Context) { | ||
if settings == nil { | ||
return | ||
} | ||
|
||
for alias, pkg := range *settings { | ||
err := analyzer.Flags.Set("alias", fmt.Sprintf("%s:%s", pkg, alias)) | ||
if err != nil { | ||
lintCtx.Log.Errorf("failed to parse configuration: %v", err) | ||
} | ||
} | ||
}).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
linters-settings: | ||
importas: | ||
fff: fmt | ||
std_os: os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//args: -Eimportas | ||
//config_path: testdata/configs/importas.yml | ||
package testdata | ||
|
||
import ( | ||
wrong_alias "fmt" // ERROR `import "fmt" imported as "wrong_alias" but must be "fff" according to config` | ||
wrong_alias_again "os" // ERROR `import "os" imported as "wrong_alias_again" but must be "std_os" according to config` | ||
) | ||
|
||
func ImportAsWrongAlias() { | ||
wrong_alias.Println("foo") | ||
wrong_alias_again.Stdout.WriteString("bar") | ||
} |