Files
FilesReadSystem/frontend/.rules/require-button-interaction.yml

57 lines
1.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

id: require-button-interaction
language: Tsx
files:
- src/**/*.tsx
- src/**/*.jsx
rule:
kind: jsx_opening_element
all:
# 必须是 <Button> 组件
- has:
kind: identifier
regex: '^Button$'
# 没有 onClick
- not:
has:
kind: jsx_attribute
has:
kind: property_identifier
regex: '^onClick$'
# 没有 asChild
- not:
has:
kind: jsx_attribute
has:
kind: property_identifier
regex: '^asChild$'
# 没有 type="submit" 或 type="reset"
- not:
has:
kind: jsx_attribute
all:
- has:
kind: property_identifier
regex: '^type$'
- any:
- has:
kind: string
regex: '^"(submit|reset)"$'
- has:
kind: jsx_expression
has:
kind: string
regex: '^"(submit|reset)"$'
# 不在 *Trigger 组件内部(如 DialogTrigger、SheetTrigger
- not:
inside:
stopBy: end
kind: jsx_element
has:
kind: jsx_opening_element
has:
kind: identifier
regex: 'Trigger$'
message: '<Button> 必须是可点击的:请添加 onClick、type="submit"、type="reset"、asChild 属性,或将其包裹在 *Trigger 组件中'
severity: error