mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
* feat(ui): add eslint rules for nested ternaries, large inline object args, and long condition chains Adds three dashboard lint rules to keep new code readable. Nested ternaries are banned outright via the built-in no-nested-ternary, with the 265 existing occurrences grandfathered in eslint-suppressions.json so only new ones fail. Two custom rules ship as a small local plugin under scripts/eslint-rules: no-large-inline-object-arg flags object literals with 4+ properties passed straight into a call, nudging toward a named variable, and no-long-condition-chain flags boolean expressions that combine 4+ conditions, nudging toward a named boolean. Both are warnings tracked on the existing budget ratchet (eslint-budgets.json + eslint-metrics.json) with headroom above the current counts, so they ratchet down over time rather than freezing a baseline. Both thresholds are configurable rule options and covered by RuleTester unit tests. * fix(ui): scope no-long-condition-chain to boolean operators, not nullish Greptile flagged that the rule counted nullish-coalescing chains the same as &&/|| chains, so a 4-part `a ?? b ?? c ?? d` fallback surfaced "Boolean expression combines 4 conditions", which is inaccurate since a `??` fallback is value defaulting, not a condition. Restrict the visitor to && / || nodes so `??` chains are treated as leaves, while a boolean chain nested inside a `??` is still caught. Drops 6 miscounted occurrences (240 -> 234). * chore(ui): sync lint metrics and suppressions with staging Merge advanced the base branch, adding one no-large-inline-object-arg occurrence (508 -> 509) and making one grandfathered react-hooks suppression stale. Regenerate eslint-metrics.json and prune the suppression so the budget/drift gate passes. * chore(ui): sync lint metrics with staging Merge advanced the base, adding four no-large-inline-object-arg occurrences (509 -> 513). Regenerate eslint-metrics.json so the drift gate passes.
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const DEFAULT_MIN_PROPERTIES = 4;
|
|
|
|
const isArgumentOf = (node) => {
|
|
const parent = node.parent;
|
|
if (parent == null) return false;
|
|
if (parent.type !== "CallExpression" && parent.type !== "NewExpression") return false;
|
|
return parent.arguments.includes(node);
|
|
};
|
|
|
|
const rule = {
|
|
meta: {
|
|
type: "suggestion",
|
|
docs: {
|
|
description:
|
|
"Disallow passing a large object literal inline as a call argument; assign it to a named variable first.",
|
|
},
|
|
schema: [
|
|
{
|
|
type: "object",
|
|
properties: { minProperties: { type: "integer", minimum: 1 } },
|
|
additionalProperties: false,
|
|
},
|
|
],
|
|
messages: {
|
|
tooLarge:
|
|
"Object literal with {{count}} properties passed inline as an argument; assign it to a named variable first.",
|
|
},
|
|
},
|
|
create(context) {
|
|
const minProperties = context.options[0]?.minProperties ?? DEFAULT_MIN_PROPERTIES;
|
|
return {
|
|
ObjectExpression(node) {
|
|
if (!isArgumentOf(node)) return;
|
|
if (node.properties.length < minProperties) return;
|
|
context.report({ node, messageId: "tooLarge", data: { count: node.properties.length } });
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export default rule;
|