| 1 |
package editorconfig |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
"gopkg.in/ini.v1" |
| 8 |
) |
| 9 |
|
| 10 |
// SimpleParser implements the Parser interface but without doing any caching. |
| 11 |
type SimpleParser struct{} |
| 12 |
|
| 13 |
// ParseIni calls go-ini's Load on the file. |
| 14 |
func (parser *SimpleParser) ParseIni(filename string) (*Editorconfig, error) { |
| 15 |
ec, warning, err := parser.ParseIniGraceful(filename) |
| 16 |
if err != nil { |
| 17 |
return nil, err |
| 18 |
} |
| 19 |
|
| 20 |
return ec, warning |
| 21 |
} |
| 22 |
|
| 23 |
// ParseIniGraceful calls go-ini's Load on the file and keep warnings in a separate error. |
| 24 |
func (parser *SimpleParser) ParseIniGraceful(filename string) (*Editorconfig, error, error) { |
| 25 |
empty := &Editorconfig{} |
| 26 |
|
| 27 |
fp, err := os.Open(filename) |
| 28 |
if err != nil { |
| 29 |
return empty, nil, err //nolint:wrapcheck |
| 30 |
} |
| 31 |
|
| 32 |
defer fp.Close() |
| 33 |
|
| 34 |
iniFile, err := ini.Load(fp) |
| 35 |
if err != nil { |
| 36 |
return empty, nil, fmt.Errorf("cannot load %q: %w", filename, err) |
| 37 |
} |
| 38 |
|
| 39 |
return newEditorconfig(iniFile) |
| 40 |
} |
| 41 |
|
| 42 |
// FnmatchCase calls the module's FnmatchCase. |
| 43 |
func (parser *SimpleParser) FnmatchCase(selector string, filename string) (bool, error) { |
| 44 |
return FnmatchCase(selector, filename) |
| 45 |
} |