1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-22 03:38:47 +02:00

Remove useless getter

This commit is contained in:
mgechev 2018-01-21 18:48:51 -08:00
parent 9c979ed65f
commit 1dc6e7cabd
13 changed files with 20 additions and 25 deletions

View File

@ -17,7 +17,7 @@ type File struct {
Name string
Pkg *Package
content []byte
ast *ast.File
AST *ast.File
}
// NewFile creates a new file
@ -30,7 +30,7 @@ func NewFile(name string, content []byte, pkg *Package) (*File, error) {
Name: name,
content: content,
Pkg: pkg,
ast: f,
AST: f,
}, nil
}
@ -39,11 +39,6 @@ func (f *File) ToPosition(pos token.Pos) token.Position {
return f.Pkg.fset.Position(pos)
}
// GetAST returns the AST of the file
func (f *File) GetAST() *ast.File {
return f.ast
}
// Render renters a node.
func (f *File) Render(x interface{}) string {
var buf bytes.Buffer
@ -83,7 +78,7 @@ func (f *File) IsUntypedConst(expr ast.Expr) (defType string, ok bool) {
}
func (f *File) isMain() bool {
if f.GetAST().Name.Name == "main" {
if f.AST.Name.Name == "main" {
return true
}
return false
@ -211,7 +206,7 @@ func (f *File) disabledIntervals(rules []Rule) disabledIntervalsMap {
handleRules(filename, parts[2], parts[1] == "enable", line, ruleNames)
}
comments := f.GetAST().Comments
comments := f.AST.Comments
for _, c := range comments {
handleComment(f.Name, c, f.ToPosition(c.Pos()).Line)
}

View File

@ -29,7 +29,7 @@ var (
// isGenerated reports whether the source file is generated code
// according the rules from https://golang.org/s/generatedcode.
// This is inherited from the original linter.
// This is inherited from the original go linter.
func isGenerated(src []byte) bool {
sc := bufio.NewScanner(bytes.NewReader(src))
for sc.Scan() {
@ -63,9 +63,9 @@ func (l *Linter) Lint(filenames []string, ruleSet []Rule, rulesConfig RulesConfi
}
if pkgName == "" {
pkgName = file.GetAST().Name.Name
} else if file.GetAST().Name.Name != pkgName {
return nil, fmt.Errorf("%s is in package %s, not %s", filename, file.GetAST().Name.Name, pkgName)
pkgName = file.AST.Name.Name
} else if file.AST.Name.Name != pkgName {
return nil, fmt.Errorf("%s is in package %s, not %s", filename, file.AST.Name.Name, pkgName)
}
pkg.files[filename] = file

View File

@ -66,9 +66,9 @@ func (p *Package) TypeCheck() error {
var astFiles []*ast.File
for _, f := range p.files {
anyFile = f
astFiles = append(astFiles, f.GetAST())
astFiles = append(astFiles, f.AST)
}
typesPkg, err := config.Check(anyFile.GetAST().Name.Name, p.fset, astFiles, info)
typesPkg, err := config.Check(anyFile.AST.Name.Name, p.fset, astFiles, info)
// Remember the typechecking info, even if config.Check failed,
// since we will get partial information.
p.TypesPkg = typesPkg

View File

@ -30,7 +30,7 @@ func (r *ArgumentsLimitRule) Apply(file *linter.File, arguments linter.Arguments
},
}
ast.Walk(walker, file.GetAST())
ast.Walk(walker, file.AST)
return failures
}

View File

@ -13,7 +13,7 @@ type BlankImportsRule struct{}
func (r *BlankImportsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure {
var failures []linter.Failure
fileAst := file.GetAST()
fileAst := file.AST
walker := lintBlankImports{
file: file,
fileAst: fileAst,

View File

@ -11,7 +11,7 @@ package rule
// failures = append(failures, failure)
// }
// astFile := file.GetAST()
// astFile := file.AST
// w := &lintElseError{astFile, onFailure}
// ast.Walk(w, astFile)
// return failures

View File

@ -22,7 +22,7 @@ func (r *ExportedRule) Apply(file *linter.File, arguments linter.Arguments) []li
return failures
}
fileAst := file.GetAST()
fileAst := file.AST
walker := lintExported{
file: file,
fileAst: fileAst,

View File

@ -13,7 +13,7 @@ type ImportsRule struct{}
func (r *ImportsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure {
var failures []linter.Failure
fileAst := file.GetAST()
fileAst := file.AST
walker := lintImports{
file: file,
fileAst: fileAst,

View File

@ -21,7 +21,7 @@ func (r *NamesRule) Apply(file *linter.File, arguments linter.Arguments) []linte
return failures
}
fileAst := file.GetAST()
fileAst := file.AST
walker := lintNames{
file: file,
fileAst: fileAst,

View File

@ -19,7 +19,7 @@ func (r *LintElseRule) Apply(file *linter.File, arguments linter.Arguments) []li
}
w := lintElse{make(map[*ast.IfStmt]bool), onFailure}
ast.Walk(w, file.GetAST())
ast.Walk(w, file.AST)
return failures
}

View File

@ -28,7 +28,7 @@ func (r *PackageCommentsRule) Apply(file *linter.File, arguments linter.Argument
failures = append(failures, failure)
}
fileAst := file.GetAST()
fileAst := file.AST
w := &lintPackageComments{fileAst, file, onFailure}
ast.Walk(w, fileAst)
return failures

View File

@ -19,7 +19,7 @@ func (r *LintRangesRule) Apply(file *linter.File, arguments linter.Arguments) []
}
w := &lintRanges{file, onFailure}
ast.Walk(w, file.GetAST())
ast.Walk(w, file.AST)
return failures
}

View File

@ -16,7 +16,7 @@ type VarDeclarationsRule struct{}
func (r *VarDeclarationsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure {
var failures []linter.Failure
fileAst := file.GetAST()
fileAst := file.AST
walker := &lintVarDeclarations{
file: file,
fileAst: fileAst,