Nope'n! Error Prone Checker

repository·master·Indexed 43 days ago

https://github.com/jakewharton/nopen

An Error Prone checker that enforces explicit inheritance intent by requiring classes to be marked as final, abstract, or annotated with @Open.

Tokens
777
Snippets
4
Records
5
Agent score
6%

What's inside Nope'n!

  1. What is Nope'n!

    master
    Nope'n! is an Error Prone checker designed to enforce explicit inheritance intent. It requires that all classes be explicitly marked as final, abstract, or annotated with @Open. This helps prevent the accidental creation of open classes, following the principle from Effective Java (Item 19) to design and document for inheritance or prohibit it.
  2. How to use Nope'n! annotations and rules

    master

    To satisfy the checker, a class must meet one of three criteria:

    1. Be declared final.
    2. Be declared abstract.
    3. Be annotated with @Open from the com.jakewharton.nopen.annotation package.

    Any class that is neither final nor abstract and lacks the @Open annotation will trigger an error: [Nopen] Classes should be explicitly marked final, abstract, or @Open.

    import com.jakewharton.nopen.annotation.Open;
    
    final class Foo {}          // Valid
    abstract class Bar {}      // Valid
    @Open class Baz {}         // Valid
    
    class Bad {}               // Error: [Nopen] Classes should be explicitly marked final, abstract, or @Open
  3. Disable Nope'n! check for tests in Java projects

    master

    If you want to disable the Nopen check specifically for test compilation in a standard Java project, configure the compileTestJava task to set the severity to OFF.

    import net.ltgt.gradle.errorprone.CheckSeverity
    
    tasks.named("compileTestJava").configure {
      options.errorprone.check("Nopen", CheckSeverity.OFF)
    }
  4. Disable Nope'n! check for tests in Android projects

    master

    In Android projects, you can disable the Nopen check for both testVariants and unitTestVariants by configuring their javaCompileProvider.

    import net.ltgt.gradle.errorprone.CheckSeverity
    
    android.testVariants.all { variant ->
      variant.javaCompileProvider.configure {
        options.errorprone.check("Nopen", CheckSeverity.OFF)
      }
    }
    android.unitTestVariants.all { variant ->
      variant.javaCompileProvider.configure {
        options.errorprone.check("Nopen", CheckSeverity.OFF)
      }
    }
  5. Install Nope'n! via Gradle

    master

    To use Nope'n!, add the annotations to your compileOnly configuration and the checker to your errorprone configuration using the net.ltgt.errorprone plugin.

    dependencies {
      compileOnly 'com.jakewharton.nopen:nopen-annotations:1.0.1'
      errorprone 'com.jakewharton.nopen:nopen-checker:1.0.1'
    }