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
33 changes: 29 additions & 4 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,33 @@ function checkLabelCase(label: string, path: string): LintIssue | null {
return null;
}

function getViewLabel(view: any, viewPath: string): { label?: string; path: string } {
if (view?.list?.label) {
return { label: view.list.label, path: `${viewPath}.list.label` };
}

const listViews = view?.listViews && typeof view.listViews === 'object' ? view.listViews : {};
for (const [key, listView] of Object.entries<any>(listViews)) {
if (listView?.label) {
return { label: listView.label, path: `${viewPath}.listViews.${key}.label` };
}
}

if (view?.list) {
return { path: `${viewPath}.list.label` };
}

const firstListViewKey = Object.keys(listViews)[0];
if (firstListViewKey) {
return { path: `${viewPath}.listViews.${firstListViewKey}.label` };
}

return { path: `${viewPath}.list.label` };
}

// ─── Lint Engine ────────────────────────────────────────────────────

function lintConfig(config: any): LintIssue[] {
export function lintConfig(config: any): LintIssue[] {
const issues: LintIssue[] = [];

const push = (issue: LintIssue | null) => {
Expand Down Expand Up @@ -144,9 +168,10 @@ function lintConfig(config: any): LintIssue[] {
if (view.name) {
push(checkSnakeCase(view.name, `${viewPath}.name`, 'View name'));
}
push(checkLabelExists(view, `${viewPath}.label`, 'View'));
if (view.label) {
push(checkLabelCase(view.label, `${viewPath}.label`));
const viewLabel = getViewLabel(view, viewPath);
push(checkLabelExists({ label: viewLabel.label, name: view.name }, viewLabel.path, 'View'));
if (viewLabel.label) {
push(checkLabelCase(viewLabel.label, viewLabel.path));
}
}

Expand Down
54 changes: 54 additions & 0 deletions packages/cli/test/lint-view-label.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest';
import { lintConfig } from '../src/commands/lint';

describe('lint view labels', () => {
it('accepts canonical default list labels', () => {
const issues = lintConfig({
views: [
{
list: {
label: 'Accounts',
columns: ['name'],
},
},
],
});

expect(issues.filter((issue) => issue.rule === 'required/label')).toEqual([]);
});

it('accepts canonical named list view labels', () => {
const issues = lintConfig({
views: [
{
listViews: {
all: {
label: 'All Accounts',
columns: ['name'],
},
},
},
],
});

expect(issues.filter((issue) => issue.rule === 'required/label')).toEqual([]);
});

it('reports a missing label at the schema-supported list label path', () => {
const issues = lintConfig({
views: [
{
list: {
columns: ['name'],
},
},
],
});

expect(issues).toContainEqual(expect.objectContaining({
rule: 'required/label',
path: 'views[0].list.label',
message: 'View "?" is missing a label',
}));
});
});