- Notifications
You must be signed in to change notification settings - Fork35
EditorConfig Core written in Go
License
editorconfig/editorconfig-core-go
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
AEditorconfig file parser and manipulator for Go.
- escaping comments in values, probably ingo-ini/ini
- adjacent nested braces
We recommend the use of Go 1.17+ modules for this package. Lower versions, such as 1.13, should be fine.
Import by the same path. The package name you will use to access it iseditorconfig
.
import"github.com/editorconfig/editorconfig-core-go/v2"
fp,err:=os.Open("path/to/.editorconfig")iferr!=nil {log.Fatal(err)}deferfp.Close()editorConfig,err:=editorconfig.Parse(fp)iferr!=nil {log.Fatal(err)}
fp,err:=os.Open("path/to/.editorconfig")iferr!=nil {log.Fatal(err)}deferfp.Close()editorConfig,warning,err:=editorconfig.ParseGraceful(fp)iferr!=nil {log.Fatal(err)}// Log the warning(s) encountered while reading the editorconfig fileifwarning!=nil {log.Print(warning)}
data:= []byte("...")editorConfig,err:=editorconfig.ParseBytes(data)iferr!=nil {log.Fatal(err)}
This method builds a definition to a given filename.This definition is a merge of the properties with selectors that matched thegiven filename.The lasts sections of the file have preference over the priors.
def:=editorConfig.GetDefinitionForFilename("my/file.go")
This definition have the following properties:
typeDefinitionstruct {SelectorstringCharsetstringIndentStylestringIndentSizestringTabWidthintEndOfLinestringTrimTrailingWhitespace*boolInsertFinalNewline*boolRawmap[string]string}
If you want a definition of a file without having to manuallyparse the.editorconfig
files, you can then use the static versionofGetDefinitionForFilename
:
def,err:=editorconfig.GetDefinitionForFilename("foo/bar/baz/my-file.go")
In the example above, the package will automatically search for.editorconfig
files on:
foo/bar/baz/.editorconfig
foo/baz/.editorconfig
foo/.editorconfig
Until it reaches a file withroot = true
or the root of the filesystem.
You can easily convert a Editorconfig struct to a compatible INI file:
// serialize to slice of bytesdata,err:=editorConfig.Serialize()iferr!=nil {log.Fatal(err)}// save directly to fileerr:=editorConfig.Save("path/to/.editorconfig")iferr!=nil {log.Fatal(err)}
To run the tests:
gotest -v ./...
To run theintegration tests:
make test-core
About
EditorConfig Core written in Go
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.