-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: bazel-assisted removal of wildcard imports (#119)
* Initial wildcard fixer * Add gazelle:scala_fix_wildcard_imports directive * Initial implementation of incremental wildcard fixing * Add TestScalaConfigParseFixWildcardImports cases
- Loading branch information
Showing
13 changed files
with
771 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "wildcardimportfixer_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/stackb/scala-gazelle/cmd/wildcardimportfixer", | ||
visibility = ["//visibility:private"], | ||
deps = ["//pkg/wildcardimport"], | ||
) | ||
|
||
go_binary( | ||
name = "wildcardimportfixer", | ||
embed = [":wildcardimportfixer_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
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,77 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/stackb/scala-gazelle/pkg/wildcardimport" | ||
) | ||
|
||
const ( | ||
executableName = "wildcardimportfixer" | ||
) | ||
|
||
type config struct { | ||
ruleLabel string | ||
targetFilename string | ||
importPrefix string | ||
bazelExe string | ||
} | ||
|
||
func main() { | ||
log.SetPrefix(executableName + ": ") | ||
log.SetFlags(0) // don't print timestamps | ||
|
||
cfg, err := parseFlags(os.Args[1:]) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := run(cfg); err != nil { | ||
log.Fatalln("ERROR:", err) | ||
} | ||
|
||
} | ||
|
||
func parseFlags(args []string) (*config, error) { | ||
cfg := new(config) | ||
|
||
fs := flag.NewFlagSet(executableName, flag.ExitOnError) | ||
fs.StringVar(&cfg.ruleLabel, "rule_label", "", "the rule label to iteratively build") | ||
fs.StringVar(&cfg.targetFilename, "target_filename", "", "the scala file to fix") | ||
fs.StringVar(&cfg.importPrefix, "import_prefix", "", "the scala import prefix to set") | ||
fs.StringVar(&cfg.bazelExe, "bazel_executable", "bazel", "the path to the bazel executable") | ||
fs.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "usage: %s OPTIONS", executableName) | ||
fs.PrintDefaults() | ||
} | ||
if err := fs.Parse(args); err != nil { | ||
return nil, err | ||
} | ||
|
||
if cfg.ruleLabel == "" { | ||
log.Fatal("-rule_label is required") | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func run(cfg *config) error { | ||
|
||
var err error | ||
|
||
fixer := wildcardimport.NewFixer(&wildcardimport.FixerOptions{ | ||
BazelExecutable: cfg.bazelExe, | ||
}) | ||
|
||
symbols, err := fixer.Fix(cfg.ruleLabel, cfg.targetFilename, cfg.importPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Println("FIXED", cfg.targetFilename, symbols) | ||
|
||
return nil | ||
} |
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
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
Oops, something went wrong.