* deps: Upgrade gopkg.in/editorconfig/editorconfig-core-go.v1 from 1.2.0 to 1.3.0 * deps: vendor updatestags/v1.10.0-rc1
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect | gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect | ||||
gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 // indirect | gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 // indirect | ||||
gopkg.in/bufio.v1 v1.0.0-20140618132640-567b2bfa514e // indirect | gopkg.in/bufio.v1 v1.0.0-20140618132640-567b2bfa514e // indirect | ||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.2.0 | |||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.3.0 | |||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df | ||||
gopkg.in/ini.v1 v1.42.0 | gopkg.in/ini.v1 v1.42.0 | ||||
gopkg.in/ldap.v3 v3.0.2 | gopkg.in/ldap.v3 v3.0.2 |
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.2.0 h1:CO465/foR4+bY1xNYjZEl6l8By1g/iMsImoruxfEt84= | |||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.2.0/go.mod h1:s2mQFI9McjArkyCwyEwU//+luQENTnD/Lfb/7Sj3/kQ= | |||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.3.0 h1:oxOEwvhxLMpWpN+0pb2r9TWrM0DCFBHxbuIlS27tmFg= | |||||
gopkg.in/editorconfig/editorconfig-core-go.v1 v1.3.0/go.mod h1:s2mQFI9McjArkyCwyEwU//+luQENTnD/Lfb/7Sj3/kQ= | |||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= | gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= | ||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | ||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE= | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE= |
[*.go] | [*.go] | ||||
indent_style = tab | indent_style = tab | ||||
indent_size = 4 | |||||
indent_size = 8 |
*.test | *.test | ||||
*.prof | *.prof | ||||
# EditorConfig | |||||
/editorconfig |
[submodule "core-test"] | |||||
path = core-test | |||||
url = https://github.com/editorconfig/editorconfig-core-test.git |
--- | |||||
language: go | |||||
sudo: false | |||||
go: | |||||
- '1.8' | |||||
- '1.9' | |||||
- '1.10' | |||||
go_import_path: gopkg.in/editorconfig/editorconfig-core-go.v1 | |||||
install: | |||||
- make installdeps | |||||
script: | |||||
- make test |
PROJECT_ROOT_DIR := $(CURDIR) | |||||
SRC := editorconfig.go cmd/editorconfig/main.go | |||||
.PHONY: bin test test-go test-core submodule installdeps | |||||
test: test-go test-core | |||||
submodule: | |||||
git submodule update --init | |||||
installdeps: | |||||
go get -t ./... | |||||
editorconfig: $(SRC) | |||||
go build ./cmd/editorconfig | |||||
test-go: | |||||
go test -v | |||||
test-core: editorconfig | |||||
cd $(PROJECT_ROOT_DIR)/core-test && \ | |||||
cmake -DEDITORCONFIG_CMD="$(PROJECT_ROOT_DIR)/editorconfig" . | |||||
# Temporarily disable core-test | |||||
# cd $(PROJECT_ROOT_DIR)/core-test && \ | |||||
# ctest --output-on-failure . |
[![Build Status](https://travis-ci.org/editorconfig/editorconfig-core-go.svg?branch=master)](https://travis-ci.org/editorconfig/editorconfig-core-go) | |||||
[![GoDoc](https://godoc.org/gopkg.in/editorconfig/editorconfig-core-go.v1?status.svg)](https://godoc.org/gopkg.in/editorconfig/editorconfig-core-go.v1) | [![GoDoc](https://godoc.org/gopkg.in/editorconfig/editorconfig-core-go.v1?status.svg)](https://godoc.org/gopkg.in/editorconfig/editorconfig-core-go.v1) | ||||
[![Go Report Card](https://goreportcard.com/badge/gopkg.in/editorconfig/editorconfig-core-go.v1)](https://goreportcard.com/report/gopkg.in/editorconfig/editorconfig-core-go.v1) | [![Go Report Card](https://goreportcard.com/badge/gopkg.in/editorconfig/editorconfig-core-go.v1)](https://goreportcard.com/report/gopkg.in/editorconfig/editorconfig-core-go.v1) | ||||
go get -u gopkg.in/editorconfig/editorconfig-core-go.v1 | go get -u gopkg.in/editorconfig/editorconfig-core-go.v1 | ||||
``` | ``` | ||||
Import by the same path. Tha package name you will use to access it is | |||||
Import by the same path. The package name you will use to access it is | |||||
`editorconfig`. | `editorconfig`. | ||||
```go | ```go |
"gopkg.in/ini.v1" | "gopkg.in/ini.v1" | ||||
) | ) | ||||
const ( | |||||
ConfigNameDefault = ".editorconfig" | |||||
) | |||||
// IndentStyle possible values | // IndentStyle possible values | ||||
const ( | const ( | ||||
IndentStyleTab = "tab" | IndentStyleTab = "tab" | ||||
EndOfLine string `ini:"end_of_line" json:"end_of_line,omitempty"` | EndOfLine string `ini:"end_of_line" json:"end_of_line,omitempty"` | ||||
TrimTrailingWhitespace bool `ini:"trim_trailing_whitespace" json:"trim_trailing_whitespace,omitempty"` | TrimTrailingWhitespace bool `ini:"trim_trailing_whitespace" json:"trim_trailing_whitespace,omitempty"` | ||||
InsertFinalNewline bool `ini:"insert_final_newline" json:"insert_final_newline,omitempty"` | InsertFinalNewline bool `ini:"insert_final_newline" json:"insert_final_newline,omitempty"` | ||||
Raw map[string]string `ini:"-" json:"-"` | |||||
} | } | ||||
// Editorconfig represents a .editorconfig file. | // Editorconfig represents a .editorconfig file. | ||||
var ( | var ( | ||||
iniSection = iniFile.Section(sectionStr) | iniSection = iniFile.Section(sectionStr) | ||||
definition = &Definition{} | definition = &Definition{} | ||||
raw = make(map[string]string) | |||||
) | ) | ||||
err := iniSection.MapTo(&definition) | err := iniSection.MapTo(&definition) | ||||
if err != nil { | if err != nil { | ||||
} | } | ||||
} | } | ||||
// Shallow copy all properties | |||||
for k, v := range iniSection.KeysHash() { | |||||
raw[k] = v | |||||
} | |||||
definition.Selector = sectionStr | definition.Selector = sectionStr | ||||
definition.Raw = raw | |||||
editorConfig.Definitions = append(editorConfig.Definitions, definition) | editorConfig.Definitions = append(editorConfig.Definitions, definition) | ||||
} | } | ||||
return editorConfig, nil | return editorConfig, nil | ||||
if !d.InsertFinalNewline { | if !d.InsertFinalNewline { | ||||
d.InsertFinalNewline = md.InsertFinalNewline | d.InsertFinalNewline = md.InsertFinalNewline | ||||
} | } | ||||
for k, v := range md.Raw { | |||||
if _, ok := d.Raw[k]; !ok { | |||||
d.Raw[k] = v | |||||
} | |||||
} | |||||
} | |||||
func (d *Definition) InsertToIniFile(iniFile *ini.File) { | |||||
iniSec := iniFile.Section(d.Selector) | |||||
for k, v := range d.Raw { | |||||
iniSec.Key(k).SetValue(v) | |||||
} | |||||
} | } | ||||
// GetDefinitionForFilename returns a definition for the given filename. | // GetDefinitionForFilename returns a definition for the given filename. | ||||
// The last section has preference over the priors. | // The last section has preference over the priors. | ||||
func (e *Editorconfig) GetDefinitionForFilename(name string) *Definition { | func (e *Editorconfig) GetDefinitionForFilename(name string) *Definition { | ||||
def := &Definition{} | def := &Definition{} | ||||
def.Raw = make(map[string]string) | |||||
for i := len(e.Definitions) - 1; i >= 0; i-- { | for i := len(e.Definitions) - 1; i >= 0; i-- { | ||||
actualDef := e.Definitions[i] | actualDef := e.Definitions[i] | ||||
if filenameMatches(actualDef.Selector, name) { | if filenameMatches(actualDef.Selector, name) { | ||||
iniFile.Section(ini.DEFAULT_SECTION).Key("root").SetValue(boolToString(e.Root)) | iniFile.Section(ini.DEFAULT_SECTION).Key("root").SetValue(boolToString(e.Root)) | ||||
} | } | ||||
for _, d := range e.Definitions { | for _, d := range e.Definitions { | ||||
iniSec := iniFile.Section(d.Selector) | |||||
if len(d.Charset) > 0 { | |||||
iniSec.Key("charset").SetValue(d.Charset) | |||||
} | |||||
if len(d.IndentStyle) > 0 { | |||||
iniSec.Key("indent_style").SetValue(d.IndentStyle) | |||||
} | |||||
if len(d.IndentSize) > 0 { | |||||
iniSec.Key("indent_size").SetValue(d.IndentSize) | |||||
} | |||||
if d.TabWidth > 0 && strconv.Itoa(d.TabWidth) != d.IndentSize { | |||||
iniSec.Key("tab_width").SetValue(strconv.Itoa(d.TabWidth)) | |||||
} | |||||
if len(d.EndOfLine) > 0 { | |||||
iniSec.Key("end_of_line").SetValue(d.EndOfLine) | |||||
} | |||||
if d.TrimTrailingWhitespace { | |||||
iniSec.Key("trim_trailing_whitespace").SetValue(boolToString(d.TrimTrailingWhitespace)) | |||||
} | |||||
if d.InsertFinalNewline { | |||||
iniSec.Key("insert_final_newline").SetValue(boolToString(d.InsertFinalNewline)) | |||||
} | |||||
d.InsertToIniFile(iniFile) | |||||
} | } | ||||
_, err := iniFile.WriteTo(buffer) | _, err := iniFile.WriteTo(buffer) | ||||
if err != nil { | if err != nil { | ||||
// folder with `root = true`, and returns the right editorconfig | // folder with `root = true`, and returns the right editorconfig | ||||
// definition for the given file. | // definition for the given file. | ||||
func GetDefinitionForFilename(filename string) (*Definition, error) { | func GetDefinitionForFilename(filename string) (*Definition, error) { | ||||
return GetDefinitionForFilenameWithConfigname(filename, ConfigNameDefault) | |||||
} | |||||
func GetDefinitionForFilenameWithConfigname(filename string, configname string) (*Definition, error) { | |||||
abs, err := filepath.Abs(filename) | abs, err := filepath.Abs(filename) | ||||
if err != nil { | if err != nil { | ||||
return nil, err | return nil, err | ||||
} | } | ||||
definition := &Definition{} | definition := &Definition{} | ||||
definition.Raw = make(map[string]string) | |||||
dir := abs | dir := abs | ||||
for dir != filepath.Dir(dir) { | for dir != filepath.Dir(dir) { | ||||
dir = filepath.Dir(dir) | dir = filepath.Dir(dir) | ||||
ecFile := filepath.Join(dir, ".editorconfig") | |||||
ecFile := filepath.Join(dir, configname) | |||||
if _, err := os.Stat(ecFile); os.IsNotExist(err) { | if _, err := os.Stat(ecFile); os.IsNotExist(err) { | ||||
continue | continue | ||||
} | } |
gopkg.in/asn1-ber.v1 | gopkg.in/asn1-ber.v1 | ||||
# gopkg.in/bufio.v1 v1.0.0-20140618132640-567b2bfa514e | # gopkg.in/bufio.v1 v1.0.0-20140618132640-567b2bfa514e | ||||
gopkg.in/bufio.v1 | gopkg.in/bufio.v1 | ||||
# gopkg.in/editorconfig/editorconfig-core-go.v1 v1.2.0 | |||||
# gopkg.in/editorconfig/editorconfig-core-go.v1 v1.3.0 | |||||
gopkg.in/editorconfig/editorconfig-core-go.v1 | gopkg.in/editorconfig/editorconfig-core-go.v1 | ||||
# gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df | # gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df | ||||
gopkg.in/gomail.v2 | gopkg.in/gomail.v2 |