Giter VIP home page Giter VIP logo

editorconfig-checker / editorconfig-checker Goto Github PK

View Code? Open in Web Editor NEW
374.0 8.0 46.0 1.08 MB

A tool to verify that your files are in harmony with your .editorconfig

Home Page: https://editorconfig-checker.github.io/

License: MIT License

Go 86.91% Makefile 7.13% Dockerfile 0.61% Nix 4.94% JavaScript 0.15% C 0.26%
editorconfig editorconfig-checker clean-code cleancode codequality code-quality linter lint linting lintcode

editorconfig-checker's Introduction

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 Files
      1. Inline
      2. Default Excludes
      3. Manually Excluding
        1. via configuration
        2. via arguments
        3. Generally
  7. Docker
  8. Continuous Integration
  9. Support

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.1"
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.
  • gcc: GCC compatible output. Useful for editors that support compiling and showing syntax errors. ::: :

Configuration

The configuration is done via arguments or an .ecrc file.

A sample .ecrc 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 an 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 indended line because it needs to be` // editorconfig-checker-disable-line

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 indended line because it needs to be
`
// editorconfig-checker-enable

Excluding Files

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 don't pass the ignore-defaults flag to the binary these files 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$"

Manually Excluding

via configuration

In your .ecrc 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. ;)

An .ecrc 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. If you use this argument the default excludes as well as the excludes from the .ecrc file will merged together.

For example: ec --exclude node_modules

Generally

Every exclude option is merged together.

If you want to see which files the tool would check without checking them you can pass the --dry-run flag.

Note that while --dry-run outputs absolute paths, a regular expression matches on relative paths from where the ec command is used.

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

Dockerhub: 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.

editorconfig-checker's People

Contributors

bezirg avatar chalkygames123 avatar chambo-e avatar dependabot-preview[bot] avatar dependabot[bot] avatar generalmimon avatar greut avatar haumont avatar joan-s-molas avatar kurt-von-laven avatar kylepolansky avatar marshallford avatar masonm avatar mefody avatar mstruebing avatar notpeter avatar nvuillam avatar orhun avatar per1234 avatar rasa avatar ruxandrafed avatar silverwind avatar soullivaneuh avatar stepancheg avatar stephanlachnit avatar thelastproject avatar theoludwig avatar tomtomsen avatar vbrandl avatar vnayar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

editorconfig-checker's Issues

use golangs power for checking of files

Golang is very good at making things concurrent/run in parallel.
This should be taken into account when searching for files to check and also when running the validators over these files.

Performance measures would be nice :)

review error handling

Maybe it would be a better approach to hand the errors up to the main/calling function and decide there if something and what should happen. Currently there are mostly just panics

The panics are bubbled up into main.go now.

Option to only disable indent_size check

It would be great to be able to just disable indent_size check but not indent_style check.

Currently it is only possible to -disable-indentation which means disabling indent_size and indent_style check.

Unfortunately there are many use cases where indent_size is not correct in complex files because every language handles some special cases differently. Also if you have blank lines with just the correct number of spaces the check fails at the moment with "Wrong amount of left-padding spaces(want multiple of x)"

At the moment it is not possible in our workspace to fix all indent_size problems, but we would like to check the indent_style only but not the indent_size.

Make default excludes configurable

The defaultExcludes are currently hardcoded into the main.go but they should be configurable either via .ecrc/.editorconfigrc or via cli parameter.

Introduce config file

There should be a config file i.e. .ecrc which contains all configuration options and you do not have to use command line flags.

Ignores non-wildcard rules

Create a .editorconfig like this

root = true

[*]
insert_final_newline = false
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[file.toml]
indent_style = space
indent_size = 2

and with a file.toml containing

[foo]
  bar = "buz"

The tool will wrongly say it expected to see tabs

.\file.toml:
        2: Wrong indentation type(spaces instead of tabs)

1 errors found

Changing the rule to be a wildcard (*.toml) works, but is undesirable when fine-grained control is required.

dry run command

There should be a dry-run command which should output all files which are checked.

Support checking all files' text encodings, if declared to be UTF-8

