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
4 changes: 2 additions & 2 deletions projects/core/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"src/format-datetime/format-datetime.test.ts": {
"@typescript-eslint/no-unnecessary-type-assertion": {
"count": 27
"count": 26
}
},
"src/format-number/format-number.test.ts": {
Expand All @@ -21,7 +21,7 @@
},
"src/format-relative-time/format-relative-time.test.ts": {
"@typescript-eslint/no-unnecessary-type-assertion": {
"count": 40
"count": 39
}
},
"src/internal/controllers/audit.controller.ts": {
Expand Down
4 changes: 2 additions & 2 deletions projects/core/src/button-group/button-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import globalStyles from './button-group.global.css?inline';
* @documentation https://nvidia.github.io/elements/docs/elements/button-group/
* @since 0.16.0
* @entrypoint \@nvidia-elements/core/button-group
* @slot - default slot for `nve-button` or `nve-icon-button`
* @slot - default slot for `nve-button`, `nve-icon-button`, `nve-divider`, `nve-media-seek-button`, or `nve-media-pause-button`
* @cssprop --background
* @cssprop --border-radius
* @cssprop --padding
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ButtonGroup extends LitElement {
static readonly metadata = {
tag: 'nve-button-group',
version: '0.0.0',
children: ['nve-button', 'nve-icon-button', 'nve-divider']
children: ['nve-button', 'nve-icon-button', 'nve-divider', 'nve-media-seek-button', 'nve-media-pause-button']
};

/** @private */
Expand Down
3 changes: 0 additions & 3 deletions projects/core/src/card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class Card extends LitElement implements ContainerElement {
* @cssprop --gap
* @aria https://github.com/w3c/aria-practices/issues
*/
@audit()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moves non critical audits/best practices to static checks only via eslint

export class CardHeader extends LitElement {
static styles = useStyles([cardHeaderStyleSheet]);

Expand Down Expand Up @@ -96,7 +95,6 @@ export class CardHeader extends LitElement {
* @cssprop --padding
* @aria https://github.com/w3c/aria-practices/issues
*/
@audit()
export class CardContent extends LitElement {
static styles = useStyles([cardContentStyleSheet]);

Expand Down Expand Up @@ -124,7 +122,6 @@ export class CardContent extends LitElement {
* @cssprop --border-top
* @aria https://github.com/w3c/aria-practices/issues
*/
@audit()
export class CardFooter extends LitElement {
static styles = useStyles([cardFooterStyleSheet]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/dialog/dialog-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './dialog-footer.css?inline';

/**
Expand All @@ -17,7 +17,6 @@ import styles from './dialog-footer.css?inline';
* @cssprop --gap
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
*/
@audit()
export class DialogFooter extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/dialog/dialog-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './dialog-header.css?inline';

/**
Expand All @@ -16,7 +16,6 @@ import styles from './dialog-header.css?inline';
* @cssprop --padding
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
*/
@audit()
export class DialogHeader extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/drawer/drawer-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './drawer-content.css?inline';

/**
Expand All @@ -16,7 +16,6 @@ import styles from './drawer-content.css?inline';
* @cssprop --width
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
*/
@audit()
export class DrawerContent extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/drawer/drawer-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './drawer-footer.css?inline';

/**
Expand All @@ -18,7 +18,6 @@ import styles from './drawer-footer.css?inline';
* @cssprop --min-height
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
*/
@audit()
export class DrawerFooter extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/drawer/drawer-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './drawer-header.css?inline';

/**
Expand All @@ -17,7 +17,6 @@ import styles from './drawer-header.css?inline';
* @cssprop --padding
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
*/
@audit()
export class DrawerHeader extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/dropdown/dropdown-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './dropdown-footer.css?inline';

/**
Expand All @@ -17,7 +17,6 @@ import styles from './dropdown-footer.css?inline';
* @cssprop --gap
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/menubar/
*/
@audit()
export class DropdownFooter extends LitElement {
static styles = useStyles([styles]);

Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/dropdown/dropdown-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { html, LitElement } from 'lit';
import { audit, useStyles } from '@nvidia-elements/core/internal';
import { useStyles } from '@nvidia-elements/core/internal';
import styles from './dropdown-header.css?inline';

/**
Expand All @@ -16,7 +16,6 @@ import styles from './dropdown-header.css?inline';
* @cssprop --padding
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/menubar/
*/
@audit()
export class DropdownHeader extends LitElement {
static styles = useStyles([styles]);

Expand Down
60 changes: 45 additions & 15 deletions projects/core/src/format-bytes/format-bytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,51 +228,81 @@ describe(FormatBytes.metadata.tag, () => {
['display', 'invalid'],
['unit', 'invalid'],
['unit-display', 'invalid']
])('should preserve input for an invalid %s option', async (attribute, value) => {
])('should preserve input without warning for an invalid %s option', async (attribute, value) => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.setAttribute(attribute, value);
await elementIsStable(element);

expect(renderedText(element)).toBe('1048576');
expect(warn).toHaveBeenCalledOnce();
expect(warn).not.toHaveBeenCalled();
});

it('should preserve and warn for invalid numeric input', async () => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.textContent = 'not-a-number';
await elementIsStable(element);
it.each(['not-a-number', 'NaN', 'Infinity', '-Infinity', '1e309'])(
'should preserve invalid numeric input %s without warning',
async value => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.textContent = value;
await elementIsStable(element);

expect(renderedText(element)).toBe('not-a-number');
expect(warn).toHaveBeenCalledWith('format-bytes: invalid numeric value "not-a-number"');
});
expect(renderedText(element)).toBe(value);
expect(warn).not.toHaveBeenCalled();
}
);

it('should preserve and warn for an invalid value attribute', async () => {
it('should preserve an invalid value attribute without warning', async () => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.setAttribute('value', 'not-a-number');
await elementIsStable(element);

expect(renderedData(element)?.getAttribute('value')).toBe('not-a-number');
expect(renderedText(element)).toBe('not-a-number');
expect(warn).toHaveBeenCalledWith('format-bytes: invalid numeric value "not-a-number"');
expect(warn).not.toHaveBeenCalled();
});

it('should preserve and warn for a NaN value property', async () => {
it('should preserve a NaN value property without warning', async () => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.value = Number.NaN;
await elementIsStable(element);

expect(renderedData(element)?.getAttribute('value')).toBe('NaN');
expect(renderedText(element)).toBe('NaN');
expect(warn).toHaveBeenCalledWith('format-bytes: invalid numeric value "NaN"');
expect(warn).not.toHaveBeenCalled();
});

it('should preserve input for invalid fraction digit options', async () => {
it('should preserve input silently for invalid fraction digit options', async () => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.minimumFractionDigits = 3;
element.maximumFractionDigits = 2;
await elementIsStable(element);

expect(renderedText(element)).toBe('1048576');
expect(warn).toHaveBeenCalledOnce();
expect(warn).not.toHaveBeenCalled();
});

it.each([
['locale', 'en_US'],
['minimum-fraction-digits', '-1'],
['maximum-fraction-digits', '101'],
['maximum-fraction-digits', 'NaN'],
['maximum-fraction-digits', 'Infinity']
])('should preserve input without warning for invalid %s', async (attribute, value) => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.setAttribute(attribute, value);
await elementIsStable(element);

expect(renderedText(element)).toBe('1048576');
expect(warn).not.toHaveBeenCalled();
});

it('should resume formatting after correcting an invalid locale', async () => {
const warn = vi.spyOn(LogService, 'warn').mockImplementation(() => undefined);
element.locale = 'en_US';
await elementIsStable(element);
expect(renderedText(element)).toBe('1048576');

element.locale = 'en-US';
await elementIsStable(element);
expect(renderedText(element)).toBe('1.05 MB');
expect(warn).not.toHaveBeenCalled();
});
});
25 changes: 3 additions & 22 deletions projects/core/src/format-bytes/format-bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { html, LitElement } from 'lit';
import { property } from 'lit/decorators/property.js';
import { LogService, typeSSR, useStyles } from '@nvidia-elements/core/internal';
import { typeSSR, useStyles } from '@nvidia-elements/core/internal';
import styles from './format-bytes.css?inline';

export type FormatBytesDisplay = 'decimal' | 'binary';
Expand Down Expand Up @@ -122,7 +122,6 @@ export class FormatBytes extends LitElement {
const numericValue = Number(rawValue);
if (Number.isFinite(numericValue)) return numericValue;

LogService.warn(`format-bytes: invalid numeric value "${rawValue}"`);
return null;
}

Expand All @@ -144,24 +143,8 @@ export class FormatBytes extends LitElement {
return Math.abs(convertedValue) === 1 ? labels.singular : labels.plural;
}

#warnInvalidOption(name: string, value: unknown): void {
LogService.warn(`format-bytes: invalid ${name} value "${String(value)}"`);
}

#hasValidConfiguration(): boolean {
if (!isDisplay(this.display)) {
this.#warnInvalidOption('display', this.display);
return false;
}
if (!isUnitDisplay(this.unitDisplay)) {
this.#warnInvalidOption('unit-display', this.unitDisplay);
return false;
}
if (this.unit !== undefined && !isUnit(this.unit)) {
this.#warnInvalidOption('unit', this.unit);
return false;
}
return true;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This does not change the functional behavior of the component but moves the checks for logging to static eslint rules. The runtime output/visual behavior is the same.

return isDisplay(this.display) && isUnitDisplay(this.unitDisplay) && (this.unit === undefined || isUnit(this.unit));
}

get #numberFormatOptions(): Intl.NumberFormatOptions {
Expand Down Expand Up @@ -201,9 +184,7 @@ export class FormatBytes extends LitElement {
try {
const roundedValue = this.#roundNumber(convertedValue);
return `${this.#formatNumber(roundedValue)} ${this.#formatLabel(resolvedUnit, roundedValue)}`;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
LogService.warn(`format-bytes: ${message}`);
} catch {
return rawValue;
}
}
Expand Down
Loading
Loading