Skip to content

Commit

Permalink
fix(eslint): support attributify for @unocss/blocklist
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 4, 2023
1 parent 9e95114 commit 6d760ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/fixtures/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
hover:(text-red text-4xl)
hover:mx1 mx1 m2
blocked-rule
"></div>
" blocked-rule-attr></div>
</div>
</template>
22 changes: 22 additions & 0 deletions packages/eslint-plugin/src/rules/blocklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RuleListener } from '@typescript-eslint/utils/ts-eslint'
import type { TSESTree } from '@typescript-eslint/types'
import { CLASS_FIELDS } from '../constants'
import { syncAction } from './_'
import { IGNORE_ATTRIBUTES } from './order-attributify'

export default ESLintUtils.RuleCreator(name => name)({
name: 'blocklist',
Expand Down Expand Up @@ -58,6 +59,27 @@ export default ESLintUtils.RuleCreator(name => name)({
checkLiteral(node.value)
}
},
// Attributify
VStartTag(node: any) {
const valueless = node.attributes.filter((i: any) => typeof i.key?.name === 'string' && !IGNORE_ATTRIBUTES.includes(i.key?.name?.toLowerCase()) && i.value == null)
if (!valueless.length)
return

for (const node of valueless) {
if (!node?.key?.name)
continue
const blocked = syncAction('blocklist', node.key.name, context.filename)
blocked.forEach((i) => {
context.report({
node,
messageId: 'in-blocklist',
data: {
name: i,
},
})
})
}
},
}

// @ts-expect-error missing-types
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/order-attributify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { TSESTree } from '@typescript-eslint/types'
import MagicString from 'magic-string'
import { syncAction } from './_'

const IGNORE_ATTRIBUTES = ['style', 'class', 'classname', 'value']
export const IGNORE_ATTRIBUTES = ['style', 'class', 'classname', 'value']

export default ESLintUtils.RuleCreator(name => name)({
name: 'order-attributify',
Expand Down

0 comments on commit 6d760ad

Please sign in to comment.