Enforcing a specified text encoding in a monorepo rife with all kinds of textual resources is hard for crossplatform development teams. This feature would be of great value, and simple to implement. Especially if only a BOM-check is done. Alternatively, every text file that is covered by the EditorConfig settings can be decoded as UTF-8 on the fly.

Get git versioned files

instead of checking each file if it is versioned by git it would be a HUGE performance gain if I would get a list of every versioned file and then doing stuff with them.

git ls-tree -r --name-only HEAD

`insert_final_newline` should ensure that the file doesn't have a final newline at the end.

As pointed out in this issue: editorconfig-checker/editorconfig-checker.javascript#59
The behaviour of insert_final_newline is handled wrongly.

Current behavour: right now it checks only if insert_final_newline is set to true and does nothing otherwise.
Expected behaviour: it should be checked that these files don't have a final newline if insert_final_newline is set to false. If it is left blank it shouldn't matter at all.

Thanks to @ericcornelissen for pointing out.

Create Chocolatey Package

It would be very useful for Winfows users if you could create a Chocolatey package to keep an always-up-to-date binary release of editorconfig-checker locally.

Ideally, the binary file should be renamed something like editorconfig-checker.exe (which is more intuitive than ec-windows-amd64.exe, etc.), regarldess of the app bitness (Chocolatey will always try to install the app with the same bitness of the OS), and make the binary available on the system PATH (Chocolatey can handle this via shims).

Chocolatey is a useful tool to keep updated many applications under Windows via a unified interface, especially via Chocolatey GUI. It can update both standalone apps as well as software that requires full setup.

As officials maintainers of the editorconfig-checker project, you could automate on GitHub the process of updating the Chocolatey package on every new release. So, after some initial setup effort, maintaining the Choco package updated should be an effortless task.

Thanks for all the great work!

Bug: Default excludes ignored?

According to the first output line

Exclude Regexp: yarn\.lock$|package-lock\.json|composer\.lock$|\.snap$|\.otf$|\.woff$|\.woff2$|\.eot$|\.ttf$|\.gif$|\.png$|\.jpg$|\.jpeg$|\.mp4$|\.wmv$|\.svg$|\.ico$|\.bak$|\.bin$|\.pdf$|\.zip$|\.gz$|\.tar$|\.7z$|\.bz2$|\.log$|\.css\.map$|\.js\.map$|min\.css$|min\.js$

I would expect that the given regex would be applied but that does not happen (at lest in the docker container):

$ docker run --rm -v=$PWD:/check mstruebing/editorconfig-checker ec -v | grep yarn.lock
Add yarn.lock to be checked
Validate yarn.lock
$ docker run --rm -v=$PWD:/check mstruebing/editorconfig-checker ec -v -exclude 'yarn\.lock$|package-lock\.json|composer\.lock$|\.snap$|\.otf$|\.woff$|\.woff2$|\.eot$|\.ttf$|\.gif$|\.png$|\.jpg$|\.jpeg$|\.mp4$|\.wmv$|\.svg$|\.ico$|\.bak$|\.bin$|\.pdf$|\.zip$|\.gz$|\.tar$|\.7z$|\.bz2$|\.log$|\.css\.map$|\.js\.map$|min\.css$|min\.js$' | grep yarn.lock
Don't add yarn.lock to be checked

RFC: Caching the different versions of the binary in wrapper tools

In every wrapper tool the release is currently downloaded to the directory where the wrapper tool is located and extracted to the bin directory right there.

We should consider caching the already downloaded binary, especially since maybe you have many projects which depend on it what would be a massive waste of space.

My suggestion would be (inspired and adopted from @vbrandl):

  1. Download the release in a writable temporary directory
  2. Extract the binary in the temporary directory
  3. Verify the correctness of the binary via some hashing function (maybe sha512?), maybe the right hash should be hard-coded into the wrapper itself?
  4. Move the binary either to $XDG_DATA_HOME/[ec|editorconfig-checker]/x.x.x/ec $XDG_CACHE_HOME/[ec|editorconfig-checker]/x.x.x/ec- I'm not really sure what would be more sufficient.
  5. Check the correctness of the binary on every execution of the wrapper, if hash doesn't match start with point 1.

