{"id":13413960,"url":"https://github.com/editorconfig/editorconfig-core-go","last_synced_at":"2025-05-16T00:03:50.314Z","repository":{"id":9563485,"uuid":"62604393","full_name":"editorconfig/editorconfig-core-go","owner":"editorconfig","description":"EditorConfig Core written in Go","archived":false,"fork":false,"pushed_at":"2025-05-05T10:43:27.000Z","size":313,"stargazers_count":146,"open_issues_count":8,"forks_count":34,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-05T11:46:01.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/editorconfig.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-05T03:50:41.000Z","updated_at":"2025-04-25T06:59:26.000Z","dependencies_parsed_at":"2023-09-27T13:24:36.514Z","dependency_job_id":"2b1b06fa-403e-4d13-8db2-d18f0a8c84c2","html_url":"https://github.com/editorconfig/editorconfig-core-go","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/editorconfig","download_url":"https://codeload.github.com/editorconfig/editorconfig-core-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442854,"owners_count":22071877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:53.789Z","updated_at":"2025-05-16T00:03:49.113Z","avatar_url":"https://github.com/editorconfig.png","language":"Go","readme":"![Build Status](https://github.com/editorconfig/editorconfig-core-go/workflows/.github/workflows/main.yml/badge.svg)\n[![Go Reference](https://pkg.go.dev/badge/github.com/editorconfig/editorconfig-core-go/v2.svg)](https://pkg.go.dev/github.com/editorconfig/editorconfig-core-go/v2)\n[![Go Report Card](https://goreportcard.com/badge/github.com/editorconfig/editorconfig-core-go)](https://goreportcard.com/report/github.com/editorconfig/editorconfig-core-go)\n\n# Editorconfig Core Go\n\nA [Editorconfig][editorconfig] file parser and manipulator for Go.\n\n## Missing features\n\n- escaping comments in values, probably in [go-ini/ini](https://github.com/go-ini/ini)\n- [adjacent nested braces](https://github.com/editorconfig/editorconfig-core-test/pull/44)\n\n## Installing\n\nWe recommend the use of Go 1.17+ modules for this package. Lower versions, such as 1.13, should be fine.\n\nImport by the same path. The package name you will use to access it is\n`editorconfig`.\n\n```go\nimport \"github.com/editorconfig/editorconfig-core-go/v2\"\n```\n\n## Usage\n\n### Parse from a file\n\n```go\nfp, err := os.Open(\"path/to/.editorconfig\")\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer fp.Close()\n\neditorConfig, err := editorconfig.Parse(fp)\nif err != nil {\n\tlog.Fatal(err)\n}\n```\n\n### Graceful parsing from a file\n\n```go\nfp, err := os.Open(\"path/to/.editorconfig\")\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer fp.Close()\n\neditorConfig, warning, err := editorconfig.ParseGraceful(fp)\nif err != nil {\n\tlog.Fatal(err)\n}\n\n// Log the warning(s) encountered while reading the editorconfig file\nif warning != nil {\n\tlog.Print(warning)\n}\n```\n\n### Parse from slice of bytes\n\n```go\ndata := []byte(\"...\")\neditorConfig, err := editorconfig.ParseBytes(data)\nif err != nil {\n\tlog.Fatal(err)\n}\n```\n\n### Get definition to a given filename\n\nThis method builds a definition to a given filename.\nThis definition is a merge of the properties with selectors that matched the\ngiven filename.\nThe lasts sections of the file have preference over the priors.\n\n```go\ndef := editorConfig.GetDefinitionForFilename(\"my/file.go\")\n```\n\nThis definition have the following properties:\n\n```go\ntype Definition struct {\n\tSelector string\n\n\tCharset                string\n\tIndentStyle            string\n\tIndentSize             string\n\tTabWidth               int\n\tEndOfLine              string\n\tTrimTrailingWhitespace *bool\n\tInsertFinalNewline     *bool\n\tRaw                    map[string]string\n}\n```\n\n#### Automatic search for `.editorconfig` files\n\nIf you want a definition of a file without having to manually\nparse the `.editorconfig` files, you can then use the static version\nof `GetDefinitionForFilename`:\n\n```go\ndef, err := editorconfig.GetDefinitionForFilename(\"foo/bar/baz/my-file.go\")\n```\n\nIn the example above, the package will automatically search for\n`.editorconfig` files on:\n\n- `foo/bar/baz/.editorconfig`\n- `foo/baz/.editorconfig`\n- `foo/.editorconfig`\n\nUntil it reaches a file with `root = true` or the root of the filesystem.\n\n### Generating a .editorconfig file\n\nYou can easily convert a Editorconfig struct to a compatible INI file:\n\n```go\n// serialize to slice of bytes\ndata, err := editorConfig.Serialize()\nif err != nil {\n\tlog.Fatal(err)\n}\n\n// save directly to file\nerr := editorConfig.Save(\"path/to/.editorconfig\")\nif err != nil {\n\tlog.Fatal(err)\n}\n```\n\n## Contributing\n\nTo run the tests:\n\n```bash\ngo test -v ./...\n```\n\nTo run the [integration tests](https://github.com/editorconfig/editorconfig-core-test):\n\n```bash\nmake test-core\n```\n\n[editorconfig]: https://editorconfig.org/\n","funding_links":[],"categories":["Text Processing","Go","文本处理","Template Engines","文本处理`解析和操作文本的代码库`","Specific Formats","Bot Building","\u003cspan id=\"文字处理-text-processing\"\u003e文字处理 Text Processing\u003c/span\u003e"],"sub_categories":["HTTP Clients","解析 器/Encoders/Decoders","Parsers/Encoders/Decoders","Advanced Console UIs","交流","查询语","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditorconfig%2Feditorconfig-core-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feditorconfig%2Feditorconfig-core-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditorconfig%2Feditorconfig-core-go/lists"}