Skip to content

Commit

Permalink
Rename to include-internal
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Oct 8, 2021
1 parent da1772b commit fbcbb70
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ If you want to ignore files (e.g. proto generated files), pass the `--skip-files
porto --skip-files ".*\\.pb\\.go$" path/to/library
```

If you want to check `internal` folders too
If you want to include `internal` folders too

```bash
porto --check-internal path/to/library
porto --include-internal path/to/library
```
6 changes: 3 additions & 3 deletions cmd/porto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
flagWriteOutputToFile := flag.Bool("w", false, "write result to (source) file instead of stdout")
flagListDiff := flag.Bool("l", false, "list files whose vanity import differs from porto's")
flagSkipFiles := flag.String("skip-files", "", "Regexps of files to skip")
flagCheckInternal := flag.Bool("check-internal", false, "check internal folders")
flagIncludeInternal := flag.Bool("include-internal", false, "include internal folders")
flag.Parse()

baseDir := flag.Arg(0)
Expand All @@ -28,7 +28,7 @@ Options:
-w Write result to (source) file instead of stdout (default: false)
-l List files whose vanity import differs from porto's (default: false)
--skip-files Regexps of files to skip
--check-internal Check internal folders
--include-internal Check internal folders
Examples:
Expand Down Expand Up @@ -63,7 +63,7 @@ Add import path to a folder
WriteResultToFile: *flagWriteOutputToFile,
ListDiffFiles: *flagListDiff,
SkipFilesRegexes: skipFilesRegex,
CheckInternal: *flagCheckInternal,
IncludeInternal: *flagIncludeInternal,
})
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func isGoTestFile(filename string) bool {
}

// isUnexportedDir checks if a dirname is a known unexported directory.
// If checkInternal is false, we also ignore "internal".
func isUnexportedDir(dirname string, checkInternal bool) bool {
return dirname == "testdata" || (!checkInternal && dirname == "internal")
// If includeInternal is false, we also ignore "internal".
func isUnexportedDir(dirname string, includeInternal bool) bool {
return dirname == "testdata" || (!includeInternal && dirname == "internal")
}

// writeContentToFile writes the content in bytes to a given file.
Expand Down
16 changes: 8 additions & 8 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func addImportPath(absFilepath string, module string) (bool, []byte, error) {
return !bytes.Equal(content, newContent), newContent, nil
}

func isUnexportedModule(moduleName string, checkInternal bool) bool {
return !checkInternal && (strings.Contains(moduleName, "/internal/") ||
func isUnexportedModule(moduleName string, includeInternal bool) bool {
return !includeInternal && (strings.Contains(moduleName, "/internal/") ||
strings.HasSuffix(moduleName, "/internal"))
}

func findAndAddVanityImportForModuleDir(workingDir, absDir string, moduleName string, opts Options) (int, error) {
if isUnexportedModule(moduleName, opts.CheckInternal) {
if isUnexportedModule(moduleName, opts.IncludeInternal) {
return 0, nil
}

Expand All @@ -83,7 +83,7 @@ func findAndAddVanityImportForModuleDir(workingDir, absDir string, moduleName st
c int
err error
)
if isUnexportedDir(dirName, opts.CheckInternal) {
if isUnexportedDir(dirName, opts.IncludeInternal) {
continue
} else if newModuleName, ok := findGoModule(absDir + pathSeparator + dirName); ok {
// if folder contains go.mod we use it from now on to build the vanity import
Expand Down Expand Up @@ -165,7 +165,7 @@ func findAndAddVanityImportForNonModuleDir(workingDir, absDir string, opts Optio
}

dirName := f.Name()
if isUnexportedDir(dirName, opts.CheckInternal) {
if isUnexportedDir(dirName, opts.IncludeInternal) {
continue
}

Expand Down Expand Up @@ -199,8 +199,8 @@ type Options struct {
ListDiffFiles bool
// Set of regex for matching files to be skipped
SkipFilesRegexes []*regexp.Regexp
// Check internal packages
CheckInternal bool
// Include internal packages
IncludeInternal bool
}

// FindAndAddVanityImportForDir scans all files in a folder and based on go.mod files
Expand All @@ -224,7 +224,7 @@ func FindAndAddVanityImportForDir(workingDir, absDir string, opts Options) (int,
}

dirName := f.Name()
if isUnexportedDir(dirName, opts.CheckInternal) {
if isUnexportedDir(dirName, opts.IncludeInternal) {
continue
}

Expand Down

0 comments on commit fbcbb70

Please sign in to comment.