Iwillfailyou

Elegant Objects Respected Here

nullfree status staticfree status allfinal status allpublic status

Build Status codecov

License: MIT

logo

What is it?

Iwillfailyou is the static analyser for your elegant code.

How it works?

Just see, what it can find in seemingly usual code:

package com.example;

import java.util.Collection;
import java.util.StringTokenizer;

public class Words {
    public static final String DELIM = " ,.";

    private Collection<String> words;

    public Words() {
        this.words = null;
    }

    public Words(Collection<String> words) {
        this.words = words;
    }

    boolean containsIn(String text) {
        if (words == null) return false;

        StringTokenizer tokenizer = new StringTokenizer(text, DELIM);
        while (tokenizer.hasMoreTokens()) {
            String nextWord = tokenizer.nextToken();
            if (words.contains(nextWord)) return true;
        }

        return false;
    }
}

The violations of the iwillfailyou analysis:

nullfree
com.example.Words(Words.java:12) > this.words = null
com.example.Words.containsIn(Words.java:20) > words == null

staticfree
com.example.Words(Words.java:7) > public static final String DELIM = " ,.";

allfinal
com.example.Words(Words.java:9) > private Collection<String> words;
com.example.Words.containsIn(Words.java:22) > StringTokenizer tokenizer = new StringTokenizer(text, DELIM)
com.example.Words.containsIn(Words.java:24) > String nextWord = tokenizer.nextToken()
com.example.Words(Words.java:15) > Collection<String> words
com.example.Words.containsIn(Words.java:19) > String text
com.example.Words(Words.java:6) > public class Words {

allpublic
com.example.Words.containsIn(Words.java:19) > boolean containsIn(String text) {

Get started

Gradle

Add the plugin to the root build.gradle

plugins {
    id 'com.iwillfailyou' version 'x.y.z'
}

// then configure it, if you need:
iwillfailyou {
    offline = true // default false
    nullfree {
        disabled = true // default false
        threshold = 3 // default 0
        skipComparisons = true // default false
    }
    staticfree {
        disabled = true // default false
        threshold = 2 // default 0
    }
    allfinal {
        disabled = true // default false
        threshold = 1 // default 0
        skipInterfaceMethodParams = false // default true
        skipLambdaParams = true // default false
        skipCatchParams = true // default false
    }
    allpublic {
        disabled = true // default false
        threshold = 4 // default 0
    } 
}

Where x.y.z is actual version from gradle plugins Gradle plugin version

Invoke it:

./gradlew iwillfailyou

Maven

Add the plugin to the pom.xml

<plugin>
  <groupId>com.iwillfailyou</groupId>
  <artifactId>iwillfailyou-maven-plugin</artifactId>
  <version>x.y.z</version>

  <!-- then configure it, if you need: -->
  <configuration>
    <offline>true</offline><!-- default false -->
    <nullfree>
      <disabled>true</disabled><!-- default false -->
      <threshold>3</threshold><!-- default 0 -->
      <skipComparisons>true</skipComparisons><!-- default false -->
    </nullfree>
    <staticfree>
      <disabled>true</disabled><!-- default false -->
      <threshold>2</threshold><!-- default 0 -->
    </staticfree>
    <allfinal>
      <disabled>true</disabled><!-- default false -->
      <threshold>1</threshold><!-- default 0 -->
      <skipInterfaceMethodParams>false</skipInterfaceMethodParams><!-- default true -->
      <skipLambdaParams>true</skipLambdaParams><!-- default false -->
      <skipCatchParams>true</skipCatchParams><!-- default false -->
    </allfinal>
    <allpublic>
      <disabled>true</disabled><!-- default false -->
      <threshold>4</threshold><!-- default 0 -->
    </allpublic>
  </configuration>
</plugin>

Invoke it:

mvn iwillfailyou:iwillfailyou

Where x.y.z is actual version from maven central Maven plugin version

Inspections

  1. nullfree (Why null is bad?) elegant code must not use the null keywords

  2. staticfree (Why static is bad?) elegant code must not use the static keywords

  3. allfinal every class, every field, every argument, every local variable must be final in the elegant code

  4. 🔄 instanceoffree [in progress] elegant code must not use the instanceof keywords

  5. 🔄 inheritancefree [in progress] elegant code must not use the class inheritance (when one class extends another one), only composition and type inheritance has been allowed

  6. 🔄 enumfree [in progress] elegant code must not use the enums

  7. 🔄 switchfree [in progress] elegant code must not use the switch blocks/expressions

  8. 🔄 nomultiplereturn [in progress] elegant code must contain only one (or no one) return in an any method

  9. 🔄 getterfree [in progress] elegant code must not contain any getters

  10. 🔄 setterfree [in progress] elegant code must not contain any getters

  11. allpublic elegant code must use only public methods

  12. 🔄 nopublicmethodnotoverrides [in progress] every public method in the elegant code must be overrided from an interface

Nullfree

Plugin configuration options:

if (some == null) {
    ...
}

Can be suppressed in the code by @SuppressWarnings("nullfree")

Staticfree

Plugin configuration options:

Can be suppressed in the code by @SuppressWarnings("staticfree")

Allfinal

Plugin configuration options:

Can be suppressed in the code by @SuppressWarnings("allfinal")

Allpublic

Badges

If you use iwillfailyou plugin without offline = true settings, then you can attach the inspection badges to your readme file:

License

MIT