github.com/editorconfig-checker/editorconfig-checker@v0.0.0-20231102090242-ddae3e68851e/README.md (about) 1 # editorconfig-checker 2 3 <a href="https://www.buymeacoffee.com/mstruebing" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a> 4 5 [![ci](https://github.com/editorconfig-checker/editorconfig-checker/actions/workflows/ci.yml/badge.svg)](https://github.com/editorconfig-checker/editorconfig-checker/actions/workflows/ci.yml) 6 [![codecov](https://codecov.io/gh/editorconfig-checker/editorconfig-checker/branch/main/graph/badge.svg)](https://codecov.io/gh/editorconfig-checker/editorconfig-checker) 7 [![Hits-of-Code](https://hitsofcode.com/github/editorconfig-checker/editorconfig-checker)](https://hitsofcode.com/view/github/editorconfig-checker/editorconfig-checker) 8 [![Go Report Card](https://goreportcard.com/badge/github.com/editorconfig-checker/editorconfig-checker)](https://goreportcard.com/report/github.com/editorconfig-checker/editorconfig-checker) 9 10 ![Logo](docs/logo.png) 11 12 1. [What?](#what) 13 2. [Quickstart](#quickstart) 14 3. [Installation](#installation) 15 4. [Usage](#usage) 16 5. [Configuration](#configuration) 17 6. [Excluding](#excluding) 18 1. [Excluding Lines](#excluding-lines) 19 2. [Excluding Blocks](#excluding-blocks) 20 3. [Excluding Files](#excluding-files) 21 1. [Inline](#inline) 22 2. [Default Excludes](#default-excludes) 23 3. [Manually Excluding](#manually-excluding) 24 1. [via configuration](#via-configuration) 25 2. [via arguments](#via-arguments) 26 3. [Generally](#generally) 27 7. [Docker](#docker) 28 8. [Continuous Integration](#continuous-integration) 29 9. [Support](#support) 30 31 ## What? 32 33 ![Example Screenshot](docs/screenshot.png) 34 35 This is a tool to check if your files consider your `.editorconfig` rules. 36 Most tools—like linters, for example—only test one filetype and need an extra configuration. 37 This tool only needs your `.editorconfig` to check all files. 38 39 If you don't know about editorconfig already you can read about it here: [editorconfig.org](https://editorconfig.org/). 40 41 Currently implemented editorconfig features are: 42 43 - `end_of_line` 44 - `insert_final_newline` 45 - `trim_trailing_whitespace` 46 - `indent_style` 47 - `indent_size` 48 - `max_line_length` 49 50 Unsupported features are: 51 52 - `charset` 53 54 ## Quickstart 55 56 ```shell 57 VERSION="2.7.2" 58 OS="linux" 59 ARCH="amd64" 60 curl -O -L -C - https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$VERSION/ec-$OS-$ARCH.tar.gz && \ 61 tar xzf ec-$OS-$ARCH.tar.gz && \ 62 ./bin/ec-$OS-$ARCH 63 ``` 64 65 ## Installation 66 67 Grab a binary from the [release page](https://github.com/editorconfig-checker/editorconfig-checker/releases). 68 69 If you have go installed you can run `go get github.com/editorconfig-checker/editorconfig-checker` and run `make build` inside the project folder. 70 This will place a binary called `ec` into the `bin` directory. 71 72 If you are using Arch Linux, you can use [pacman](https://wiki.archlinux.org/title/Pacman) to install from [extra repository](https://archlinux.org/packages/extra/x86_64/editorconfig-checker/): 73 74 ```shell 75 pacman -S editorconfig-checker 76 ``` 77 78 Also, development (VCS) package is available in the [AUR](https://aur.archlinux.org/packages/editorconfig-checker-git): 79 80 ```shell 81 # <favourite-aur-helper> <install-command> editorconfig-checker-git 82 83 # i.e. 84 paru -S editorconfig-checker-git 85 ``` 86 87 If go 1.16 or greater is installed, you can also install it globally via `go install`: 88 89 ```shell 90 go install github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@latest 91 ``` 92 93 ## Usage 94 95 ``` 96 USAGE: 97 -config string 98 config 99 -debug 100 print debugging information 101 -disable-end-of-line 102 disables the trailing whitespace check 103 -disable-indent-size 104 disables only the indent-size check 105 -disable-indentation 106 disables the indentation check 107 -disable-insert-final-newline 108 disables the final newline check 109 -disable-trim-trailing-whitespace 110 disables the trailing whitespace check 111 -dry-run 112 show which files would be checked 113 -exclude string 114 a regex which files should be excluded from checking - needs to be a valid regular expression 115 -h print the help 116 -help 117 print the help 118 -ignore-defaults 119 ignore default excludes 120 -init 121 creates an initial configuration 122 -no-color 123 dont print colors 124 -v print debugging information 125 -verbose 126 print debugging information 127 -version 128 print the version number 129 ``` 130 131 If you run this tool from a repository root it will check all files which are added to the git repository and are text files. If the tool isn't able to determine a file type it will be added to be checked too. 132 133 If you run this tool from a normal directory it will check all files which are text files. If the tool isn't able to determine a file type it will be added to be checked too. 134 135 ## Configuration 136 137 The configuration is done via arguments or an `.ecrc` file. 138 139 A sample `.ecrc` file can look like this and will be used from your current working directory if not specified via the `--config` argument: 140 141 ```json 142 { 143 "Verbose": false, 144 "Debug": false, 145 "IgnoreDefaults": false, 146 "SpacesAftertabs": false, 147 "NoColor": false, 148 "Exclude": [], 149 "AllowedContentTypes": [], 150 "PassedFiles": [], 151 "Disable": { 152 "EndOfLine": false, 153 "Indentation": false, 154 "IndentSize": false, 155 "InsertFinalNewline": false, 156 "TrimTrailingWhitespace": false, 157 "MaxLineLength": false 158 } 159 } 160 ``` 161 162 You can set any of the options under the `"Disable"` section to `true` to disable those particular checks. 163 164 You could also specify command line arguments and they will get merged with the configuration file, the command line arguments have a higher precedence than the configuration. 165 166 You can create a configuration with the `init`-flag. If you specify an `config`-path it will be created there. 167 168 By default the allowed_content_types are: 169 170 1. `text/` (matches `text/plain`, `text/html`, etc.) 171 1. `application/ecmascript` 172 1. `application/json` 173 1. `application/x-ndjson` 174 1. `application/xml` 175 1. `+json` (matches `application/geo+json`, etc.) 176 1. `+xml` (matches `application/rss+xml`, etc.) 177 1. `application/octet-stream` 178 179 `application/octet-stream` is needed as a fallback when no content type could be determined. You can add additional accepted content types with the `allowed_content_types` key. But the default ones don't get removed. 180 181 ## Excluding 182 183 ### Excluding Lines 184 185 You can exclude single lines inline. To do that you need a comment on that line that says: `editorconfig-checker-disable-line`. 186 187 ```javascript 188 const myTemplateString = ` 189 first line 190 wrongly indended line because it needs to be` // editorconfig-checker-disable-line 191 ``` 192 193 ### Excluding Blocks 194 195 To temporarily disable all checks, add a comment containing `editorconfig-checker-disable`. Re-enable with a comment containing `editorconfig-checker-enable` 196 197 ```javascript 198 // editorconfig-checker-disable 199 const myTemplateString = ` 200 first line 201 wrongly indended line because it needs to be 202 ` 203 // editorconfig-checker-enable 204 ``` 205 206 ### Excluding Files 207 208 #### Inline 209 210 If you want to exclude a file inline you need a comment on the first line of the file that contains: `editorconfig-checker-disable-file` 211 212 ```haskell 213 -- editorconfig-checker-disable-file 214 add :: Int -> Int -> Int 215 add x y = 216 let result = x + y -- falsy indentation would not report 217 in result -- falsy indentation would not report 218 ``` 219 220 #### Default Excludes 221 222 If you don't pass the `ignore-defaults` flag to the binary these files are excluded automatically: 223 224 ``` 225 "^\\.yarn/", 226 "^yarn\\.lock$", 227 "^package-lock\\.json$", 228 "^composer\\.lock$", 229 "^Cargo\\.lock$", 230 "^\\.pnp\\.cjs$", 231 "^\\.pnp\\.js$", 232 "^\\.pnp\\.loader\\.mjs$", 233 "\\.snap$", 234 "\\.otf$", 235 "\\.woff$", 236 "\\.woff2$", 237 "\\.eot$", 238 "\\.ttf$", 239 "\\.gif$", 240 "\\.png$", 241 "\\.jpg$", 242 "\\.jpeg$", 243 "\\.webp$", 244 "\\.avif", 245 "\\.mp4$", 246 "\\.wmv$", 247 "\\.svg$", 248 "\\.ico$", 249 "\\.bak$", 250 "\\.bin$", 251 "\\.pdf$", 252 "\\.zip$", 253 "\\.gz$", 254 "\\.tar$", 255 "\\.7z$", 256 "\\.bz2$", 257 "\\.log$", 258 "\\.patch$", 259 "\\.css\\.map$", 260 "\\.js\\.map$", 261 "min\\.css$", 262 "min\\.js$" 263 ``` 264 265 #### Manually Excluding 266 267 ##### via configuration 268 269 In your `.ecrc` file you can exclude files with the `"exclude"` key which takes an array of regular expressions. 270 This will get merged with the default excludes (if not ignored). You should remember to escape your regular expressions correctly. ;) 271 272 An `.ecrc` which would ignore all test files and all markdown files can look like this: 273 274 ```json 275 { 276 "Verbose": false, 277 "IgnoreDefaults": false, 278 "Exclude": ["testfiles", "\\.md$"], 279 "SpacesAfterTabs": false, 280 "Disable": { 281 "EndOfLine": false, 282 "Indentation": false, 283 "IndentSize": false, 284 "InsertFinalNewline": false, 285 "TrimTrailingWhitespace": false, 286 "MaxLineLength": false 287 } 288 } 289 ``` 290 291 ##### via arguments 292 293 If you want to play around how the tool would behave you can also pass the `--exclude` argument to the binary. This will accept a regular expression as well. If you use this argument the default excludes as well as the excludes from the `.ecrc` file will merged together. 294 295 For example: `ec --exclude node_modules` 296 297 ##### Generally 298 299 Every exclude option is merged together. 300 301 If you want to see which files the tool would check without checking them you can pass the `--dry-run` flag. 302 303 Note that while `--dry-run` outputs absolute paths, a regular expression matches on relative paths from where the `ec` command is used. 304 305 ## Docker 306 307 You are able to run this tool inside a Docker container. 308 To do this you need to have Docker installed and run this command in your repository root which you want to check: 309 `docker run --rm --volume=$PWD:/check mstruebing/editorconfig-checker` 310 311 Dockerhub: [mstruebing/editorconfig-checker](https://hub.docker.com/r/mstruebing/editorconfig-checker) 312 313 ## Continuous Integration 314 315 ### Mega-Linter 316 317 Instead of installing and configuring `editorconfig-checker` and all other linters in your project CI workflows (GitHub Actions & others), you can use [Mega-Linter](https://megalinter.io/latest/) which does all that for you with a single [assisted installation](https://megalinter.io/latest/install-assisted/). 318 319 Mega-Linter embeds [editorconfig-checker](https://megalinter.io/latest/descriptors/editorconfig_editorconfig_checker/) by default in all its [flavors](https://megalinter.io/latest/flavors/), meaning that it will be run at each commit or Pull Request to detect any issue related to `.editorconfig`. 320 321 If you want to use only `editorconfig-checker` and not the 70+ other linters, you can use the following `.mega-linter.yml` configuration file: 322 323 ```yaml 324 ENABLE: 325 - EDITORCONFIG 326 ``` 327 328 ### GitLab CI 329 330 The [ss-open/ci/recipes project](https://gitlab.com/ss-open/ci/recipes) offers a ready to use lint job integrating editorconfig-checker. 331 332 - Main documentation: https://gitlab.com/ss-open/ci/recipes/-/blob/main/README.md 333 - Editorconfig job specific documentation: https://gitlab.com/ss-open/ci/recipes/-/blob/main/stages/lint/editorconfig/README.md 334 335 ## Support 336 337 If you have any questions, suggestions, need a wrapper for a programming language or just want to chat join #editorconfig-checker on freenode(IRC). 338 If you don't have an IRC-client set up you can use the [freenode webchat](https://webchat.freenode.net/?channels=editorconfig-checker).