refactor(core): drive metrics from a Metric registry - #40
Merged
Merged
Conversation
The seven metric names were listed by hand in config validation, limit resolution, violation emission, and baseline lookup, so a missed entry compiled fine and silently dropped the metric. A Metric enum now holds the list, names, and applicability, and exhaustive accessors make a new variant fail to compile until every path handles it. Output and config are unchanged.
ALL is the one list an exhaustive match cannot check. The test compares it with the serialized keys of Limits, MetricValues, and FunctionMetrics, so a metric field added without an ALL entry fails instead of being skipped.
3 tasks done
add_violations read raw language limits and applied only the test-file exemption, so a restricted metric with a nonzero value on an excluded unit would fail while --base reported its limit as null. It now uses effective_limits, the same path as --base. baseline::status takes a Metric, and the golden projection destructures FunctionMetrics so a new metric field cannot go unchecked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #39
The seven metric names were listed by hand in config key validation,
limits_for,effective_limits,add_violations, andMetricValues, so a missed entry compiled fine and silently dropped the metric. AMetricenum incrates/core/src/metric.rsnow holds the list, the names, and applicability:linesandparamsskip Svelte template units, andwidget_depthcovers only Dartbuildmethods. Every accessor matches onMetricwithout a wildcard, so a new variant fails to compile until each path handles it.ALLis the one list a match cannot check, so a test ties it to the serialized keys ofLimits,MetricValues, andFunctionMetrics.The struct fields and serde attributes are unchanged, so JSON output, config shape, error messages, and exit codes are the same.
pickcheck-coregainsMetricandget/valueaccessors as additive public items. The crate is not published and only the CLI in this workspace uses it.The issue originally said to wait for a second language-specific metric. The maintainer overrode that on 2026-09-30.
Metricaccepted as a key inlimitsandlanguages.rust.limits; unknownlimits.bogusandlanguages.go.limits.widgetdepthstill rejectedevery_metric_round_trips_through_config_limits_and_values; QAbadkey,badlangkeybuildunits against every metricapplicability_follows_template_and_widget_units--basewith new/worsened/unchanged statuses,--changedWidgetDepthfromALLfailsall_covers_every_metric_fieldandnames_match_the_default_config_limits--baselimitslines,params,widget_depthemits nothing; ordinary unit emitslinesandparams; test file with defaultexempt: ["lines"]emits onlyparams. Reverting either path fails the testviolations_skip_metrics_that_do_not_apply_to_the_unitExpected::fromdestructuresFunctionMetricswithout..crates/core/tests/golden.rscargo test, QA belowcargo test --workspace --locked --all-targets,cargo clippy ... -D warnings,cargo fmt --check,cargo llvm-cov --fail-under-lines 94(94.60%),pickcheck check --base origin/main --fail-on new,worsened,unmatched(35 checked, 0 violations), all on 20bf65fQA: a CLI pass compared
pickcheck0.4.0 built from main at 99a0826 with this branch, over a scratch Git repo holding a copy oftests/fixtures. Scenarios were plain and JSON checks, a.pickcheck.jsonwith global and per-language overrides includingnullandtests.exempt, three invalid configs,--basetext and JSON with default and custom limits (30 new, 8 worsened, 1 unchanged), and--changed. All outputs, stderr, and exit codes matched byte for byte. The comparison was rerun on e14f76d after the review fix, adding a config withparamsandwidget_depthlimits of 0, and again matched in 14 of 14 scenarios. 20bf65f changes only a test. The evidence stays local and outside the repo.Review: independent xhigh reviews by Astra (Lanes) and Fable at 27b6a95 found no regression for the seven current metrics. Both flagged that
add_violationsbypassedMetric::applies_toand that the golden projection could skip a new metric. Fable also noted thatbaseline::statusre-parsed the metric name. e14f76d fixes all three. Fable's recheck added a nit about direct coverage of the test-file exemption, fixed in 20bf65f. Both reviewers confirmed every finding resolved.Follow-up found during QA: #41, a pre-existing misleading error path for per-language config keys.