Skip to content

Commit 9b5509f

Browse files
committed
chore(ci): lint cleanup
- max-nested-callbacks - max-statements - max-depth Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent 3de7ab9 commit 9b5509f

21 files changed

Lines changed: 348 additions & 246 deletions

File tree

patches/monaco-editor.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,4 +1166,4 @@ index 414405319ded9b3671a070b7405b7150afaa8321..c8b924d17e513acb02b8f8a74b75d8a7
11661166
+ const element = this.domNode.getRootNode().querySelector(`#${this._list.getElementID(index)}`);
11671167
if (element) {
11681168
element.style.width = 'auto';
1169-
const width = element.getBoundingClientRect().width;
1169+
const width = element.getBoundingClientRect().width;

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import globalStyles from './button-group.global.css?inline';
2121

2222
/**
2323
* @element nve-button-group
24-
* @description A button group is a control that enables users to choose between two or more distinct mutually exclusive options.
24+
* @description A button group organizes related buttons and can support either mutually exclusive single or multi selection. Prefer usage within toolbars.
2525
* @since 0.16.0
2626
* @entrypoint \@nvidia-elements/core/button-group
2727
* @slot - default slot for `nve-button` or `nve-icon-button`

projects/core/src/format-relative-time/format-relative-time.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ import styles from './format-relative-time.css?inline';
88

99
type TimeUnitOption = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
1010

11+
const UNIT_DIVISORS: Record<TimeUnitOption, number> = {
12+
second: 1000,
13+
minute: 60000,
14+
hour: 3600000,
15+
day: 86400000,
16+
week: 604800000,
17+
month: 2592000000,
18+
year: 31536000000
19+
};
20+
21+
const THRESHOLDS: { unit: TimeUnitOption; max: number }[] = [
22+
{ unit: 'second', max: 60 },
23+
{ unit: 'minute', max: 60 },
24+
{ unit: 'hour', max: 24 },
25+
{ unit: 'day', max: 7 },
26+
{ unit: 'week', max: 4 },
27+
{ unit: 'month', max: 12 },
28+
{ unit: 'year', max: Number.POSITIVE_INFINITY }
29+
];
30+
1131
/**
1232
* @element nve-format-relative-time
1333
* @description Formats a date/time value as localized relative text using the Intl.RelativeTimeFormat API. Renders inside a semantic time element.
@@ -71,34 +91,22 @@ export class FormatRelativeTime extends LitElement {
7191
const absDiff = Math.abs(diffMs);
7292
const sign = diffMs < 0 ? -1 : 1;
7393

74-
const seconds = Math.round(absDiff / 1000);
75-
const minutes = Math.round(absDiff / 60000);
76-
const hours = Math.round(absDiff / 3600000);
77-
const days = Math.round(absDiff / 86400000);
78-
const weeks = Math.round(absDiff / 604800000);
79-
const months = Math.round(absDiff / 2592000000);
80-
const years = Math.round(absDiff / 31536000000);
81-
82-
if (seconds < 60) return { value: sign * seconds, unit: 'second' };
83-
if (minutes < 60) return { value: sign * minutes, unit: 'minute' };
84-
if (hours < 24) return { value: sign * hours, unit: 'hour' };
85-
if (days < 7) return { value: sign * days, unit: 'day' };
86-
if (weeks < 4) return { value: sign * weeks, unit: 'week' };
87-
if (months < 12) return { value: sign * months, unit: 'month' };
88-
return { value: sign * years, unit: 'year' };
94+
for (const { unit, max } of THRESHOLDS) {
95+
const value = Math.round(absDiff / UNIT_DIVISORS[unit]);
96+
if (value < max) return { value: sign * value, unit };
97+
}
98+
throw new Error('format-relative-time: no relative time threshold matched');
8999
}
90100

91101
#computeExplicitUnit(diffMs: number, unit: TimeUnitOption): number {
92-
const divisors: Record<string, number> = {
93-
second: 1000,
94-
minute: 60000,
95-
hour: 3600000,
96-
day: 86400000,
97-
week: 604800000,
98-
month: 2592000000,
99-
year: 31536000000
100-
};
101-
return Math.round(diffMs / (divisors[unit] ?? 1));
102+
return Math.round(diffMs / UNIT_DIVISORS[unit]);
103+
}
104+
105+
#resolveValueAndUnit(diffMs: number): { value: number; unit: Intl.RelativeTimeFormatUnit } {
106+
if (this.unit === 'auto') {
107+
return this.#computeUnit(diffMs);
108+
}
109+
return { unit: this.unit, value: this.#computeExplicitUnit(diffMs, this.unit) };
102110
}
103111

104112
get #formattedRelativeTime(): string {
@@ -111,16 +119,7 @@ export class FormatRelativeTime extends LitElement {
111119
return iso;
112120
}
113121

114-
const diffMs = target.getTime() - Date.now();
115-
let value: number;
116-
let resolvedUnit: Intl.RelativeTimeFormatUnit;
117-
118-
if (this.unit === 'auto') {
119-
({ value, unit: resolvedUnit } = this.#computeUnit(diffMs));
120-
} else {
121-
resolvedUnit = this.unit;
122-
value = this.#computeExplicitUnit(diffMs, resolvedUnit);
123-
}
122+
const { value, unit: resolvedUnit } = this.#resolveValueAndUnit(target.getTime() - Date.now());
124123

125124
try {
126125
return new Intl.RelativeTimeFormat(this.#resolvedLocale, {

projects/core/src/forms/validation.examples.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ export const ResetForm = {
158158
}
159159
}
160160

161-
/* eslint-disable @nvidia-elements/lint/no-missing-popover-trigger */
162-
163161
@customElement('app-login')
164162
export class AppLogin extends LitElement {
165163
static styles = [unsafeCSS(layout)];

projects/core/src/internal/utils/objects.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,26 @@ export function deepMerge(
2525

2626
if (isObjectLiteral(target) && isObjectLiteral(source)) {
2727
for (const key in source) {
28-
if (isObjectLiteral(source[key])) {
29-
if (isObjectLiteral(target[key])) {
30-
deepMerge(target[key], source[key]);
31-
} else {
32-
target[key] = source[key];
33-
}
34-
} else {
35-
Object.assign(target, { [key]: source[key] });
36-
}
28+
mergeProperty(target, source, key);
3729
}
3830
}
3931

4032
return deepMerge(target, ...sources);
4133
}
4234

35+
function mergeProperty(target: Record<string, unknown>, source: Record<string, unknown>, key: string) {
36+
const sourceValue = source[key];
37+
if (!isObjectLiteral(sourceValue)) {
38+
target[key] = sourceValue;
39+
return;
40+
}
41+
if (isObjectLiteral(target[key])) {
42+
deepMerge(target[key], sourceValue);
43+
} else {
44+
target[key] = sourceValue;
45+
}
46+
}
47+
4348
export function parseVersion(version: string) {
4449
const [major, minor, patch] = version.split('.').map(v => {
4550
const n = parseInt(v, 10);

projects/core/src/tooltip/tooltip.test.lighthouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ describe('tooltip lighthouse report', () => {
1717
expect(report.scores.performance).toBe(100);
1818
expect(report.scores.accessibility).toBe(100);
1919
expect(report.scores.bestPractices).toBe(100);
20-
expect(report.payload.javascript.kb).toBeLessThan(14.4);
20+
expect(report.payload.javascript.kb).toBeLessThan(14.6);
2121
});
2222
});

projects/forms/src/internal/schema.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,37 +165,22 @@ export function validateSchema(schema: Schema, value: unknown): ValidationResult
165165

166166
export function parseControlValue<T>(value: string, schema: Schema): T | undefined {
167167
const schemaType = schema.type;
168-
let parsedValue: unknown;
169168

170169
switch (schemaType) {
171-
case 'string': {
172-
parsedValue = value;
173-
break;
174-
}
175-
case 'number': {
176-
parsedValue = parseFloat(value);
177-
break;
178-
}
179-
case 'boolean': {
180-
parsedValue = !!value || value === 'true';
181-
break;
182-
}
183-
case 'array': {
184-
parsedValue = JSON.parse(value);
185-
break;
186-
}
187-
case 'object': {
188-
parsedValue = JSON.parse(value);
189-
break;
190-
}
191-
case 'enum': {
192-
parsedValue = schema.enum.includes(value) ? value : undefined;
193-
break;
194-
}
170+
case 'string':
171+
return value as T;
172+
case 'number':
173+
return parseFloat(value) as T;
174+
case 'boolean':
175+
return (!!value || value === 'true') as T;
176+
case 'array':
177+
case 'object':
178+
return JSON.parse(value) as T;
179+
case 'enum':
180+
return (schema.enum.includes(value) ? value : undefined) as T;
195181
default: {
196182
const _exhaustiveCheck: never = schemaType;
197183
return undefined;
198184
}
199185
}
200-
return parsedValue as T;
201186
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ const config = {
8080
'no-useless-return': 'error',
8181
'no-param-reassign': 'error',
8282
'no-warning-comments': 'error',
83+
'max-nested-callbacks': ['error', 3],
8384
'no-shadow': ['error', { allow: ['_', 'args', 'resolve', 'cwd'] }], // globals and a few large refactors
8485
'no-restricted-imports': ['error', { patterns: ['**/dist/**', '**/node_modules/**'] }],
86+
'max-depth': ['error', 3],
8587
'max-params': ['error', 3],
8688
'max-lines': ['error', 1000],
89+
'max-statements': ['error', 15],
8790
'max-lines-per-function': ['error', 50],
8891
'max-statements-per-line': ['error', { max: 1 }],
8992
'import/extensions': ['error', 'ignorePackages', { js: 'always', 'css?inline': 'never' }],
@@ -134,10 +137,7 @@ const config = {
134137
'@typescript-eslint/no-unnecessary-type-parameters': 'off',
135138
'@typescript-eslint/prefer-readonly': 'off',
136139
'@typescript-eslint/explicit-function-return-type': 'off',
137-
'id-length': ['off', { min: 2, exceptions: ['_'] }],
138-
'max-statements': ['error', 20], // goal 15
139-
'max-depth': ['off', 3],
140-
'max-nested-callbacks': ['off', 3]
140+
'id-length': ['off', { min: 2, exceptions: ['_'] }]
141141
},
142142
settings: {
143143
jsdoc: {
@@ -190,6 +190,7 @@ export const browserTypescriptConfig = [
190190
'max-lines': 'off',
191191
'max-lines-per-function': 'off',
192192
'max-statements': 'off',
193+
'max-nested-callbacks': 'off',
193194
'local-typescript/require-fixture-cleanup': ['error'],
194195
'local-typescript/require-element-stable': ['off'], // temporarily disabled, will enable in followup
195196
'local-typescript/require-listener-cleanup': ['off'],
@@ -238,6 +239,7 @@ export const nodeTypescriptConfig = [
238239
'max-lines': 'off',
239240
'max-statements': 'off',
240241
'max-lines-per-function': 'off',
242+
'max-nested-callbacks': 'off',
241243
'local-typescript/require-fixture-cleanup': ['error'],
242244
'local-typescript/require-element-stable': ['off'], // temporarily disabled, will enable in followup
243245
'local-typescript/require-listener-cleanup': ['off'],

projects/internals/metadata/src/tasks/wireit.utils.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,23 @@ function extractWireitScripts(packageJsonPath: string) {
9595
}
9696
}
9797

98+
function addDependency(dep: unknown, script: { packagePath: string; dependencies: string[] }, key: string) {
99+
try {
100+
const { packagePath, scriptName } = parseDependency(dep as string, script.packagePath);
101+
if (packagePath) {
102+
script.dependencies.push(`${packagePath}:${scriptName}`);
103+
}
104+
} catch (err) {
105+
console.error(`error parsing dependency in ${key}:`, (err as Error).message);
106+
}
107+
}
108+
98109
function buildDependencyGraph() {
99110
for (const [key, script] of wireitScripts.entries()) {
100111
const deps = script.config.dependencies || [];
101112

102113
for (const dep of deps) {
103-
try {
104-
const { packagePath, scriptName } = parseDependency(dep, script.packagePath);
105-
if (packagePath) {
106-
const depKey = `${packagePath}:${scriptName}`;
107-
script.dependencies.push(depKey);
108-
}
109-
} catch (err) {
110-
console.error(`error parsing dependency in ${key}:`, (err as Error).message);
111-
}
114+
addDependency(dep, script, key);
112115
}
113116
}
114117
}

0 commit comments

Comments
 (0)