diff options
23 files changed, 394 insertions, 121 deletions
@@ -29,6 +29,7 @@ require ( github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect github.com/denisenkom/go-mssqldb v0.0.0-20190924004331-208c0a498538 github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/editorconfig/editorconfig-core-go/v2 v2.1.1 github.com/emirpasic/gods v1.12.0 github.com/etcd-io/bbolt v1.3.2 // indirect github.com/ethantkoenig/rupture v0.0.0-20180203182544-0a76f03a811a @@ -107,13 +108,11 @@ require ( golang.org/x/tools v0.0.0-20190910221609-7f5965fd7709 // 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/editorconfig/editorconfig-core-go.v1 v1.3.0 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/ini.v1 v1.48.0 gopkg.in/ldap.v3 v3.0.2 gopkg.in/src-d/go-billy.v4 v4.3.2 gopkg.in/src-d/go-git.v4 v4.13.1 - gopkg.in/stretchr/testify.v1 v1.2.2 // indirect gopkg.in/testfixtures.v2 v2.5.0 mvdan.cc/xurls/v2 v2.1.0 strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 @@ -134,6 +134,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/editorconfig/editorconfig-core-go/v2 v2.1.1 h1:mhPg/0hGebcpiiQLqJD2PWWyoHRLEdZ3sXKaEvT1EQU= +github.com/editorconfig/editorconfig-core-go/v2 v2.1.1/go.mod h1:/LuhWJiQ9Gvo1DhVpa4ssm5qeg8rrztdtI7j/iCie2k= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= @@ -522,6 +524,7 @@ github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1 github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -763,13 +766,12 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -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/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= 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/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.2/go.mod h1:M3Cogqpuv0QCi3ExAY5V4uOt4qb/R3xZubo9m8lK5wg= gopkg.in/ini.v1 v1.46.0 h1:VeDZbLYGaupuvIrsYCEOe/L/2Pcs5n7hdO1ZTjporag= @@ -786,8 +788,6 @@ gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOA gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= -gopkg.in/stretchr/testify.v1 v1.2.2 h1:yhQC6Uy5CqibAIlk1wlusa/MJ3iAN49/BsR/dCCKz3M= -gopkg.in/stretchr/testify.v1 v1.2.2/go.mod h1:QI5V/q6UbPmuhtm10CaFZxED9NreB8PnFYN9JcR6TxU= gopkg.in/testfixtures.v2 v2.5.0 h1:N08B7l2GzFQenyYbzqthDnKAA+cmb17iAZhhFxr7JHw= gopkg.in/testfixtures.v2 v2.5.0/go.mod h1:vyAq+MYCgNpR29qitQdLZhdbLFf4mR/2MFJRFoQZZ2M= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/modules/context/repo.go b/modules/context/repo.go index f4af19a0e8..e891e7b85c 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -19,8 +19,8 @@ import ( "code.gitea.io/gitea/modules/setting" "gitea.com/macaron/macaron" + "github.com/editorconfig/editorconfig-core-go/v2" "github.com/unknwon/com" - "gopkg.in/editorconfig/editorconfig-core-go.v1" ) // PullRequest contains informations to make a pull request diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 2c53e05fca..9bb803c010 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -30,7 +30,7 @@ import ( "code.gitea.io/gitea/services/gitdiff" mirror_service "code.gitea.io/gitea/services/mirror" - "gopkg.in/editorconfig/editorconfig-core-go.v1" + "github.com/editorconfig/editorconfig-core-go/v2" ) // NewFuncMap returns functions for injecting to templates @@ -145,7 +145,11 @@ func NewFuncMap() []template.FuncMap { }, "TabSizeClass": func(ec *editorconfig.Editorconfig, filename string) string { if ec != nil { - def := ec.GetDefinitionForFilename(filename) + def, err := ec.GetDefinitionForFilename(filename) + if err != nil { + log.Error("tab size class: getting definition for filename: %v", err) + return "tab-size-8" + } if def.TabWidth > 0 { return fmt.Sprintf("tab-size-%d", def.TabWidth) } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index ae20e1e96b..f213737d54 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -136,7 +136,7 @@ func GetEditorconfig(ctx *context.APIContext) { } fileName := ctx.Params("filename") - def := ec.GetDefinitionForFilename(fileName) + def, _ := ec.GetDefinitionForFilename(fileName) if def == nil { ctx.NotFound(err) return diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.editorconfig b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.editorconfig index 715e21f1de..aca7129072 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.editorconfig +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.editorconfig @@ -3,11 +3,12 @@ root = true [*] -end_of_line = lf insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true +indent_style = space +indent_size = 2 -[*.go] +[{Makefile,go.mod,go.sum,*.go}] indent_style = tab indent_size = 8 diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitattributes b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitattributes new file mode 100644 index 0000000000..176a458f94 --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitignore b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitignore index f5dcd26083..f5dcd26083 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitignore +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitignore diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitmodules b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitmodules index 9e75e1ca0b..9e75e1ca0b 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitmodules +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.gitmodules diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/.travis.yml b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.travis.yml new file mode 100644 index 0000000000..9a1fdf77df --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/.travis.yml @@ -0,0 +1,30 @@ +--- +language: go +dist: xenial +sudo: true + +go: + - '1.11.x' + - '1.12.x' + +compiler: + - gcc + +install: + # first we create a directory for the CMake binaries + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" + - mkdir ${DEPS_DIR} && cd ${DEPS_DIR} + # we use wget to fetch the cmake binaries + - travis_retry wget --no-check-certificate https://cmake.org/files/v3.14/cmake-3.14.6-Linux-x86_64.tar.gz + - echo "82e08e50ba921035efa82b859c74c5fbe27d3e49a4003020e3c77618a4e912cd cmake-3.14.6-Linux-x86_64.tar.gz" > sha256sum.txt + - sha256sum -c sha256sum.txt + - tar -xvf cmake-3.14.6-Linux-x86_64.tar.gz > /dev/null + - mv cmake-3.14.6-Linux-x86_64 cmake-install + - PATH=${DEPS_DIR}/cmake-install:${DEPS_DIR}/cmake-install/bin:$PATH + - cd ${TRAVIS_BUILD_DIR} + +env: + - GO111MODULE=on + +script: + - make test diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/CHANGELOG.md b/vendor/github.com/editorconfig/editorconfig-core-go/v2/CHANGELOG.md new file mode 100644 index 0000000000..c09da69744 --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/CHANGELOG.md @@ -0,0 +1,20 @@ +# Change log + +## v2.1.1 - 2019-08-18 + +- Fix a small path bug + ([#17](https://github.com/editorconfig/editorconfig-core-go/issues/17), + [#18](https://github.com/editorconfig/editorconfig-core-go/pull/18)). + +## v2.1.0 - 2019-08-10 + +- This package is now *way* more compliant with the Editorconfig definition + thanks to a refactor work made by [@greut](https://github.com/greut) + ([#15](https://github.com/editorconfig/editorconfig-core-go/pull/15)). + +## v2.0.0 - 2019-07-14 + +- This project now uses [Go Modules](https://blog.golang.org/using-go-modules) + ([#14](https://github.com/editorconfig/editorconfig-core-go/pull/14)). +- The import path has been changed from `gopkg.in/editorconfig/editorconfig-core-go.v1` + to `github.com/editorconfig/editorconfig-core-go/v2`. diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/CMakeLists.txt b/vendor/github.com/editorconfig/editorconfig-core-go/v2/CMakeLists.txt new file mode 100644 index 0000000000..1ebcf1d173 --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/CMakeLists.txt @@ -0,0 +1,5 @@ +project(editorconfig-core-go) +cmake_minimum_required(VERSION 3.14) +enable_testing() +set(EDITORCONFIG_CMD ${CMAKE_CURRENT_LIST_DIR}/editorconfig) +add_subdirectory(core-test) diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/LICENSE b/vendor/github.com/editorconfig/editorconfig-core-go/v2/LICENSE index 4a30d56440..4a30d56440 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/LICENSE +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/LICENSE diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/Makefile b/vendor/github.com/editorconfig/editorconfig-core-go/v2/Makefile new file mode 100644 index 0000000000..eff4473ddf --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/Makefile @@ -0,0 +1,19 @@ +PROJECT_ROOT_DIR := $(CURDIR) +SRC := $(shell git ls-files *.go */*.go) + +.PHONY: bin test test-go test-core submodule + +test: test-go test-core + +submodule: + git submodule update --init + +editorconfig: $(SRC) + go build ./cmd/editorconfig + +test-go: + go test -v ./... + +test-core: editorconfig + cd core-test; cmake .. + cd core-test; ctest -E "(comments_after_section|octothorpe|unset_|_pre_0.9.0|max_|root_file_mixed_case)" --output-on-failure . diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/README.md b/vendor/github.com/editorconfig/editorconfig-core-go/v2/README.md index e060f1061f..784e37cf54 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/README.md +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/README.md @@ -1,27 +1,30 @@ -[![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) -[![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) +<!-- Currently tests against core-test are not done so hide build status badge for now --> +<!-- [![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/github.com/editorconfig/editorconfig-core-go?status.svg)](https://godoc.org/github.com/editorconfig/editorconfig-core-go) +[![Go Report Card](https://goreportcard.com/badge/github.com/editorconfig/editorconfig-core-go)](https://goreportcard.com/report/github.com/editorconfig/editorconfig-core-go) # Editorconfig Core Go A [Editorconfig][editorconfig] file parser and manipulator for Go. -> This package is already working, but still under testing. +> Currently this package does some basic work but does not fully support +> EditorConfig specs, so using it in "real world" is not recommended. -## Installing +## Missing features -We recommend the use of [gopkg.in][gopkg] for this package: +- `unset` +- escaping comments in values, probably in [go-ini/ini](https://github.com/go-ini/ini) -```bash -go get -u gopkg.in/editorconfig/editorconfig-core-go.v1 -``` +## Installing + +We recommend the use of Go 1.11+ modules for this package. Import by the same path. The package name you will use to access it is `editorconfig`. ```go import ( - "gopkg.in/editorconfig/editorconfig-core-go.v1" + "github.com/editorconfig/editorconfig-core-go/v2" ) ``` @@ -70,6 +73,7 @@ type Definition struct { EndOfLine string TrimTrailingWhitespace bool InsertFinalNewline bool + Raw map[string]string } ``` @@ -115,8 +119,7 @@ if err != nil { To run the tests: ```bash -go test -v +go test -v ./... ``` [editorconfig]: http://editorconfig.org/ -[gopkg]: https://gopkg.in diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/editorconfig.go b/vendor/github.com/editorconfig/editorconfig-core-go/v2/editorconfig.go index d9d629f143..1122612b49 100644 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/editorconfig.go +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/editorconfig.go @@ -15,6 +15,7 @@ import ( ) const ( + // ConfigNameDefault represents the name of the configuration file ConfigNameDefault = ".editorconfig" ) @@ -37,6 +38,7 @@ const ( CharsetUTF8 = "utf-8" CharsetUTF16BE = "utf-16be" CharsetUTF16LE = "utf-16le" + CharsetUTF8BOM = "utf-8 bom" ) // Definition represents a definition inside the .editorconfig file. @@ -81,28 +83,21 @@ func ParseBytes(data []byte) (*Editorconfig, error) { var ( iniSection = iniFile.Section(sectionStr) definition = &Definition{} - raw = make(map[string]string) + raw = make(map[string]string) ) err := iniSection.MapTo(&definition) if err != nil { return nil, err } - // tab_width defaults to indent_size: - // https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#tab_width - if definition.TabWidth <= 0 { - if num, err := strconv.Atoi(definition.IndentSize); err == nil { - definition.TabWidth = num - } - } - // Shallow copy all properties for k, v := range iniSection.KeysHash() { - raw[k] = v + raw[strings.ToLower(k)] = v } definition.Selector = sectionStr definition.Raw = raw + definition.normalize() editorConfig.Definitions = append(editorConfig.Definitions, definition) } return editorConfig, nil @@ -122,44 +117,18 @@ var ( regexpBraces = regexp.MustCompile("{.*}") ) -func filenameMatches(pattern, name string) bool { - // basic match - matched, _ := filepath.Match(pattern, name) - if matched { - return true - } - // foo/bar/main.go should match main.go - matched, _ = filepath.Match(pattern, filepath.Base(name)) - if matched { - return true - } - // foo should match foo/main.go - matched, _ = filepath.Match(filepath.Join(pattern, "*"), name) - if matched { - return true - } - // *.{js,go} should match main.go - if str := regexpBraces.FindString(pattern); len(str) > 0 { - // remote initial "{" and final "}" - str = strings.TrimPrefix(str, "{") - str = strings.TrimSuffix(str, "}") - - // testing for empty brackets: "{}" - if len(str) == 0 { - patt := regexpBraces.ReplaceAllString(pattern, "*") - matched, _ = filepath.Match(patt, filepath.Base(name)) - return matched - } +// normalize fixes some values to their lowercaes value +func (d *Definition) normalize() { + d.Charset = strings.ToLower(d.Charset) + d.EndOfLine = strings.ToLower(d.EndOfLine) + d.IndentStyle = strings.ToLower(d.IndentStyle) - for _, patt := range strings.Split(str, ",") { - patt = regexpBraces.ReplaceAllString(pattern, patt) - matched, _ = filepath.Match(patt, filepath.Base(name)) - if matched { - return true - } - } + // tab_width defaults to indent_size: + // https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#tab_width + num, err := strconv.Atoi(d.IndentSize) + if err == nil && d.TabWidth <= 0 { + d.TabWidth = num } - return false } func (d *Definition) merge(md *Definition) { @@ -192,26 +161,71 @@ func (d *Definition) merge(md *Definition) { } } +// InsertToIniFile ... TODO func (d *Definition) InsertToIniFile(iniFile *ini.File) { iniSec := iniFile.Section(d.Selector) for k, v := range d.Raw { - iniSec.Key(k).SetValue(v) + if k == "insert_final_newline" { + iniSec.Key(k).SetValue(strconv.FormatBool(d.InsertFinalNewline)) + } else if k == "trim_trailing_whitespace" { + iniSec.Key(k).SetValue(strconv.FormatBool(d.TrimTrailingWhitespace)) + } else if k == "charset" { + iniSec.Key(k).SetValue(d.Charset) + } else if k == "end_of_line" { + iniSec.Key(k).SetValue(d.EndOfLine) + } else if k == "indent_style" { + iniSec.Key(k).SetValue(d.IndentStyle) + } else if k == "tab_width" { + iniSec.Key(k).SetValue(strconv.Itoa(d.TabWidth)) + } else if k == "indent_size" { + iniSec.Key(k).SetValue(d.IndentSize) + } else { + iniSec.Key(k).SetValue(v) + } + } + if _, ok := d.Raw["indent_size"]; !ok { + if d.TabWidth > 0 { + iniSec.Key("indent_size").SetValue(strconv.Itoa(d.TabWidth)) + } else if d.IndentStyle == IndentStyleTab { + iniSec.Key("indent_size").SetValue(IndentStyleTab) + } + } + + if _, ok := d.Raw["tab_width"]; !ok && len(d.IndentSize) > 0 { + if _, err := strconv.Atoi(d.IndentSize); err == nil { + iniSec.Key("tab_width").SetValue(d.IndentSize) + } } } // GetDefinitionForFilename returns a definition for the given filename. // The result is a merge of the selectors that matched the file. // The last section has preference over the priors. -func (e *Editorconfig) GetDefinitionForFilename(name string) *Definition { +func (e *Editorconfig) GetDefinitionForFilename(name string) (*Definition, error) { def := &Definition{} def.Raw = make(map[string]string) for i := len(e.Definitions) - 1; i >= 0; i-- { actualDef := e.Definitions[i] - if filenameMatches(actualDef.Selector, name) { + selector := actualDef.Selector + if !strings.HasPrefix(selector, "/") { + if strings.ContainsRune(selector, '/') { + selector = "/" + selector + } else { + selector = "/**/" + selector + } + } + if !strings.HasPrefix(name, "/") { + name = "/" + name + } + ok, err := FnmatchCase(selector, name) + if err != nil { + return nil, err + } + if ok { def.merge(actualDef) } } - return def + return def, nil } func boolToString(b bool) string { @@ -279,10 +293,23 @@ func GetDefinitionForFilenameWithConfigname(filename string, configname string) if err != nil { return nil, err } - definition.merge(ec.GetDefinitionForFilename(filename)) + + relativeFilename := filename + if len(dir) < len(abs) { + relativeFilename = abs[len(dir):] + } + + def, err := ec.GetDefinitionForFilename(relativeFilename) + if err != nil { + return nil, err + } + + definition.merge(def) + if ec.Root { break } } + return definition, nil } diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/fnmatch.go b/vendor/github.com/editorconfig/editorconfig-core-go/v2/fnmatch.go new file mode 100644 index 0000000000..c33544cf78 --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/fnmatch.go @@ -0,0 +1,177 @@ +package editorconfig + +import ( + "fmt" + "regexp" + "strconv" + "strings" +) + +var ( + // findLeftBrackets matches the opening left bracket { + findLeftBrackets = regexp.MustCompile(`(^|[^\\])\{`) + // findLeftBrackets matches the closing right bracket { + findRightBrackets = regexp.MustCompile(`(^|[^\\])\}`) + // findNumericRange matches a range of number, e.g. -2..5 + findNumericRange = regexp.MustCompile(`^([+-]?\d+)\.\.([+-]?\d+)$`) +) + +// FnmatchCase tests whether the name matches the given pattern case included. +func FnmatchCase(pattern, name string) (bool, error) { + p, err := translate(pattern) + if err != nil { + return false, err + } + + r, err := regexp.Compile(fmt.Sprintf("^%s$", p)) + if err != nil { + return false, err + } + + return r.MatchString(name), nil +} + +func translate(pattern string) (string, error) { + index := 0 + pat := []rune(pattern) + length := len(pat) + + result := strings.Builder{} + + braceLevel := 0 + isEscaped := false + inBrackets := false + + matchesBraces := len(findLeftBrackets.FindAllString(pattern, -1)) == len(findRightBrackets.FindAllString(pattern, -1)) + + for index < length { + r := pat[index] + index++ + + if r == '*' { + p := index + if p < length && pat[p] == '*' { + result.WriteString(".*") + index++ + } else { + result.WriteString("[^/]*") + } + } else if r == '/' { + p := index + if p+2 < length && pat[p] == '*' && pat[p+1] == '*' && pat[p+2] == '/' { + result.WriteString("(?:/|/.*/)") + index += 3 + } else { + result.WriteRune(r) + } + } else if r == '?' { + result.WriteString("[^/]") + } else if r == '[' { + if inBrackets { + result.WriteString("\\[") + } else { + hasSlash := false + res := strings.Builder{} + + p := index + for p < length { + if pat[p] == ']' && pat[p-1] != '\\' { + break + } + res.WriteRune(pat[p]) + if pat[p] == '/' && pat[p-1] != '\\' { + hasSlash = true + break + } + p++ + } + if hasSlash { + result.WriteString("\\[" + res.String()) + index = p + 1 + } else { + inBrackets = true + if index < length && pat[index] == '!' || pat[index] == '^' { + index++ + result.WriteString("[^") + } else { + result.WriteRune('[') + } + } + } + } else if r == ']' { + if inBrackets && pat[index-2] == '\\' { + result.WriteString("\\]") + } else { + result.WriteRune(r) + inBrackets = false + } + } else if r == '{' { + hasComma := false + p := index + res := strings.Builder{} + + for p < length { + if pat[p] == '}' && pat[p-1] != '\\' { + break + } + res.WriteRune(pat[p]) + if pat[p] == ',' && pat[p-1] != '\\' { + hasComma = true + break + } + p++ + } + + if !hasComma && p < length { + inner := res.String() + sub := findNumericRange.FindStringSubmatch(inner) + if len(sub) == 3 { + from, _ := strconv.Atoi(sub[1]) + to, _ := strconv.Atoi(sub[2]) + result.WriteString("(?:") + // XXX does not scale well + for i := from; i < to; i++ { + result.WriteString(strconv.Itoa(i)) + result.WriteRune('|') + } + result.WriteString(strconv.Itoa(to)) + result.WriteRune(')') + } else { + r, _ := translate(inner) + result.WriteString(fmt.Sprintf("\\{%s\\}", r)) + } + index = p + 1 + } else if matchesBraces { + result.WriteString("(?:") + braceLevel++ + } else { + result.WriteString("\\{") + } + } else if r == '}' { + if braceLevel > 0 { + if isEscaped { + result.WriteRune('}') + isEscaped = false + } else { + result.WriteRune(')') + braceLevel-- + } + } else { + result.WriteString("\\}") + } + } else if r == ',' { + if braceLevel == 0 || isEscaped { + result.WriteRune(r) + } else { + result.WriteRune('|') + } + } else if r != '\\' || isEscaped { + result.WriteString(regexp.QuoteMeta(string(r))) + isEscaped = false + } else { + isEscaped = true + } + } + + return result.String(), nil +} diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.mod b/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.mod new file mode 100644 index 0000000000..e4364b8b45 --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.mod @@ -0,0 +1,9 @@ +module github.com/editorconfig/editorconfig-core-go/v2 + +go 1.12 + +require ( + github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect + github.com/stretchr/testify v1.3.0 + gopkg.in/ini.v1 v1.42.0 +) diff --git a/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.sum b/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.sum new file mode 100644 index 0000000000..061cdf586b --- /dev/null +++ b/vendor/github.com/editorconfig/editorconfig-core-go/v2/go.sum @@ -0,0 +1,22 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitattributes b/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitattributes deleted file mode 100644 index d7f0d87596..0000000000 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.gitattributes +++ /dev/null @@ -1,5 +0,0 @@ -* text eol=lf -*.jpg binary -*.jpeg binary -*.png binary -*.ico binary diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.travis.yml b/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.travis.yml deleted file mode 100644 index a3183d6a78..0000000000 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -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 diff --git a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/Makefile b/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/Makefile deleted file mode 100644 index 5151ed818d..0000000000 --- a/vendor/gopkg.in/editorconfig/editorconfig-core-go.v1/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -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 . diff --git a/vendor/modules.txt b/vendor/modules.txt index cda2acf0ee..91f7fce0d9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -119,6 +119,8 @@ github.com/denisenkom/go-mssqldb/internal/decimal github.com/denisenkom/go-mssqldb/internal/querytext # github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go +# github.com/editorconfig/editorconfig-core-go/v2 v2.1.1 +github.com/editorconfig/editorconfig-core-go/v2 # github.com/edsrzf/mmap-go v1.0.0 github.com/edsrzf/mmap-go # github.com/emirpasic/gods v1.12.0 @@ -537,8 +539,6 @@ google.golang.org/appengine/urlfetch gopkg.in/alexcesaro/quotedprintable.v3 # gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 gopkg.in/asn1-ber.v1 -# gopkg.in/editorconfig/editorconfig-core-go.v1 v1.3.0 -gopkg.in/editorconfig/editorconfig-core-go.v1 # gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/gomail.v2 # gopkg.in/ini.v1 v1.48.0 |