Skip to content
/ oop-cop Public

The static analysis tool and a Maven plugin that will help you model your objects, classes, methods properly by rejecting your non-perfect code.

License

Notifications You must be signed in to change notification settings

l3r8yJ/oop-cop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Managed By Self XDSD

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

maven central javadoc codecov

Hits-of-Code Lines-of-Code PDD status License

Motivation. We don't have such tool that will validate our project OOP practices, tells exactly where we are doing wrong.

OOPCOP is a static analysis tool and a Maven plugin that will help you model your objects, classes, methods properly by rejecting your non-perfect code. These things we don't tolerate:

  • -ER class names e.g. Parser, Validator, Controller (why?)
  • Utility classes (why?)
  • Mutable Objects (why?)
  • Getters (why?)
  • Objects without state (why?)
  • Long class names

How to use. All you need is this (get the latest version here):

Maven:

<build>
  <plugins>
    <plugin>
      <groupId>ru.l3r8y</groupId>
      <artifactId>oop-cop</artifactId>
      <version>0.2.8</version>
      <executions>
        <execution>
          <goals>
            <goal>search</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

if you want to run plugin directly:

$ mvn ru.l3r8y:oop-cop:search

MutableStateCheck

These classes are valid:

class Pet {
    private final String name;

    public Pet(final String n) {
        this.name = n;
    }
}

This class is invalid:

class Pet {
    private String name;

    public Pet(final String n) {
        this.name = n;
    }

    public void setName(final String name) {
        this.name = name;
    }
}

However, you can suppress this check by adding:

@SupressWarnings("OOP.MutableStateCheck")

ErSuffixCheck

These examples are valid:

class ParsedFile {
  ...
  public String asText() {
      ...
  }   
}

While this is invalid:

class FileParser {
    ...
    public String parse() {
        ...
    }
}

However, you can suppress this check by adding:

@SupressWarnings("OOP.ErSuffixCheck")

Utility classes

TBD..

Getters

TBD..

Objects without state

TBD..

Long class names

This example is valid:

class PgItem {
    ...
}

while this is broken:

class AbstractDatabaseConnection {
    ...
}

to configure the maximal reasonable length consider using the following parameter:

<plugin>
  <groupId>ru.l3r8y</groupId>
  <artifactId>oop-cop</artifactId>
  ...
  <configuration>
    <maxClassNameLen>15</maxClassNameLen>
    <!-- default is 13 -->
  </configuration>
</plugin>

How to Contribute

Fork repository, make changes, 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

You will need Maven 3.8+ and Java 8+.

About

The static analysis tool and a Maven plugin that will help you model your objects, classes, methods properly by rejecting your non-perfect code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published