Is there something I'm missing? Are there any other good ideas?
Feel free to tell me :)

cache already checked results

We could save the results to specific checks maybe somewhere in ~/.editorconfig-checker/ or ~/.ec/
and so make recurring checks way faster.

Also keep in mind to add clear-cache and no-cache flags.

Don't run exclude regexp on absolute path

Currently the regular expression of the default excludes are run on the whole absolute path but it should rather run on the relative path of the project root somehow.

For example for this repository, git would match (read exclude) all of this and much more (because of the github.com):

git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/Makefile
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/README.md
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/bin/ec
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/cmd/editorconfig-checker/main.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/cmd/editorconfig-checker/main_test.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/coverage.txt
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/docs/logo.png
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/pkg/types/types.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/pkg/utils/utils.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/pkg/utils/utils_test.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/pkg/validators/validators.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/pkg/validators/validators_test.go
git /home/maex/go/src/github.com/editorconfig-checker/editorconfig-checker.go/tags

Disable line

There should be an inline option to disable single lines from checking.

// editorconfig-checker disable-line or something

Support "tabs for indentation, spaces for alignment" style

This is a continuation of discussion of the issue in editorconfig-checker.javascript project.

"Tabs for indentation, spaces for alignment" is a common coding style. It allows the code viewers to adjust any tab space they want without breaking alignments. Addition information is presented in these articles: https://dmitryfrank.com/articles/indent_with_tabs_align_with_spaces, https://vim.fandom.com/wiki/Indent_with_tabs,_align_with_spaces. This style is called "Smart tabs" in some IDEs (e. g. in JetBrains IDEs).

For now for projects using this style, editorconfig-checker shows the following error for each line with alignment:

136: Wrong indentation type(spaces instead of tabs)

I see several ways to deal with it it.

I think, the most natural way is automatically detect the alignment with spaces. If we are in a block, nested with N tabs, and then if we see spaces after N tabs, we should consider it an alignment with spaces.

Another approach would be to introduce additional command line key to enable this style or additional custom parameter to .editorconfig (if this is possible).

max_line_length should support non ASCII characters

Currently it seems like ä, ö and ü are counted as two characters which makes the max_line_length rule not usable for not plain ASCII files (like UTF-8 so everything with emojis which maybe should also count as one character ;))

autofix flag

introduce an autofix flag which should fix all issues which can be fixed.

editorconfig-checker ignores multiple files with brace expansion notation

Also opening an issue here because the python repo might not be monitored.

See editorconfig-checker/editorconfig-checker.python#1


This is my .editorconfig:

root = true

[*]
insert_final_newline = true
indent_style = space
tab_width = 4
trim_trailing_whitespace = true

[*.yml]
tab_width = 2

[{Makefile, Makefile.am, Makefile.in}]
indent_style = tab

[*.{diff, patch}]
trim_trailing_whitespace = false

When running editorconfig-checker, it warns about trailing whitespaces in patches.

It works fine if I change

[*.{diff, patch}]
trim_trailing_whitespace = false

to

[*.diff]
trim_trailing_whitespace = false
[*.patch]
trim_trailing_whitespace = false

But this shouldn't be necessary as the original syntax is supported by the editorconfig standard. It is used in the example.

editorconfig-checker -version
2.0.3

python --version
Python 3.8.1

extend default excludes

It would be cool to have some default excludes which can be extended and/or discarded for own excludes.

Problems excluding files via .ecrc on Windows

I upgraded from 1.4.0 release to 2.0.1 of https://github.com/editorconfig-checker/editorconfig-checker.javascript.

Using the old version I used a bunch of --exclude-pattern parameters. These exclusions I moved to a .ecrc file:

\.js$
\.jsx$
\.css$
\.scss$
\.less$
^dir1\/
^dir2\/
^dir3\/subdir1\/
^dir3\/subdir2\/

This works on Mac but on Windows it seems that the config file is completely ignored. I also tried to test for / or \, with optional prepending ./ and without ^. But everything I tried without success.

Disable file

There should be an inline option to disable single files from checking.

// editorconfig-checker disable-file or something

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.