GithubHelp home page GithubHelp logo

ec4j / editorconfig-ant-tasks Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 84 KB

Ant tasks for checking whether project files comply with format rules defined in .editorconfig files and eventually also for fixing the violations

License: Apache License 2.0

Java 100.00%
apache-ant editorconfig

editorconfig-ant-tasks's Introduction

ec4j

License Maven Central badge

ec4j is an EditorConfig implementation for Java. It provides:

  • A parser for .editorconfig files

  • An API for querying EditorConfig properties applicable to a given file

  • A model of an editorconfig file rich enough to support validation, folding, code completion, etc. of .editorconfig files in editors and IDEs.

Who is using ec4j?

Here are some projects that use ec4j:

Basic usage

Add the following dependency to your project:

<dependency>
  <groupId>org.ec4j.core</groupId>
  <artifactId>ec4j-core</artifactId>
  <version><!-- check the latest on http://central.maven.org/maven2/org/ec4j/core/ec4j-core/ --></version>
</dependency>

To parse a single .editorconfig file into an EditorConfig model:

java.nio.file.Path editorConfigFile = Paths.get("path/to/my/.editorconfig");
EditorConfigParser parser = EditorConfigParser.builder().build();
EditorConfigModelHandler handler = new EditorConfigModelHandler(PropertyTypeRegistry.default_(), Version.CURRENT);
parser.parse(Resources.ofPath(editorConfigFile, StandardCharsets.UTF_8), handler, ErrorHandler.THROW_SYNTAX_ERRORS_IGNORE_OTHERS);
EditorConfig editorConfig = handler.getEditorConfig();

To query the properties applicable to a file in a source tree:

Cache myCache = ...; // e.g. Caches.permanent()
EditorConfigLoader myLoader = ...; // e.g. EditorConfigLoader.default_()
ResourcePropertiesService propService = ResourcePropertiesService.builder()
        .cache(myCache)
        .loader(myLoader)
        .rootDirectory(ResourcePaths.ofPath(Paths.get("/my/dir"), StandardCharsets.UTF_8))
        .build();

ResourceProperties props = propService.queryProperties(Resources.ofPath(Paths.get("/my/dir1/Class1.java"), StandardCharsets.UTF_8));
IndentStyleValue indentStyleValue = props.getValue(PropertyType.indent_style, IndentStyleValue.space, true);
char indentChar = indentStyleValue.getIndentChar();
// Now you can e.g. check that /my/dir1/Class1.java is indented using indentChar

How to build

Prerequisites:

  • Java 8+

  • Optionally Maven 3.6.1+, unless you want to use ./mvnw or mvnw.bat delivered by the project

  • cmake 2.6+ to run the editorconfig-core-test testsuite (optional).

The most common build with unit tests:

./mvnw clean install

On Windows:

mvnw.bat clean install

A build with editorconfig-core-test testsuite:

git submodule init
git submodule update
mvn -Pcore-test clean install && ( cd core && cmake . && ctest . )

Relationship to editorconfig-core-java

The authors of ec4j decided to start ec4j because they were unsuccessful with their proposals in editorconfig-core-java.

Although ec4j is not a fork of editorconfig-core-java it uses a few portions of code from editorconfig-core-java. Such ones are clearly marked in ec4j 's JavaDoc.

ec4j aims at offering a superset of editorconfig-core-java 's functionality.

While editorconfig-core-java supports just the basic use case of querying the EditorConfig properties applicable to a given file, ec4j offers much more in addition to that:

Misc.

editorconfig-ant-tasks's People

Contributors

ppalaga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.