MCPcopy Create free account
hub / github.com/decomp/decomp / processFile

Function processFile

cmd/go-post/main.go:122–214  ·  view source on GitHub ↗
(filename string, useStdin bool)

Source from the content-addressed store, hash-verified

120}
121
122func processFile(filename string, useStdin bool) error {
123 var f *os.File
124 var err error
125 var fixlog bytes.Buffer
126
127 if useStdin {
128 f = os.Stdin
129 } else {
130 f, err = os.Open(filename)
131 if err != nil {
132 return err
133 }
134 defer f.Close()
135 }
136
137 src, err := ioutil.ReadAll(f)
138 if err != nil {
139 return err
140 }
141
142 file, err := parser.ParseFile(fset, filename, src, parserMode)
143 if err != nil {
144 return err
145 }
146
147 // Apply all fixes to file.
148 newFile := file
149 fixed := false
150 for _, fix := range fixes {
151 if allowed != nil && !allowed[fix.name] {
152 continue
153 }
154 for fix.f(newFile) {
155 fixed = true
156 fmt.Fprintf(&fixlog, " %s", fix.name)
157
158 // AST changed.
159 // Print and parse, to update any missing scoping
160 // or position information for subsequent fixers.
161 newSrc, err := gofmtFile(newFile)
162 if err != nil {
163 return err
164 }
165 newFile, err = parser.ParseFile(fset, filename, newSrc, parserMode)
166 if err != nil {
167 if debug {
168 fmt.Printf("%s", newSrc)
169 report(err)
170 os.Exit(exitCode)
171 }
172 return err
173 }
174
175 // All go fix rules are idempotent and only need to run once, except
176 // for the "unresolved" go fix rule.
177 if fix.name != "unresolved" {
178 break
179 }

Callers 2

mainFunction · 0.85
visitFileFunction · 0.85

Calls 4

gofmtFileFunction · 0.85
reportFunction · 0.85
diffFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected