Nothing Special   »   [go: up one dir, main page]

Skip to content

editorconfig-checker/editorconfig-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

editorconfig-checker

Buy Me A Coffee

ci codecov Hits-of-Code Go Report Card

Logo

  1. What?
  2. Quickstart
  3. Installation
  4. Usage
  5. Configuration
  6. Excluding
    1. Excluding Lines
    2. Excluding Blocks
    3. Excluding Paths
      1. Inline
      2. Default Excludes
      3. Ignoring Default Excludes
      4. Manually Excluding
        1. via configuration
        2. via arguments
  7. Docker
  8. Continuous Integration
  9. Support
  10. Contributing
  11. Semantic Versioning Policy

What?

Example Screenshot

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_line
  • insert_final_newline
  • trim_trailing_whitespace
  • indent_style
  • indent_size
  • max_line_length

Unsupported features are:

  • charset

Quickstart

VERSION="v3.0.3"
OS="linux"
ARCH="amd64"
curl -O -L -C - https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$VERSION/ec-$OS-$ARCH.tar.gz && \
tar xzf ec-$OS-$ARCH.tar.gz && \
./bin/ec-$OS-$ARCH

Installation

Grab a binary from the release page.

If you have go installed you can run go get github.com/editorconfig-checker/editorconfig-checker/v3 and run make build inside the project folder. This will place a binary called ec into the bin directory.

If you are using Arch Linux, you can use pacman to install from extra repository:

pacman -S editorconfig-checker

Also, development (VCS) package is available in the AUR:

# <favourite-aur-helper> <install-command> editorconfig-checker-git

# i.e.
paru -S editorconfig-checker-git

If Go 1.16 or greater is installed, you can also install it globally via go install:

go install github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@latest

Usage

USAGE:
  -config string
        config
  -debug
        print debugging information
  -disable-end-of-line
        disables the trailing whitespace check
  -disable-indent-size
        disables only the indent-size check
  -disable-indentation
        disables the indentation check
  -disable-insert-final-newline
        disables the final newline check
  -disable-trim-trailing-whitespace
        disables the trailing whitespace check
  -dry-run
        show which files would be checked
  -exclude string
        a regex which files should be excluded from checking - needs to be a valid regular expression
  -format
        specifies the output format, see "Formats" below for more information
  -h    print the help
  -help
        print the help
  -ignore-defaults
        ignore default excludes
  -init
        creates an initial configuration
  -no-color
        dont print colors
  -v    print debugging information
  -verbose
        print debugging information
  -version
        print the version number

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.

Formats

The following output formats are supported:

  • default: Plain text, human readable output.
    <file>:
      <startingLine>-<endLine>: <message>
    
  • gcc: GCC compatible output. Useful for editors that support compiling and showing syntax errors.
    <file>:<line>:<column>: <type>: <message>
  • github-actions: The format used by GitHub Actions
    ::error file=<file>,line=<startingLine>,endLine=<endingLine>::<message>
  • 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
          }
        }
      }
    ]

Configuration

The configuration is done via arguments or it will take the first config file found with the following file names:

  • .editorconfig-checker.json
  • .ecrc (deprecated filename, soon unsupported)

A sample configuration file can look like this and will be used from your current working directory if not specified via the --config argument:

{
  "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
  }
}

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:

  1. text/ (matches text/plain, text/html, etc.)
  2. application/ecmascript
  3. application/json
  4. application/x-ndjson
  5. application/xml
  6. +json (matches application/geo+json, etc.)
  7. +xml (matches application/rss+xml, etc.)
  8. application/octet-stream

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.

Excluding

Excluding Lines

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-line

Alternatively, 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 comment

Please 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.

Excluding Blocks

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-enable

Excluding Paths

You can exclude paths from being checked in several ways:

  • ignoring a file by documenting it inside the to-be-excluded file
  • adding a regex matching the path to the configuration file
  • passing a regex matching the path as argument to --exclude

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 write must match the filenames using relative paths from where editorconfig-checker is used. This becomes especially relevant if you need to anchor your regular expression in order to only match files in the top level your checked directory.

Inline

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

