Skip to content

A collection of style checkers for XMIR: they don't predict runtime errors, but prevent compilation mistakes

License

Notifications You must be signed in to change notification settings

objectionary/lints

Repository files navigation

Collection of Checkers for EO Programs

EO principles respected here We recommend IntelliJ IDEA

mvn PDD status Maven Central Javadoc Hits-of-Code codecov License

This Java package is a collection of "lints" (aka "checkers") for XMIR (an intermediate representation of a EO object). This is not about static analysis or code formatting. This is about best practices and readiness of code for successful compilation and execution.

We use this package as a dependency in the EO-to-Java compiler:

<dependency>
  <groupId>org.eolang</groupId>
  <artifactId>lints</artifactId>
  <version>0.0.49</version>
</dependency>

You can also use it in order to validate the validity of XMIR documents your software may generate:

import com.jcabi.xml.StrictXML;
import org.eolang.lints.Source;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

final class Foo {
    @Test
    void testValidSource() {
        Assertions.assertTrue(
            new Source(
                new StrictXML("<object> your XMIR goes here </object>")
            ).defects().isEmpty()
        );
    }
}

Then, you can run a whole-program analysis of XMIR files in your project, using the Program class (there is a different set of lints to be executed here!):

import java.nio.file.Paths;
import org.eolang.lints.Program;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

final class Foo {
    @Test
    void testProgram() {
        Assertions.assertTrue(
            new Program(
                Paths.get("xmir-files") // directory with XMIR files
            ).defects().isEmpty()
        );
    }
}

It is possible to disable any particular linter in a program, with the help of the +unlint meta.

Design of This Library

The library is designed as a set of lints, each of which is a separate class implementing the Lint interface. Each lint is responsible for checking one particular aspect of the XMIR document. The Source class is responsible for running all lints and collecting defects for a single XMIR file. The Program class is responsible for running all lints and collecting defects for whole EO program, as set of XMIR files. All in all, there are only four classes and interfaces that are supposed to be exposed to a user of the library:

  • Source - checker of a single XMIR
  • Program - checker of a set of XMIR
  • Defect - a single defect discovered
  • Severity - a severity of a defect

There are also a few classes that implement Iterable<Lint>: PkMono, PkWpa, and PkByXsl. They are supposed to be used only by the Source and Program, and are not supposed to be exposed to the user of the library. They are responsible for providing a set of lints to be executed, building them from the information in classpath.

Benchmark

Here is the result of linting XMIRs:

Input: com/sun/jna/PointerType.class (S source)
Lint time: 4s (4446 ms)

Input: com/sun/jna/Memory.class (M source)
Lint time: 5s (4951 ms)

Input: com/sun/jna/Pointer.class (L source)
Lint time: 6s (6035 ms)

Input: com/sun/jna/Structure.class (XL source)
Lint time: 7s (7342 ms)

Input: org/apache/hadoop/hdfs/server/namenode/FSNamesystem.class (XXL source)
Lint time: 20s (20040 ms)



unlint-non-existing-defect (XXL) (9925 ms)
unlint-non-existing-defect (XL) (3628 ms)
unlint-non-existing-defect (L) (2983 ms)
unlint-non-existing-defect (M) (2435 ms)
unlint-non-existing-defect (S) (2194 ms)
application-duality (XXL) (1555 ms)
object-has-data (XXL) (1273 ms)
named-object-abstract-nested (XXL) (980 ms)
name-outside-of-abstract-object (XXL) (805 ms)
incorrect-bytes-format (XXL) (418 ms)
line-is-absent (XXL) (354 ms)
application-duality (XL) (313 ms)
bytes-without-data (XXL) (276 ms)
duplicate-names (XXL) (268 ms)
object-has-data (XL) (263 ms)
named-object-abstract-nested (XL) (197 ms)

The results were calculated in this GHA job on 2025-05-05 at 14:53, on Linux with 4 CPUs.

How to Contribute

Fork repository, make changes, then send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

mvn clean install -Pqulice

Also, run this and make sure your changes don't slow us down:

mvn jmh:benchmark

You will need Maven 3.3+ and Java 11+ installed. Also, if you have xcop installed, make sure it is version 0.8.0+. If you want the code to be checked using error-prone, use Java 17+

About

A collection of style checkers for XMIR: they don't predict runtime errors, but prevent compilation mistakes

Topics

Resources

License

Stars

Watchers

Forks

Contributors 8