Skip to content

Commit 453b378

Browse files
committed
chore(ci): enable max params lint rule
Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent f62bb11 commit 453b378

14 files changed

Lines changed: 182 additions & 189 deletions

File tree

projects/core/src/internal/controllers/keynav-grid.controller.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ function getGridDelta(code: KeynavCode | string, dir: string): { dx: number; dy:
165165

166166
function applyGridHomeEnd(
167167
code: KeynavCode | string,
168-
x: number,
169-
y: number,
170-
columnCount: number,
171-
rowCount: number,
172-
ctrlKey: boolean
168+
position: { x: number; y: number },
169+
bounds: { columnCount: number; rowCount: number; ctrlKey: boolean }
173170
) {
171+
const { x, y } = position;
172+
const { columnCount, rowCount, ctrlKey } = bounds;
174173
if (code === KeynavCode.End) {
175174
return { x: columnCount, y: ctrlKey ? rowCount : y };
176175
}
@@ -201,7 +200,7 @@ export function getNextKeyGridItem(
201200
x = Math.max(0, Math.min(columnCount, x + delta.dx));
202201
y = Math.max(0, Math.min(rowCount, y + delta.dy));
203202
} else {
204-
({ x, y } = applyGridHomeEnd(config.code, x, y, columnCount, rowCount, config.ctrlKey));
203+
({ x, y } = applyGridHomeEnd(config.code, { x, y }, { columnCount, rowCount, ctrlKey: config.ctrlKey }));
205204
}
206205

207206
return { x, y };

projects/core/src/internal/controllers/keynav-list.controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ function resolveSpecialKey(code: KeynavCode): 'home' | 'end' | 'pageup' | 'paged
149149
return null;
150150
}
151151

152-
function navigateWithLoop(current: number, limit: number, step: number, loop: boolean | undefined) {
152+
function navigateWithLoop(current: number, step: number, options: { limit: number; loop: boolean | undefined }) {
153+
const { limit, loop } = options;
153154
const next = current + step;
154155
if (next >= 0 && next <= limit) return next;
155156
return loop ? (step < 0 ? limit : 0) : current;
@@ -163,10 +164,10 @@ export function getNextKeyListItem(item: HTMLElement, items: HTMLElement[], conf
163164

164165
switch (direction ?? resolveSpecialKey(config.code)) {
165166
case 'backward':
166-
next = navigateWithLoop(next, itemCount, -1, config.loop);
167+
next = navigateWithLoop(next, -1, { limit: itemCount, loop: config.loop });
167168
break;
168169
case 'forward':
169-
next = navigateWithLoop(next, itemCount, 1, config.loop);
170+
next = navigateWithLoop(next, 1, { limit: itemCount, loop: config.loop });
170171
break;
171172
case 'end':
172173
next = itemCount;

projects/core/src/sparkline/sparkline.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,19 @@ export class Sparkline extends LitElement implements DataElement<number[]> {
154154
}
155155

156156
#renderLineVariant(width: number, height: number) {
157-
const domain = calculateDomain(this.validData, this.min, this.max);
157+
const domain = calculateDomain(this.validData, { explicitMin: this.min, explicitMax: this.max });
158158
if (!domain) return nothing;
159159

160-
const baselineY = valueToY(0, domain.min, domain.max);
160+
const baselineY = valueToY(0, domain);
161161
const drawZeroLine = domain.min < 0 && domain.max > 0;
162162

163-
const plotPoints = toPlotPoints(this.validData, domain.min, domain.max, width);
164-
const symbolIndices = calculateSymbolIndices(
165-
this.validData,
166-
this.denoteFirst,
167-
this.denoteLast,
168-
this.denoteMin,
169-
this.denoteMax
170-
);
163+
const plotPoints = toPlotPoints(this.validData, domain, { width });
164+
const symbolIndices = calculateSymbolIndices(this.validData, {
165+
first: this.denoteFirst,
166+
last: this.denoteLast,
167+
min: this.denoteMin,
168+
max: this.denoteMax
169+
});
171170
const interpolation = toInterpolation(this.interpolation);
172171

173172
const linePath = toLinePath(plotPoints, interpolation, width);
@@ -235,12 +234,16 @@ export class Sparkline extends LitElement implements DataElement<number[]> {
235234
}
236235

237236
#renderColumn(width: number, height: number) {
238-
const domain = calculateDomain(this.validData, this.min, this.max, true);
237+
const domain = calculateDomain(this.validData, {
238+
explicitMin: this.min,
239+
explicitMax: this.max,
240+
includeZero: true
241+
});
239242
if (!domain) return nothing;
240243

241-
const baselineY = valueToY(0, domain.min, domain.max);
244+
const baselineY = valueToY(0, domain);
242245
const showZeroLine = domain.min < 0 && domain.max > 0;
243-
const plotPoints = toPlotPoints(this.validData, domain.min, domain.max, width);
246+
const plotPoints = toPlotPoints(this.validData, domain, { width });
244247
const rects = toColumnRects(plotPoints, baselineY, width);
245248

246249
return svg`
@@ -257,7 +260,7 @@ export class Sparkline extends LitElement implements DataElement<number[]> {
257260
#renderWinLoss(baselineY: number, width: number, height: number) {
258261
if (this.validData.length === 0) return nothing;
259262

260-
const rects = toWinLossRects(this.validData, baselineY, width, height);
263+
const rects = toWinLossRects(this.validData, baselineY, { width, height });
261264

262265
return svg`
263266
<svg viewBox="0 0 ${width} ${height}" preserveAspectRatio="xMidYMid meet" aria-hidden="true">

projects/core/src/sparkline/sparkline.utils.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ describe('sparkline.utils', () => {
4747
});
4848

4949
it('includes zero in the domain when includeZero is true', () => {
50-
expect(calculateDomain([10, 20, 15], undefined, undefined, true)).toEqual({ min: 0, max: 20 });
50+
expect(calculateDomain([10, 20, 15], { includeZero: true })).toEqual({ min: 0, max: 20 });
5151
});
5252

5353
it('returns the observed range when data includes negatives', () => {
5454
expect(calculateDomain([5, -3, 2])).toEqual({ min: -3, max: 5 });
5555
});
5656

5757
it('uses explicit min/max overrides even when data exceeds those bounds', () => {
58-
expect(calculateDomain([-100, 50, 200], -10, 10)).toEqual({ min: -10, max: 10 });
59-
expect(calculateDomain([5, -3, 2], -10, undefined)).toEqual({ min: -10, max: 5 });
60-
expect(calculateDomain([5, -3, 2], undefined, 10)).toEqual({ min: -3, max: 10 });
58+
expect(calculateDomain([-100, 50, 200], { explicitMin: -10, explicitMax: 10 })).toEqual({ min: -10, max: 10 });
59+
expect(calculateDomain([5, -3, 2], { explicitMin: -10 })).toEqual({ min: -10, max: 5 });
60+
expect(calculateDomain([5, -3, 2], { explicitMax: 10 })).toEqual({ min: -3, max: 10 });
6161
});
6262
});
6363

6464
describe('plot and symbol helpers', () => {
6565
it('maps values to plot points and handles zero-range values', () => {
66-
const points = toPlotPoints([5, 5], 5, 5, 120);
66+
const points = toPlotPoints([5, 5], { min: 5, max: 5 }, { width: 120 });
6767
expect(points).toEqual([
6868
{ x: 0, y: 50 },
6969
{ x: 120, y: 50 }
7070
]);
71-
expect(valueToY(5, 5, 5)).toBe(50);
71+
expect(valueToY(5, { min: 5, max: 5 })).toBe(50);
7272
});
7373

7474
it('resolves symbol indices for all boolean flag permutations', () => {
@@ -93,14 +93,14 @@ describe('sparkline.utils', () => {
9393
] as const;
9494

9595
for (const { flags, expected } of cases) {
96-
const [denoteFirst, denoteLast, denoteMin, denoteMax] = flags;
97-
const actual = Array.from(calculateSymbolIndices(values, denoteFirst, denoteLast, denoteMin, denoteMax));
96+
const [first, last, min, max] = flags;
97+
const actual = Array.from(calculateSymbolIndices(values, { first, last, min, max }));
9898
expect(actual).toEqual(expected);
9999
}
100100
});
101101

102102
it('returns no symbol indices for empty values', () => {
103-
expect(Array.from(calculateSymbolIndices([], true, true, true, true))).toEqual([]);
103+
expect(Array.from(calculateSymbolIndices([], { first: true, last: true, min: true, max: true }))).toEqual([]);
104104
});
105105
});
106106

@@ -183,7 +183,7 @@ describe('sparkline.utils', () => {
183183

184184
describe('winloss rect builders', () => {
185185
it('builds winloss rects with expected class and geometry', () => {
186-
const winlossRects = toWinLossRects([1, 0, -1], 50, 180, 100);
186+
const winlossRects = toWinLossRects([1, 0, -1], 50, { width: 180, height: 100 });
187187
expect(winlossRects).toEqual([
188188
{ className: 'win', x: 4.5, y: 0, width: 51, height: 50 },
189189
{ className: 'draw', x: 64.5, y: 37.5, width: 51, height: 25 },
@@ -192,12 +192,12 @@ describe('sparkline.utils', () => {
192192
});
193193

194194
it('centers a single winloss bar with the expected width', () => {
195-
const [winlossRect] = toWinLossRects([1], 50, 60, 100);
195+
const [winlossRect] = toWinLossRects([1], 50, { width: 60, height: 100 });
196196
expect(winlossRect).toEqual({ className: 'win', x: 4.5, y: 0, width: 51, height: 50 });
197197
});
198198

199199
it('returns no rects for empty winloss inputs', () => {
200-
expect(toWinLossRects([], 50, 120, 100)).toEqual([]);
200+
expect(toWinLossRects([], 50, { width: 120, height: 100 })).toEqual([]);
201201
});
202202
});
203203
});

projects/core/src/sparkline/sparkline.utils.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ export function calculateViewBox(
3636

3737
export function calculateDomain(
3838
values: number[],
39-
explicitMin?: number,
40-
explicitMax?: number,
41-
includeZero = false
39+
options: { explicitMin?: number; explicitMax?: number; includeZero?: boolean } = {}
4240
): Scale | undefined {
4341
if (values.length === 0) return undefined;
42+
const { explicitMin, explicitMax, includeZero = false } = options;
4443

4544
const dataMinimum = Math.min(...values);
4645
const dataMaximum = Math.max(...values);
@@ -51,48 +50,44 @@ export function calculateDomain(
5150
};
5251
}
5352

54-
export function valueToY(value: number, min: number, max: number, viewHeight = VIEW_HEIGHT): number {
55-
const range = max - min;
56-
if (range === 0) return viewHeight / 2;
57-
return viewHeight - ((value - min) / range) * viewHeight;
53+
export function valueToY(value: number, range: { min: number; max: number }, viewHeight = VIEW_HEIGHT): number {
54+
const span = range.max - range.min;
55+
if (span === 0) return viewHeight / 2;
56+
return viewHeight - ((value - range.min) / span) * viewHeight;
5857
}
5958

6059
export function toPlotPoints(
6160
values: number[],
62-
min: number,
63-
max: number,
64-
viewWidth: number,
65-
viewHeight = VIEW_HEIGHT
61+
range: { min: number; max: number },
62+
view: { width: number; height?: number }
6663
): Point[] {
67-
const stepX = values.length > 1 ? viewWidth / (values.length - 1) : 0;
64+
const viewHeight = view.height ?? VIEW_HEIGHT;
65+
const stepX = values.length > 1 ? view.width / (values.length - 1) : 0;
6866
return values.map((value, index) => ({
6967
x: index * stepX,
70-
y: valueToY(value, min, max, viewHeight)
68+
y: valueToY(value, range, viewHeight)
7169
}));
7270
}
7371

7472
export function calculateSymbolIndices(
7573
values: number[],
76-
denoteFirst: boolean,
77-
denoteLast: boolean,
78-
denoteMin: boolean,
79-
denoteMax: boolean
74+
denote: { first: boolean; last: boolean; min: boolean; max: boolean }
8075
): Set<number> {
8176
const indices = new Set<number>();
8277
if (values.length === 0) return indices;
8378

84-
if (denoteFirst) indices.add(0);
85-
if (denoteLast) indices.add(values.length - 1);
79+
if (denote.first) indices.add(0);
80+
if (denote.last) indices.add(values.length - 1);
8681

87-
const needsExtrema = denoteMin || denoteMax;
82+
const needsExtrema = denote.min || denote.max;
8883
if (!needsExtrema) return indices;
8984

9085
const min = Math.min(...values);
9186
const max = Math.max(...values);
9287

9388
values.forEach((value, index) => {
94-
if (denoteMin && value === min) indices.add(index);
95-
if (denoteMax && value === max) indices.add(index);
89+
if (denote.min && value === min) indices.add(index);
90+
if (denote.max && value === max) indices.add(index);
9691
});
9792

9893
return indices;
@@ -174,11 +169,14 @@ export function toColumnRects(points: Point[], baselineY: number, width: number)
174169
export function toWinLossRects(
175170
values: number[],
176171
baselineY: number,
177-
width: number,
178-
height: number
172+
dimensions: { width: number; height: number }
179173
): (Rect & { className: 'win' | 'loss' | 'draw' })[] {
180-
const { bandSize: bandWidth, stepSize: stepX } = calculateBandSizing(values.length, width, WINLOSS_GAP_RATIO);
181-
const barHeight = height / 2;
174+
const { bandSize: bandWidth, stepSize: stepX } = calculateBandSizing(
175+
values.length,
176+
dimensions.width,
177+
WINLOSS_GAP_RATIO
178+
);
179+
const barHeight = dimensions.height / 2;
182180

183181
return values.map((value, index) => {
184182
const x = index * stepX + (stepX - bandWidth) / 2;

projects/core/src/tabs/tabs-group.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class TabsGroup extends LitElement {
164164
return;
165165
}
166166

167-
this.#setActiveTab(tabItems, tabItem, true);
167+
this.#setActiveTab(tabItems, tabItem, { emitEvent: true });
168168
};
169169

170170
// --- Tab strip sync (tabs → state) ---
@@ -198,7 +198,7 @@ export class TabsGroup extends LitElement {
198198
return;
199199
}
200200

201-
this.#setActiveTab(tabItems, selectedTab, false, nextPanelValues);
201+
this.#setActiveTab(tabItems, selectedTab, { emitEvent: false, nextPanelValues });
202202
}
203203

204204
/**
@@ -209,9 +209,10 @@ export class TabsGroup extends LitElement {
209209
#setActiveTab(
210210
tabItems: TabsItem[],
211211
nextTab: TabsItem,
212-
emitEvent: boolean,
213-
nextPanelValues: string[] = uniqueNonEmptyStrings(tabItems.map(item => item.value))
212+
options: { emitEvent: boolean; nextPanelValues?: string[] }
214213
): void {
214+
const { emitEvent } = options;
215+
const nextPanelValues = options.nextPanelValues ?? uniqueNonEmptyStrings(tabItems.map(item => item.value));
215216
// True when the effective selection differs from the prior committed state (value, flags, or multi-select).
216217
// `select` is only dispatched when both `emitEvent` (invoker/command path) and `changed` are true.
217218
const changed =

projects/forms/src/internal/schema.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import type { Schema } from './types.js';
55
import { FormControlError } from './errors.js';
66

7-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- caller specifies T for typed return
87
export function parseValueSchema<T>(formControlName: string, value: string, schema: Schema): T {
98
const parsedValue = parseControlValue(value, schema);
109
if (parsedValue === undefined) {
@@ -89,15 +88,15 @@ function validateArray(schema: Schema & { type: 'array' }, value: unknown): Vali
8988
}
9089

9190
function validateObjectProperty(
92-
prop: string,
93-
propSchema: Schema,
91+
property: { name: string; schema: Schema },
9492
value: Record<string, unknown>,
9593
required?: string[]
9694
): ValidationResult {
97-
const propValue = value[prop];
95+
const { name, schema: propSchema } = property;
96+
const propValue = value[name];
9897
if (propValue === undefined) {
99-
if (required?.includes(prop)) {
100-
return invalid({ valueMissing: true }, `missing required property: ${prop}`);
98+
if (required?.includes(name)) {
99+
return invalid({ valueMissing: true }, `missing required property: ${name}`);
101100
}
102101
return VALID;
103102
}
@@ -118,7 +117,11 @@ function validateObject(schema: Schema & { type: 'object' }, value: unknown): Va
118117
}
119118

120119
for (const [prop, propSchema] of Object.entries(schema.properties)) {
121-
const result = validateObjectProperty(prop, propSchema, value as Record<string, unknown>, schema.required);
120+
const result = validateObjectProperty(
121+
{ name: prop, schema: propSchema },
122+
value as Record<string, unknown>,
123+
schema.required
124+
);
122125
if (!result.validity.valid) {
123126
return result;
124127
}
@@ -160,7 +163,6 @@ export function validateSchema(schema: Schema, value: unknown): ValidationResult
160163
}
161164
}
162165

163-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- caller specifies T for typed return
164166
export function parseControlValue<T>(value: string, schema: Schema): T | undefined {
165167
const schemaType = schema.type;
166168
let parsedValue: unknown;

projects/internals/eslint/src/configs/typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const config = {
8282
'no-warning-comments': 'error',
8383
'no-shadow': ['error', { allow: ['_', 'args', 'resolve', 'cwd'] }], // globals and a few large refactors
8484
'no-restricted-imports': ['error', { patterns: ['**/dist/**', '**/node_modules/**'] }],
85+
'max-params': ['error', 3],
8586
'max-lines': ['error', 1000],
8687
'max-lines-per-function': ['error', 50],
8788
'max-statements-per-line': ['error', { max: 1 }],
@@ -134,7 +135,6 @@ const config = {
134135
'@typescript-eslint/prefer-readonly': 'off',
135136
'@typescript-eslint/explicit-function-return-type': 'off',
136137
'id-length': ['off', { min: 2, exceptions: ['_'] }],
137-
'max-params': ['error', 6], // goal 3
138138
'max-statements': ['error', 20], // goal 15
139139
'max-depth': ['off', 3],
140140
'max-nested-callbacks': ['off', 3]

0 commit comments

Comments
 (0)