Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

EditorConfig Core written in Go

License

NotificationsYou must be signed in to change notification settings

editorconfig/editorconfig-core-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusGo ReferenceGo Report Card

Editorconfig Core Go

AEditorconfig file parser and manipulator for Go.

Missing features

Installing

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"

Usage

Parse from a file

fp,err:=os.Open("path/to/.editorconfig")iferr!=nil {log.Fatal(err)}deferfp.Close()editorConfig,err:=editorconfig.Parse(fp)iferr!=nil {log.Fatal(err)}

Graceful parsing from a file

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)}

Parse from slice of bytes

data:= []byte("...")editorConfig,err:=editorconfig.ParseBytes(data)iferr!=nil {log.Fatal(err)}

Get definition to a given filename

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}

Automatic search for.editorconfig files

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.

Generating a .editorconfig file

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)}

Contributing

To run the tests:

gotest -v ./...

To run theintegration tests:

make test-core

About

EditorConfig Core written in Go

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors10

Languages


[8]ページ先頭

©2009-2025 Movatter.jp