A tool to verify that your files are in harmony with your .editorconfig
A tool to verify that your files are in harmony with your .editorconfig
This is a tool to check if your files consider your .editorconfig rules.
Most tools—like linters, for example—only test one filetype and need an extra configuration.
This tool only needs your .editorconfig to check all files.
If you don't know about editorconfig already you can read about it here: editorconfig.org.
Currently, implemented editorconfig features are:
end_of_lineinsert_final_newlinetrim_trailing_whitespaceindent_styleindent_sizemax_line_lengthcharset (see Charset Setting below)Unsupported features are:
spelling_languagetab_widthVERSION="v4.0.1"
OS="linux"
ARCH="amd64"
curl -O -L -C - https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$VERSION/editorconfig-checker-$OS-$ARCH.tar.gz && \
tar xzf editorconfig-checker-$OS-$ARCH.tar.gz && \
./bin/editorconfig-checker-$OS-$ARCHYou can install editorconfig-checker in several ways, depending on your platform and preferences:
If you have Go installed, you can install editorconfig-checker with the following command:
go install github.com/editorconfig-checker/editorconfig-checker/v4/cmd/editorconfig-checker@latestGrab a binary from the release page.
If you use Nix:
nix-env -iA nixpkgs.editorconfig-checkerOr, with flakes:
nix run nixpkgs#editorconfig-checkerYou can run editorconfig-checker inside a Docker container without installing it locally:
docker run --rm --volume=$PWD:/check ghcr.io/editorconfig-checker/editorconfig-checker:4.0.1or
docker run --rm --volume=$PWD:/check mstruebing/editorconfig-checker:4.0.1This command mounts your current directory into the container and runs the check inside it.
See also: Docker Hub: mstruebing/editorconfig-checker
If you use mise, install with:
mise use -g editorconfig-checker@latestIf you use Homebrew on macOS or Linux:
brew install editorconfig-checkerpacman -S editorconfig-checker# With your favorite AUR helper, e.g.:
paru -S editorconfig-checker-gitWe do have a couple of language specific wrappers available that you can install with your favorites language package manager. See their respective documentation for installation and usage instructions.
…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.
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.
Use --fix to apply the safe fixes supported by
editorconfig-checker before it checks the files. The fix mode currently supports
only these rules:
trim_trailing_whitespace = trueend_of_line = lf, cr, or crlfinsert_final_newline = true or falseIndentation, indent_size, max_line_length, and charset violations remain
check-only. All non-UTF-8, invalid UTF-8, and binary-like files are skipped, as
are symbolic links and empty files. Inline disable directives are honored for
trailing whitespace, and files with editorconfig-checker-disable-file are
skipped. A second --fix run is idempotent. Changes are written through a
same-directory temporary file and replacement; this is crash-resistant and
atomic only where the operating system and filesystem provide those guarantees.
Replacing a path does not update other hard links to the original file.
The following output formats are supported:
default: Plain text, human readable output.
:
-: gcc: GCC compatible output. Useful for editors that support compiling and showing syntax errors.
::: :
github-actions: The format used by GitHub Actions
::error file=,line=,endLine=::
codeclimate: The Code Climate json format used for custom quality reports in GitLab CI
[
{
"check_name": "editorconfig-checker",
"description": "Wrong indent style found (tabs instead of spaces)",
"fingerprint": "e87a958a3960d60a11d4b49c563cccd2",
"severity": "minor",
"location": {
"path": ".vscode/extensions.json",
"lines": {
"begin": 2,
"end": 2
}
}
}
]The configuration is done via arguments or it will take the config file named .editorconfig-checker.json.
A sample configuration file can look like this and will be used from your current working directory if not specified via the --config argument:
{
"$schema": "https://raw.githubusercontent.com/editorconfig-checker/editorconfig-checker/v4.0.1/.editorconfig-checker.schema.json",
"Verbose": false,
"Debug": false,
"IgnoreDefaults": false,
"SpacesAfterTabs": false,
"NoColor": false,
"Exclude": [],
"AllowedContentTypes": [],
"PassedFiles": [],
"Disable": {
"EndOfLine": false,
"Indentation": false,
"IndentSize": false,
"InsertFinalNewline": false,
"TrimTrailingWhitespace": false,
"MaxLineLength": false,
"Charset": false
}
}The $schema property is an optional field for specifying the JSON Schema and is ignored by editorconfig-checker.
| Key | Type | Default | Description |
|---|---|---|---|
Verbose |
bool | false |
Print verbose output during checking |
Debug |
bool | false |
Print debugging information |
IgnoreDefaults |
bool | false |
Ignore the default exclude patterns |
SpacesAfterTabs |
bool | false |
Allow spaces after tabs in indentation (mixed indentation). When false, spaces following tabs are flagged as errors |
NoColor |
bool | false |
Disable colored output |
Exclude |
string[] | [] |
Regular expressions for files to exclude from checking |
AllowedContentTypes |
string[] | [] |
Additional content types to check (added to the defaults listed below) |
PassedFiles |
string[] | [] |
Explicit list of files, directories, or shell-style glob patterns (e.g. src/*.go) to check. When set, only these paths are checked instead of auto-discovering files from the working directory or git. Glob patterns that don't match any file are left as-is so a subsequent content-type check surfaces the missing path |
Version |
string | "" |
When set, the tool verifies this value matches the binary version and exits with an error if they differ. Useful for pinning a specific version in CI |
Disable |
object | Selectively disable individual checks (see below) |
You can set any of the options under the "Disable" section to true to disable those particular checks.
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.
You can create a configuration with the init-flag. If you specify a config-path it will be created there.
By default, the allowed_content_types are:
text/ (matches text/plain, text/html, etc.)application/ecmascriptapplication/jsonapplication/x-ndjsonapplication/xml+json (matches application/geo+json, etc.)+xml (matches application/rss+xml, etc.)application/octet-streamapplication/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.
You can exclude single lines inline. To do that you need a comment on that line that says: editorconfig-checker-disable-line.
const myTemplateString = `
first line
wrongly indented line because it needs to be` // editorconfig-checker-disable-lineAlternatively, you can use editorconfig-checker-disable-next-line to skip the line that comes after this comment.
This modifier is present to improve readability, or because your sometimes have no other choice because of your own/language constraints.
// editorconfig-checker-disable-next-line used because blah blah blah what ever the reason blah
const myTemplateString = `a line that is (...) longer (...) than ... usual` // or with a very long inline commentPlease note that using editorconfig-checker-disable-next-line has only an effect on the next line, so it will report if the line where you added the modifier doesn't comply.
To temporarily disable all checks, add a comment containing editorconfig-checker-disable. Re-enable with a comment containing editorconfig-checker-enable
// editorconfig-checker-disable
const myTemplateString = `
first line
wrongly indented line because it needs to be
`
// editorconfig-checker-enableYou can exclude paths from being checked in several ways:
--excludeThe --exclude flag accepts a single regular expression. To exclude multiple patterns, combine them using | (regex alternation):
editorconfig-checker --exclude "vendor|testdata|\.min\.js$"In a configuration file, you can list each pattern as a separate entry in the Exclude array instead:
{
"Exclude": ["vendor", "testdata", "\\.min\\.js$"]
}All these excludes are used in addition to the default excludes, unless you opt out of them.
If you want to see which files would be checked without checking them you can pass the --dry-run flag.
Note that while --dry-run might output absolute paths, the regular expression you writ
No open issues yet, or sync has not completed.