func lintFile(filename string) { src, err := ioutil.ReadFile(filename) if err != nil { fmt.Fprintln(os.Stderr, err) return } l := new(lint.Linter) ps, err := l.Lint(filename, src) if err != nil { fmt.Fprintf(os.Stderr, "%v:%v\n", filename, err) return } for _, p := range ps { if p.Confidence >= *minConfidence { if *excludeInitialisms && strings.HasSuffix(p.Link, "#Initialisms") { continue } fmt.Printf("%s:%v: %s\n", filename, p.Position, p.Text) } } }
func isLinted() bool { errors := 0 l := new(lint.Linter) filepath.Walk(sourcePath+"/...", func(path string, f os.FileInfo, err error) error { if !strings.HasSuffix(filepath.Ext(path), ".go") { return nil } file, err := ioutil.ReadFile(path) if err != nil { return nil } if lnt, _ := l.Lint(f.Name(), file); len(lnt) > 0 { if lnt[0].Confidence > 0.2 { errors++ return nil } } return nil }) return errors == 0 }
func main() { filename := os.Args[1] src, err := ioutil.ReadFile(filename) if err != nil { fmt.Fprintln(os.Stderr, err) return } l := new(lint.Linter) ps, err := l.Lint("-", src) if err != nil { return } for _, p := range ps { fmt.Printf("%s:%v: %s\n", filename, p.Position, p.Text) } }
func runLint(r *http.Request, importPath string) (*lintPackage, error) { dir, err := gosrc.Get(httpClient(r), importPath, "") if err != nil { return nil, err } pkg := lintPackage{ Path: importPath, Updated: time.Now(), LineFmt: dir.LineFmt, URL: dir.BrowseURL, } linter := lint.Linter{} for _, f := range dir.Files { if !strings.HasSuffix(f.Name, ".go") { continue } problems, err := linter.Lint(f.Name, f.Data) if err == nil && len(problems) == 0 { continue } file := lintFile{Name: f.Name, URL: f.BrowseURL} if err != nil { file.Problems = []*lintProblem{{Text: err.Error()}} } else { for _, p := range problems { file.Problems = append(file.Problems, &lintProblem{ Line: p.Position.Line, Text: p.Text, LineText: p.LineText, Confidence: p.Confidence, Link: p.Link, }) } } if len(file.Problems) > 0 { pkg.Files = append(pkg.Files, &file) } } if err := putPackage(appengine.NewContext(r), importPath, &pkg); err != nil { return nil, err } return &pkg, nil }
func lintFile(filename string) { src, err := ioutil.ReadFile(filename) if err != nil { fmt.Fprintln(os.Stderr, err) return } l := new(lint.Linter) ps, err := l.Lint(filename, src) if err != nil { fmt.Fprintf(os.Stderr, "%v:%v\n", filename, err) return } for _, p := range ps { if p.Confidence >= *minConfidence { fmt.Printf("%s:%v: %s\n", filename, p.Position, p.Text) } } }
func lintFile(filename string) { src, err := ioutil.ReadFile(filename) if err != nil { log.Printf("Failed reading %v: %v", filename, err) return } l := new(lint.Linter) ps, err := l.Lint(filename, src) if err != nil { log.Printf("Failed parsing %v: %v", filename, err) return } for _, p := range ps { if p.Confidence >= *minConfidence { fmt.Printf("%s:%v: %s\n", filename, p.Position, p.Text) } } }