-- editorconfig-checker-disable-file
add :: Int -> Int -> Int
add x y =
  let result = x + y -- falsy indentation would not report
  in result -- falsy indentation would not report

Default Excludes

If you choose to ignore them, these paths are excluded automatically:

"^\\.yarn/",
"^yarn\\.lock$",
"^package-lock\\.json$",
"^composer\\.lock$",
"^Cargo\\.lock$",
"^\\.pnp\\.cjs$",
"^\\.pnp\\.js$",
"^\\.pnp\\.loader\\.mjs$",
"\\.snap$",
"\\.otf$",
"\\.woff$",
"\\.woff2$",
"\\.eot$",
"\\.ttf$",
"\\.gif$",
"\\.png$",
"\\.jpg$",
"\\.jpeg$",
"\\.webp$",
"\\.avif",
"\\.pnm",
"\\.pbm",
"\\.pgm",
"\\.ppm",
"\\.mp4$",
"\\.wmv$",
"\\.svg$",
"\\.ico$",
"\\.bak$",
"\\.bin$",
"\\.pdf$",
"\\.zip$",
"\\.gz$",
"\\.tar$",
"\\.7z$",
"\\.bz2$",
"\\.log$",
"\\.patch$",
"\\.css\\.map$",
"\\.js\\.map$",
"min\\.css$",
"min\\.js$"

Ignoring Default Excludes

If you either set IgnoreDefaults to true or pass the -ignore-defaults commandline switch, the default excludes will be ignored entirely.

Manually Excluding

via configuration

In your configuration file you can exclude files with the "exclude" key which takes an array of regular expressions. This will get merged with the default excludes (if not ignored). You should remember to escape your regular expressions correctly.

A configuration file which would ignore all test files and all Markdown files can look like this:

{
  "Verbose": false,
  "IgnoreDefaults": false,
  "Exclude": ["testfiles", "\\.md$"],
  "SpacesAfterTabs": false,
  "Disable": {
    "EndOfLine": false,
    "Indentation": false,
    "IndentSize": false,
    "InsertFinalNewline": false,
    "TrimTrailingWhitespace": false,
    "MaxLineLength": false
  }
}
via arguments

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. The argument given will be added to the excludes as defined by your configuration file (respecting both its Exclude and IgnoreDefaults settings).

For example: ec --exclude node_modules

Docker

You are able to run this tool inside a Docker container. To do this you need to have Docker installed and run this command in your repository root which you want to check: docker run --rm --volume=$PWD:/check mstruebing/editorconfig-checker

Docker Hub: mstruebing/editorconfig-checker

Continuous Integration

Mega-Linter

Instead of installing and configuring editorconfig-checker and all other linters in your project CI workflows (GitHub Actions & others), you can use Mega-Linter which does all that for you with a single assisted installation.

Mega-Linter embeds editorconfig-checker by default in all its flavors, meaning that it will be run at each commit or Pull Request to detect any issue related to .editorconfig.

If you want to use only editorconfig-checker and not the 70+ other linters, you can use the following .mega-linter.yml configuration file:

ENABLE:
  - EDITORCONFIG

GitLab CI

The ss-open/ci/recipes project offers a ready to use lint job integrating editorconfig-checker.

Support

If you have any questions, suggestions, need a wrapper for a programming language or just want to chat join #editorconfig-checker on freenode(IRC). If you don't have an IRC-client set up you can use the freenode webchat.

Contributing

Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a spelling mistake.

The steps to contribute can be found in the CONTRIBUTING.md file.

Semantic Versioning Policy

editorconfig-checker adheres to Semantic Versioning for releases.

However, as it is a code quality tool, it's not always clear when a minor or major version bump occurs. The following rules are used to determine the version bump:

  • Patch release (1.0.x -> 1.0.y)
    • Updates to output formats (error messages, logs, ...).
    • Performance improvements which doesn't affect behavior.
    • Build process changes (e.g., updating dependencies, updating Dockerfile, ...).
    • Reverts (reverting a previous commit).
    • Bug fixes which result in editorconfig-checker reporting less linting errors (removing "false-positive" linting errors).
  • Minor release (1.x.0 -> 1.y.0)
  • Major release (x.0.0 -> y.0.0)