Skip to content

Commit 1c1e64f

Browse files
committed
chore(ci): update eslint
- progress improving lint rules to simplify the complexity levels of source Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent 2276640 commit 1c1e64f

57 files changed

Lines changed: 370 additions & 384 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

projects/cli/src/index.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ describe('index', () => {
6565

6666
describe('interactive fallback for missing required args', () => {
6767
it('should not exit with validation error for project.create without <type>', () => {
68-
const output = runWithoutRequiredArgs('project.create');
69-
expect(output).not.toContain('Not enough non-option arguments');
70-
expect(output).not.toContain('Missing required argument');
68+
const result = runWithoutRequiredArgs('project.create');
69+
expect(result).not.toContain('Not enough non-option arguments');
70+
expect(result).not.toContain('Missing required argument');
7171
});
7272

7373
it('should not exit with validation error for api.get without <names>', () => {
74-
const output = runWithoutRequiredArgs('api.get');
75-
expect(output).not.toContain('Not enough non-option arguments');
76-
expect(output).not.toContain('Missing required argument');
74+
const result = runWithoutRequiredArgs('api.get');
75+
expect(result).not.toContain('Not enough non-option arguments');
76+
expect(result).not.toContain('Missing required argument');
7777
});
7878

7979
it('should not exit with validation error for project.validate without <type>', () => {
80-
const output = runWithoutRequiredArgs('project.validate');
81-
expect(output).not.toContain('Not enough non-option arguments');
82-
expect(output).not.toContain('Missing required argument');
80+
const result = runWithoutRequiredArgs('project.validate');
81+
expect(result).not.toContain('Not enough non-option arguments');
82+
expect(result).not.toContain('Missing required argument');
8383
});
8484
});
8585

@@ -102,10 +102,10 @@ describe('index', () => {
102102
encoding: 'utf-8',
103103
input: ''
104104
});
105-
const output = `${result.stdout}${result.stderr}`;
106-
expect(output).not.toContain('"nve-foo,nve-bar"');
107-
expect(output).toContain('nve-foo');
108-
expect(output).toContain('nve-bar');
105+
const combined = `${result.stdout}${result.stderr}`;
106+
expect(combined).not.toContain('"nve-foo,nve-bar"');
107+
expect(combined).toContain('nve-foo');
108+
expect(combined).toContain('nve-bar');
109109
});
110110
});
111111
});

