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
6 changes: 6 additions & 0 deletions projects/lint/src/eslint/internals/slots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('noUnexpectedSlotValue', () => {
expect(hasSlot('nve-badge', '')).toBe(true);
expect(hasSlot('nve-tabs-group', 'overview')).toBe(true);
expect(hasSlot('nve-tabs-group', 'details')).toBe(true);
expect(hasSlot('nve-select', 'option-1')).toBe(true);
expect(hasSlot('nve-select', '')).toBe(true);
});
});

Expand All @@ -25,4 +27,8 @@ describe('getRecommendedSlotName', () => {
expect(getRecommendedSlotName('default', 'nve-card')).toBe('');
expect(getRecommendedSlotName('icon', 'nve-badge')).toBe('prefix-icon');
});

it('should recommend the unnamed slot when it is not listed first', () => {
expect(getRecommendedSlotName('default', 'nve-alert')).toBe('');
});
});
5 changes: 3 additions & 2 deletions projects/lint/src/eslint/internals/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export function isKnownElement(tagName: string) {
export function getRecommendedSlotName(slot: string, tagName: string) {
const element = elements.find(el => el.name === tagName);
const slots = element?.manifest?.slots?.map(s => s.name)?.filter(s => s !== undefined) ?? [];
const hasUnnamedSlot = slots.find(s => s === '');
const hasUnnamedSlot = slots.includes('');
let recommendedSlot = slots[0];

if (tagName === 'default' && hasUnnamedSlot) {
// the unnamed slot is not always listed first, so slot="default" must map to it explicitly
if (slot === 'default' && hasUnnamedSlot) {
recommendedSlot = '';
}

Expand Down
17 changes: 17 additions & 0 deletions projects/lint/src/eslint/rules/no-unexpected-slot-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ describe('noUnexpectedSlotValue', () => {
]
}
]
},
{
// nve-alert lists named slots before its unnamed slot
code: '<nve-alert><div slot="default"></div></nve-alert>',
errors: [
{
messageId: 'unexpected-slot-value',
data: { slotName: 'default', tagName: 'div', parentTagName: 'nve-alert' },
suggestions: [
{
messageId: 'suggest-remove-slot-value',
data: { slotName: 'default', alternative: '' },
output: '<nve-alert><div ></div></nve-alert>'
}
]
}
]
}
]
});
Expand Down