public final class PrettyScore extends Object
ScoreProfile and explains every deduction.
ScoreReport r = new PrettyScore().score(formattedSql, EDbVendor.dbvmssql, ScoreProfile.defaults(), originalSql, null); r.getScore(); // 0-100 r.getAttainable(); // what the formatter could reach on this input r.getRatio(); // score / attainable — the closed-loop target r.toJson(); // published contract, version "prettyscore/0.1"
Read this before quoting a number. While the profile's
calibration is heuristic-v0 the weights are engineering guesses:
the score is reliable only as a relative measure within one profile on one
corpus (before/after a formatter change). It is not an absolute readability
verdict and must not be presented as one.
Syntax errors are fine: the lexical facts come from the pp2 pipeline, which never needs a successful parse; only the AST depth is lost, in which case the indent dimension's weight is halved and a note is attached.
Thread-safety: the only configuration is setAstEnabled(boolean), read
once at the start of every score call; instances may be shared.
| Constructor and Description |
|---|
PrettyScore() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isAstEnabled() |
ScoreReport |
score(String sql,
EDbVendor vendor)
Score
sql with the default profile and no fidelity gate. |
ScoreReport |
score(String sql,
EDbVendor vendor,
ScoreProfile profile,
String original,
Map<String,Object> options) |
PrettyScore |
setAstEnabled(boolean enabled)
Whether a second GSP parse is run to stamp AST depth (default true).
|
static String |
targetFor(String rule)
The formatter option / renderer component a rule id maps to (see the improvement list).
|
public PrettyScore()
public PrettyScore setAstEnabled(boolean enabled)
public boolean isAstEnabled()
public ScoreReport score(String sql, EDbVendor vendor)
sql with the default profile and no fidelity gate.public ScoreReport score(String sql, EDbVendor vendor, ScoreProfile profile, String original, Map<String,Object> options)
sql - the formatted SQL; must not be nullvendor - dialect; must not be nullprofile - style profile; null selects isf-defaultoriginal - the un-formatted input; when given the fidelity gate
(token / comment / AST preservation) and the comments
dimension are evaluatedoptions - the formatter options the caller claims produced
sql (GFmtOpt field names); when given,
contradictions surface as OPTION_NOT_HONORED