projects/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ yargsInstance.command(
7272

7373
tools
7474
.filter(tool => tool.metadata.support & ToolSupport.CLI)
75+
// eslint-disable-next-line max-lines-per-function
7576
.forEach(tool => {
7677
const { inputSchema, summary } = tool.metadata;
7778
const { properties, required } = inputSchema ?? {};
@@ -101,6 +102,7 @@ tools
101102
optionalArgs.forEach(key => builder.option(key, argOptions(properties[key]!)));
102103
},
103104
// main handler for the command
105+
// eslint-disable-next-line max-statements
104106
async args => {
105107
const start = performance.now();
106108
const { result, status, message } = await runAsyncTool(args, tool);

projects/cli/src/mcp/mcp.test.ts

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
55

66
const { mockRegisterTool, mockRegisterPrompt, mockConnect, mcpTool, cliTool, allTool, mockPrompt, mockZodSchema } =
77
vi.hoisted(() => {
8-
const mockRegisterTool = vi.fn();
9-
const mockRegisterPrompt = vi.fn();
10-
const mockConnect = vi.fn().mockResolvedValue(undefined);
11-
const mockZodSchema = { shape: {}, optional: () => mockZodSchema };
8+
const zodSchema = { shape: {}, optional: () => zodSchema };
129

1310
const createMockTool = (overrides: Record<string, unknown>) => {
1411
const fn = vi.fn().mockResolvedValue({ status: 'complete', result: 'test' });
@@ -27,41 +24,42 @@ const { mockRegisterTool, mockRegisterPrompt, mockConnect, mcpTool, cliTool, all
2724
return fn;
2825
};
2926

30-
const mcpTool = createMockTool({
31-
support: 1,
32-
toolName: 'mcp_tool',
33-
command: 'mcp.tool',
34-
title: 'MCP Tool',
35-
summary: 'MCP only',
36-
inputSchema: undefined
37-
});
38-
39-
const cliTool = createMockTool({
40-
support: 2,
41-
toolName: 'cli_tool',
42-
command: 'cli_tool',
43-
title: 'CLI Tool',
44-
summary: 'CLI only'
45-
});
46-
47-
const allTool = createMockTool({
48-
support: 3,
49-
toolName: 'all_tool',
50-
command: 'all.tool',
51-
title: 'All Tool',
52-
summary: 'All support',
53-
outputSchema: { type: 'string' }
54-
});
55-
56-
const mockPrompt = {
57-
name: 'test-prompt',
58-
title: 'Test Prompt',
59-
description: 'A test prompt',
60-
argsSchema: { type: 'object', properties: {} },
61-
handler: vi.fn().mockResolvedValue({ messages: [] })
27+
return {
28+
mockRegisterTool: vi.fn(),
29+
mockRegisterPrompt: vi.fn(),
30+
mockConnect: vi.fn().mockResolvedValue(undefined),
31+
mockZodSchema: zodSchema,
32+
mcpTool: createMockTool({
33+
support: 1,
34+
toolName: 'mcp_tool',
35+
command: 'mcp.tool',
36+
title: 'MCP Tool',
37+
summary: 'MCP only',
38+
inputSchema: undefined
39+
}),
40+
cliTool: createMockTool({
41+
support: 2,
42+
toolName: 'cli_tool',
43+
command: 'cli_tool',
44+
title: 'CLI Tool',
45+
summary: 'CLI only'
46+
}),
47+
allTool: createMockTool({
48+
support: 3,
49+
toolName: 'all_tool',
50+
command: 'all.tool',
51+
title: 'All Tool',
52+
summary: 'All support',
53+
outputSchema: { type: 'string' }
54+
}),
55+
mockPrompt: {
56+
name: 'test-prompt',
57+
title: 'Test Prompt',
58+
description: 'A test prompt',
59+
argsSchema: { type: 'object', properties: {} },
60+
handler: vi.fn().mockResolvedValue({ messages: [] })
61+
}
6262
};
63-
64-
return { mockRegisterTool, mockRegisterPrompt, mockConnect, mcpTool, cliTool, allTool, mockPrompt, mockZodSchema };
6563
});
6664

6765
vi.mock('@modelcontextprotocol/sdk/server/mcp.js', () => ({

projects/cli/src/mcp/mcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { type ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
1111
export const VERSION = '0.0.0';
1212
export const BUILD_SHA = '__NVE_BUILD_CHECKSUM__';
1313

14+
// eslint-disable-next-line max-lines-per-function
1415
export async function startMcpServer() {
1516
process.env.ELEMENTS_ENV = 'mcp';
1617

projects/cli/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ export function getSelect(value: string, prop: { enum?: string[] }) {
109109
return select({
110110
message: `Select a ${value}:`,
111111
choices:
112-
prop.enum?.map(value => ({
113-
name: value,
114-
value
112+
prop.enum?.map(option => ({
113+
name: option,
114+
value: option
115115
})) ?? []
116116
});
117117
}

projects/code/src/codeblock/codeblock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ export class CodeBlock extends LitElement implements ContainerElement {
144144
const lines = this.formattedCode.split('\n').map((line, index) => {
145145
let span = `${line}`;
146146
if (linesToHighlight.includes(index + 1)) {
147+
let wrapped = line;
147148
// fix for highlightjs multi-line comments
148149
if (line.includes('hljs-comment') && !line.endsWith('</span>')) {
149-
line = `${line}</span>`;
150+
wrapped = `${line}</span>`;
150151
}
151-
span = `<span class="hljs-highlight">${line}</span>`;
152+
span = `<span class="hljs-highlight">${wrapped}</span>`;
152153
}
153154
return span;
154155
});

projects/core/build/icons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export interface IconSVG {
7474
svg: () => Promise<string> | string;
7575
}
7676
77-
function iconImport(iconImport: () => Promise<{default: string}>): IconSVG {
77+
function iconImport(importer: () => Promise<{default: string}>): IconSVG {
7878
return {
7979
async svg() {
80-
return (await iconImport()).default;
80+
return (await importer()).default;
8181
}
8282
}
8383
}

projects/core/src/color/color.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ describe(Color.metadata.tag, () => {
4646
});
4747

4848
it('should not apply default if custom default is provided', async () => {
49-
const element = document.createElement(Color.metadata.tag) as Color;
49+
const customElement = document.createElement(Color.metadata.tag) as Color;
5050
const input = document.createElement('input');
5151
input.value = '#fff';
5252

53-
element.appendChild(input);
54-
document.body.appendChild(element);
55-
await element.updateComplete;
53+
customElement.appendChild(input);
54+
document.body.appendChild(customElement);
55+
await customElement.updateComplete;
5656
expect(input.value).toBe('#fff');
57-
element.remove();
57+
customElement.remove();
5858
});
5959

6060
it('should update the color value if EyeDropper is used', async () => {

projects/core/src/combobox/combobox.examples.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ const schema = {
780780
class ComboboxDemo extends LitElement {
781781
@state() private value = [{ name: '', value: '' }];
782782

783-
// todo
784783
/* eslint-disable @nvidia-elements/lint/no-deprecated-popover-attributes */
785784
render() {
786785
return html`

projects/core/src/combobox/combobox.test.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ describe(Combobox.metadata.tag, () => {
7575
it('should reflect each option to a menu item', async () => {
7676
emulateClick(input);
7777
await elementIsStable(element);
78-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
79-
expect(items.length).toBe(3);
80-
expect(items[0].textContent.trim()).toBe(options[0].value);
81-
expect(items[1].textContent.trim()).toBe(options[1].value);
82-
expect(items[2].textContent.trim()).toBe(options[2].value);
78+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
79+
expect(menuItems.length).toBe(3);
80+
expect(menuItems[0].textContent.trim()).toBe(options[0].value);
81+
expect(menuItems[1].textContent.trim()).toBe(options[1].value);
82+
expect(menuItems[2].textContent.trim()).toBe(options[2].value);
8383
});
8484

8585
it('should default the dropdown to align bottom center with position-area "bottom span-right" ensure wide selection options span to the right of the input', async () => {
@@ -107,10 +107,10 @@ describe(Combobox.metadata.tag, () => {
107107
it('should each menu item with the aria role of option', async () => {
108108
emulateClick(input);
109109
await elementIsStable(element);
110-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
111-
expect(items[0].getAttribute('role')).toBe('option');
112-
expect(items[1].getAttribute('role')).toBe('option');
113-
expect(items[2].getAttribute('role')).toBe('option');
110+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
111+
expect(menuItems[0].getAttribute('role')).toBe('option');
112+
expect(menuItems[1].getAttribute('role')).toBe('option');
113+
expect(menuItems[2].getAttribute('role')).toBe('option');
114114
});
115115

116116
it('should only show options that partial match the input value', async () => {
@@ -147,9 +147,9 @@ describe(Combobox.metadata.tag, () => {
147147
await elementIsStable(element);
148148
expect(dropdown.matches(':popover-open')).toBe(true);
149149

150-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
151-
items[0].focus();
152-
items[0].dispatchEvent(new KeyboardEvent('keydown', { code: 'Escape', bubbles: true }));
150+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
151+
menuItems[0].focus();
152+
menuItems[0].dispatchEvent(new KeyboardEvent('keydown', { code: 'Escape', bubbles: true }));
153153
await elementIsStable(element);
154154
expect(dropdown.matches(':popover-open')).toBe(false);
155155
});
@@ -164,7 +164,7 @@ describe(Combobox.metadata.tag, () => {
164164
});
165165

166166
it('should focus first option if key arrow down is pressed', async () => {
167-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
167+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
168168
const dropdown = element.shadowRoot.querySelector<Dropdown>(Dropdown.metadata.tag);
169169
expect(dropdown.matches(':popover-open')).toBe(false);
170170
element.dispatchEvent(new KeyboardEvent('keydown'));
@@ -176,8 +176,8 @@ describe(Combobox.metadata.tag, () => {
176176
input.focus();
177177
await open;
178178
element.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowDown' }));
179-
expect(items[0].tabIndex).toBe(0);
180-
expect(element.shadowRoot.activeElement.tagName).toBe(items[0].tagName);
179+
expect(menuItems[0].tabIndex).toBe(0);
180+
expect(element.shadowRoot.activeElement.tagName).toBe(menuItems[0].tagName);
181181
});
182182

183183
it('should hide dropdown on keydown and is a tab event', async () => {
@@ -209,24 +209,24 @@ describe(Combobox.metadata.tag, () => {
209209
});
210210

211211
it('should set the input value if a option is clicked', async () => {
212-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
212+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
213213
const dropdown = element.shadowRoot.querySelector<Dropdown>(Dropdown.metadata.tag);
214214
expect(dropdown.matches(':popover-open')).toBe(false);
215215

216216
element.dispatchEvent(new KeyboardEvent('keydown'));
217217
await elementIsStable(element);
218218
expect(dropdown.matches(':popover-open')).toBe(true);
219219

220-
emulateClick(items[0]);
220+
emulateClick(menuItems[0]);
221221
expect(input.value).toBe('Option 1');
222222
});
223223

224224
it('should show "no results" message if no options are provided', async () => {
225-
const options = element.querySelectorAll('option');
225+
const allOptions = element.querySelectorAll('option');
226226
const dropdown = element.shadowRoot.querySelector<Dropdown>(Dropdown.metadata.tag);
227227
expect(dropdown.matches(':popover-open')).toBe(false);
228228

229-
options.forEach(i => i.remove());
229+
allOptions.forEach(i => i.remove());
230230
element.shadowRoot.dispatchEvent(new Event('slotchange'));
231231
element.dispatchEvent(new KeyboardEvent('keydown'));
232232
await elementIsStable(element);
@@ -270,15 +270,14 @@ describe(Combobox.metadata.tag, () => {
270270
});
271271

272272
it('should filter out menu items when corresponding option is disabled', async () => {
273-
const items = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
274-
expect(items[0].disabled).toBe(false);
273+
const menuItems = element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
274+
expect(menuItems[0].disabled).toBe(false);
275275
options[0].disabled = true;
276276
element.shadowRoot.dispatchEvent(new Event('slotchange'));
277277
await elementIsStable(element);
278-
expect(items[0].disabled).toBe(true);
278+
expect(menuItems[0].disabled).toBe(true);
279279
});
280280

281-
// todo: this should be handled better at runtime
282281
it('should throw when selectAll() is called on datalist combobox without a select element', async () => {
283282
expect(() => element.selectAll()).toThrow();
284283
});

0 commit comments

Comments
 (0)