Skip to content

Commit 7f3b358

Browse files
committed
feat: support filter custom blocks
1 parent b403435 commit 7f3b358

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/index.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,35 @@ const cache = new Map<string, Block[]>()
4343

4444
export interface Options {
4545
blocks?: {
46+
/**
47+
* Create virtual files for each `<style>` block
48+
* @default false
49+
*/
4650
styles?: boolean
51+
/**
52+
* Enable custom blocks
53+
* Pass an string array to specify custom block types, or `true` to enable all custom blocks
54+
* @default false
55+
*/
56+
customBlocks?: boolean | string[]
57+
/**
58+
* Create virtual files for each `<template>` block
59+
* Generally not recommended, as `eslint-plugin-vue` handles it
60+
* @default false
61+
*/
4762
template?: boolean
63+
/**
64+
* Create virtual files for each `<script>` block
65+
* Generally not recommended, as `eslint-plugin-vue` handles it
66+
* @default false
67+
*/
4868
script?: boolean
69+
/**
70+
* Create virtual files for each `<script setup>` block
71+
* Generally not recommended, as `eslint-plugin-vue` handles it
72+
* @default false
73+
*/
4974
scriptSetup?: boolean
50-
customBlocks?: boolean
5175
}
5276
/**
5377
* Default language for each block type
@@ -73,6 +97,7 @@ function processor(options: Options = {}): Linter.Processor {
7397
style: 'css',
7498
template: 'html',
7599
script: 'js',
100+
i18n: 'json',
76101
...options.defaultLanguage,
77102
}
78103

@@ -98,8 +123,13 @@ function processor(options: Options = {}): Linter.Processor {
98123

99124
if (options.blocks?.styles)
100125
descriptor.styles.forEach(style => pushBlock(style))
101-
if (options.blocks?.customBlocks)
102-
descriptor.customBlocks.forEach(block => pushBlock(block))
126+
if (options.blocks?.customBlocks) {
127+
descriptor.customBlocks.forEach((block) => {
128+
if (Array.isArray(options.blocks?.customBlocks) && !options.blocks?.customBlocks.includes(block.type))
129+
return
130+
pushBlock(block)
131+
})
132+
}
103133
if (options.blocks?.template && descriptor.template)
104134
pushBlock(descriptor.template)
105135
if (options.blocks?.script && descriptor.script)

0 commit comments

Comments
 (0)