Skip to content

Lint

Lint

The :tools:lint module statically checks Java/JML sources for specification problems. Every rule is a LintRule visitor over the AST; the facade runs the configured rules and reports LintProblems, optionally as SARIF 2.1.0 for editor/tooling integration (e.g. GitHub code scanning).

Usage

val facade = JmlLintingFacade(JmlLintingConfig())

// collect problems (sorted by source location)
val problems: Collection<LintProblem> = facade.lint(nodes)

// stream them to a reporter as they are found
facade.lint(LintProblemReporter { problem -> ... }, nodes)

// SARIF 2.1.0 document for CI integration
val sarif: SarifSchema = facade.asSarif(problems)

LintProblem carries everything a tool needs:

data class LintProblem(
    val level: String,          // e.g. "WARNING" / "ERROR"
    val message: String,
    val location: TokenRange?,  // source span
    val category: String?,      // e.g. rule family
    val ruleId: String,         // fully-qualified rule name
)

Configuration

data class JmlLintingConfig(
    val checkNameClashes: Boolean,        // JML names vs. Java names (default true)
    val checkMissingNames: Boolean,       // missing declarations (default true)
    val topLevelNullity: DefaultNullity,  // default top-level nullability (NON_NULL)
    val checkJspecifyNullness: Boolean,   // JSpecify annotation interop (default false)
    val checkSpecVisibility: Boolean,     // visibility of specs vs. declarations (default true)
)

Rule catalog

RuleChecks
AllowedJmlClausesclauses not permitted in the current context
AssignableValidatorsyntactic well-formedness of assignable clause elements
AssignableLocsetValidatorlocation sets in assignable clauses
ContextSensitiveForbiddenFunctionsValidator\old/\pre style functions used outside their legal positions
DefaultNullityValidatornullness of parameters/results against the default-nullity policy
ExceptionVarCheckthe signals exception variable binding
FormulaEvaluatorconst-foldable formula sanity
JavaContainsJmlConstructJML constructs leaking into Java positions
JmlDuplicateNamesValidatorduplicated JML declarations (ghost/model fields)
JmlJavaNameClashesa JML name shadowing a Java name
MethodBodyHasNoContractexecutable methods without any specification
OverridingLocalNamesInGhostghost bindings shadowing locals
PurityValidatorside effects inside pure/helper-method specs
ResultVarCheckmisuse of \result
SignalsExceptionTypeChecksignals clause exception types
SpecVisibilityValidatorspecs visible where they are used
TrivialFormulaValidatortautological/contradictory formulas

Status

The library is fully functional and used from tests and the web playground. The jmltk lint CLI subcommand is registered but not yet implemented — for now, drive the rules through JmlLintingFacade or the web interface.