Skip to content

Commit

Permalink
fix(autocomplete): remove blocked rules from suggestions (#2496)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Apr 12, 2023
1 parent 6b39445 commit c873e4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/autocomplete/src/create.ts
Expand Up @@ -175,7 +175,7 @@ export function createAutocomplete(uno: UnoGenerator): UnocssAutocomplete {

function processSuggestions(suggestions: (string[] | undefined)[], prefix = '', suffix = '') {
return uniq(suggestions.flat())
.filter((i): i is string => !!(i && !i.match(/-$/)))
.filter((i): i is string => !!(i && !i.match(/-$/) && !uno.isBlocked(i)))
.sort((a, b) => {
const numA = +(a.match(/\d+$/)?.[0] || NaN)
const numB = +(b.match(/\d+$/)?.[0] || NaN)
Expand Down
16 changes: 16 additions & 0 deletions test/autocomplete.test.ts
Expand Up @@ -111,6 +111,22 @@ describe('autocomplete', () => {
).toMatchSnapshot()
})

it('should not suggest blocked rules', async () => {
const uno = createGenerator({
presets: [
presetUno(),
],
blocklist: [
/[A-Z]/,
],
})

const ac = createAutocomplete(uno)

expect((await ac.suggest('text-trueGray-')))
.toMatchInlineSnapshot('[]')
})

it('should provide skip DEFAULT', async () => {
expect((await ac.suggest('text-red-')))
.toMatchSnapshot()
Expand Down

0 comments on commit c873e4c

Please sign in to comment.