Address code review feedback

Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
Alexander Bezzubov 2019-04-08 16:07:10 +02:00
parent 416afb45fc
commit bdb5603f28
No known key found for this signature in database
GPG Key ID: 8039F5787EFCD05D
3 changed files with 14 additions and 18 deletions

View File

@ -29,7 +29,7 @@ func main() {
breakdownFlag := flag.Bool("breakdown", false, "")
jsonFlag := flag.Bool("json", false, "")
showVersion := flag.Bool("version", false, "Show the enry version information")
allLangs := flag.Bool("all", false, "Show not only the files with programming languages (default) but all languages instead")
allLangs := flag.Bool("all", false, "Show all files, including those identifed as non-programming languages")
countMode := flag.String("mode", "byte", "the method used to count file size. Available options are: file, line and byte")
limitKB := flag.Int64("limit", 16*1024, "Analyse first N KB of the file (-1 means no limit)")
flag.Parse()
@ -85,7 +85,7 @@ func main() {
if enry.IsVendor(relativePath) || enry.IsDotFile(relativePath) ||
enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) {
//TODO(bzz): skip enry.IsGeneratedPath() after https://github.com/src-d/enry/issues/213
// TODO(bzz): skip enry.IsGeneratedPath() after https://github.com/src-d/enry/issues/213
if f.IsDir() {
return filepath.SkipDir
}
@ -97,16 +97,16 @@ func main() {
return nil
}
//TODO(bzz): provide API that mimics lingust CLI output for
// running ByExtension & ByFilename
// reading the file, if that did not work
// GetLanguage([]Strategy)
// TODO(bzz): provide API that mimics lingust CLI output for
// - running ByExtension & ByFilename
// - reading the file, if that did not work
// - GetLanguage([]Strategy)
content, err := readFile(path, limit)
if err != nil {
log.Println(err)
return nil
}
//TODO(bzz): skip enry.IsGeneratedContent() after https://github.com/src-d/enry/issues/213
// TODO(bzz): skip enry.IsGeneratedContent() as well, after https://github.com/src-d/enry/issues/213
language := enry.GetLanguage(filepath.Base(path), content)
if language == enry.OtherLanguage {
@ -184,7 +184,7 @@ func (e filelistError) Error() string {
func printPercents(root string, fSummary map[string][]string, buff *bytes.Buffer, mode string) {
// Select the way we quantify 'amount' of code.
var reducer func(string, []string) (float64, filelistError)
reducer := fileCountValues
switch mode {
case "file":
reducer = fileCountValues
@ -192,8 +192,6 @@ func printPercents(root string, fSummary map[string][]string, buff *bytes.Buffer
reducer = lineCountValues
case "byte":
reducer = byteCountValues
default:
reducer = fileCountValues
}
// Reduce the list of files to a quantity of file type.
@ -204,7 +202,6 @@ func printPercents(root string, fSummary map[string][]string, buff *bytes.Buffer
fileValues = make(map[string]float64)
)
for fType, files := range fSummary {
//FIXME(bzz): all files here have relative paths
val, err := reducer(root, files)
if err != nil {
unreadableFiles = append(unreadableFiles, err...)

View File

@ -391,7 +391,7 @@ func getDotIndexes(filename string) []int {
}
// GetLanguagesByContent returns a slice of languages for the given content.
// It is a Strategy that uses a content-based regexp heuristics and a filename extension.
// It is a Strategy that uses content-based regexp heuristics and a filename extension.
func GetLanguagesByContent(filename string, content []byte, _ []string) []string {
if filename == "" {
return nil

View File

@ -53,12 +53,11 @@ func getFrequencies(samplesDir string) (*samplesFrequencies, error) {
for _, langDir := range langDirs {
if !langDir.IsDir() {
log.Println(err)
continue
}
lang := langDir.Name()
samples, err := getSamplesFrom(filepath.Join(samplesDir, lang))
samples, err := readSamples(filepath.Join(samplesDir, lang))
if err != nil {
log.Println(err)
}
@ -92,14 +91,14 @@ func getFrequencies(samplesDir string) (*samplesFrequencies, error) {
}, nil
}
func getSamplesFrom(samplesLangDir string) ([]string, error) {
func readSamples(samplesLangDir string) ([]string, error) {
const samplesLangFilesDir = "filenames"
var samples []string
sampleFiles, err := ioutil.ReadDir(samplesLangDir)
if err != nil {
return nil, err
}
var samples []string
for _, sampleFile := range sampleFiles {
filename := filepath.Join(samplesLangDir, sampleFile.Name())
if sampleFile.Mode().IsRegular() {
@ -108,7 +107,7 @@ func getSamplesFrom(samplesLangDir string) ([]string, error) {
}
if sampleFile.IsDir() && sampleFile.Name() == samplesLangFilesDir {
subSamples, err := getSubSamplesFrom(filename)
subSamples, err := readSubSamples(filename)
if err != nil {
return nil, err
}
@ -121,7 +120,7 @@ func getSamplesFrom(samplesLangDir string) ([]string, error) {
return samples, nil
}
func getSubSamplesFrom(path string) ([]string, error) {
func readSubSamples(path string) ([]string, error) {
subSamples := []string{}
entries, err := ioutil.ReadDir(path)
if err != nil {