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
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")
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")
TBD..
TBD..
TBD..
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>
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+.