Skip to content

Commit

Permalink
Run revive over a invalid go source file (mgechev#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
doniacld committed Oct 16, 2021
1 parent 55e1594 commit 21b53e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lint/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (f *File) ToPosition(pos token.Pos) token.Position {
return f.Pkg.fset.Position(pos)
}

// Render renters a node.
// Render renders a node.
func (f *File) Render(x interface{}) string {
var buf bytes.Buffer
if err := printer.Fprint(&buf, f.Pkg.fset, x); err != nil {
Expand All @@ -74,7 +74,7 @@ var basicTypeKinds = map[types.BasicKind]string{
// and indicates what its default type is.
// scope may be nil.
func (f *File) IsUntypedConst(expr ast.Expr) (defType string, ok bool) {
// Re-evaluate expr outside of its context to see if it's untyped.
// Re-evaluate expr outside its context to see if it's untyped.
// (An expr evaluated within, for example, an assignment context will get the type of the LHS.)
exprStr := f.Render(expr)
tv, err := types.Eval(f.Pkg.fset, f.Pkg.TypesPkg, expr.Pos(), exprStr)
Expand Down Expand Up @@ -206,7 +206,6 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
if len(match) == 0 {
continue
}

ruleNames := []string{}
tempNames := strings.Split(match[rulesPos], ",")
for _, name := range tempNames {
Expand All @@ -215,7 +214,6 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
ruleNames = append(ruleNames, name)
}
}

mustCheckDisablingReason := mustSpecifyDisableReason && match[directivePos] == "disable"
if mustCheckDisablingReason && strings.Trim(match[reasonPos], " ") == "" {
failures <- Failure{
Expand Down
8 changes: 7 additions & 1 deletion lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ func (l *Linter) lintPackage(filenames []string, ruleSet []Rule, config Config,

file, err := NewFile(filename, content, pkg)
if err != nil {
return err
failures <- Failure{
Confidence: 1,
Failure: fmt.Sprintf("invalid file %s: %v", filename, err.Error()),
RuleName: "no-rule",
Category: "validity",
}
continue
}
pkg.files[filename] = file
}
Expand Down

0 comments on commit 21b53e0

Please sign in to comment.