Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Override score, severity, or enable/disable individual rules:

| Rule ID | Default Score | Default Severity |
|---------|--------------|-----------------|
| `non-standard-naming` | -1 | suggestion |
| `non-standard-naming` | -3 | suggestion |
| `non-semantic-name` | -1 | suggestion |
| `inconsistent-naming-convention` | -1 | suggestion |
<!-- RULE_TABLE_END -->
Expand Down
20 changes: 8 additions & 12 deletions src/core/engine/scoring.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { calculateScores, formatScoreSummary, gradeToClassName, getCategoryLabel, getSeverityLabel, buildResultJson } from "./scoring.js";
import { calculateScores, formatScoreSummary, gradeToClassName, getCategoryLabel, getSeverityLabel, buildResultJson, CATEGORY_WEIGHT } from "./scoring.js";
import type { AnalysisIssue, AnalysisResult } from "./rule-engine.js";
import type { AnalysisFile, AnalysisNode } from "../contracts/figma-node.js";
import type { Rule, RuleConfig, RuleViolation } from "../contracts/rule.js";
Expand Down Expand Up @@ -226,17 +226,13 @@ describe("calculateScores", () => {
makeIssue({ ruleId: "no-auto-layout", category: "pixel-critical", severity: "blocking" }),
], 100));

const categoryPercentages = [
scores.byCategory["pixel-critical"].percentage,
scores.byCategory["responsive-critical"].percentage,
scores.byCategory["code-quality"].percentage,
scores.byCategory["token-management"].percentage,
scores.byCategory["interaction"].percentage,
scores.byCategory["minor"].percentage,
];
const expectedOverall = Math.round(
categoryPercentages.reduce((a, b) => a + b, 0) / 6
);
let weightedSum = 0;
let totalWeight = 0;
for (const [cat, w] of Object.entries(CATEGORY_WEIGHT)) {
weightedSum += scores.byCategory[cat as Category].percentage * w;
totalWeight += w;
}
const expectedOverall = Math.round(weightedSum / totalWeight);
expect(scores.overall.percentage).toBe(expectedOverall);
});

Expand Down
24 changes: 14 additions & 10 deletions src/core/engine/scoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,23 @@ function computeTotalScorePerCategory(
}

/**
* Category weights for overall score.
* All equal (1.0) by design — no category is inherently more important than another.
* This avoids subjective bias; individual rule scores within each category already
* encode relative importance. If calibration reveals certain categories correlate
* more strongly with visual-compare similarity, these weights can be adjusted.
* Category weights for overall score, based on ablation experiment data (PR #149, #150).
*
* Evidence:
* - responsive-critical: ΔV +15.9% at expanded viewport, mobile-shop +46% — highest impact
* - pixel-critical: ΔV +5.4% when layout info stripped — direct pixel accuracy impact
* - token-management: ΔV +3.5% (style-ref, Phase 2) — moderate
* - code-quality: ΔV ≈0%, CSS classes -8~15 — affects structure, not pixels
* - interaction: data incomplete (missing-prototype disabled, #139 fixture rebuild pending)
* - minor: ΔV <2%, negligible code difference
*/
const CATEGORY_WEIGHT: Record<Category, number> = {
"pixel-critical": 1.0,
"responsive-critical": 1.0,
export const CATEGORY_WEIGHT: Record<Category, number> = {
"pixel-critical": 2.5,
"responsive-critical": 3.0,
"code-quality": 1.0,
"token-management": 1.0,
"interaction": 1.0,
"minor": 1.0,
"interaction": 0.5,
"minor": 0.3,
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/rules/rule-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ export const RULE_CONFIGS: Record<RuleId, RuleConfig> = {
"missing-prototype": {
severity: "missing-info",
score: -3,
enabled: true,
enabled: false, // disabled: interactionDestinations data missing from fixtures (#139)
},

// ── Minor ──
"non-standard-naming": {
severity: "suggestion",
score: -1,
score: -3, // higher than other naming rules: non-standard state names break interaction detection pipeline
Comment on lines +134 to +140
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove inline calibration rationale comments from auto-managed config.

Line 134 and Line 140 add inline rationale in RULE_CONFIGS. Keep this file comment-free for calibration rationale to avoid churn from nightly auto-adjustments.

Proposed cleanup
   "missing-prototype": {
     severity: "missing-info",
     score: -3,
-    enabled: false, // disabled: interactionDestinations data missing from fixtures (`#139`)
+    enabled: false,
   },
@@
   "non-standard-naming": {
     severity: "suggestion",
-    score: -3, // higher than other naming rules: non-standard state names break interaction detection pipeline
+    score: -3,
     enabled: true,
   },

Based on learnings: In let-sunny/canicode, src/core/rules/rule-config.ts is auto-adjusted by a nightly calibration pipeline, and inline calibration rationale should not be added there.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/rules/rule-config.ts` around lines 134 - 140, Remove inline
calibration rationale comments from the auto-managed RULE_CONFIGS object: delete
the comment after the enabled property (the "// disabled:
interactionDestinations data missing from fixtures (`#139`)") and the comment
after the score for "non-standard-naming" (and any similar rationale comments in
RULE_CONFIGS). Keep the configuration values unchanged, and ensure no other
inline calibration rationale comments remain in the RULE_CONFIGS declaration
(move any rationale to external docs if needed).

enabled: true,
},
"non-semantic-name": {
Expand Down
Loading