Open JoshuaKGoldberg opened 1 year ago
We'd welcome a rule for this, as some plugin authors may prefer to avoid complex selectors. However, I would lean toward any such rule to be optional and not recommended. It feels too opinionated to be in the recommended config. I wouldn't want to prevent plugin authors from taking full advantage of selectors if they prefer that style.
I would like to contribute this rule but I think there needs to be discussion about what a complex selector is.
Personally I would only allow node types (e.g. FunctionDeclaration
) and node classes (e.g. :function
) combined with ,
or an optional :exit
.
Valid Examples:
ClassDeclaration, ClassExpression
:function:exit
onCodePathStart
Invalid examples:
CallExpression[callee.type="MemberExpression"]
utils.getKeyName
)*
: never seen this selector in an actual rule[attr]
: probably will lead to an unforeseen error for AST nodes unknown to the rule authorBut as basically none of the selector syntax is used, it should be clear what and what is not allowed (versus different rule options, e.g. allowing maximally one attribute selector, ...). This also makes other rules for node selectors unnecessary (e.g. formatting or whether a selector can be simplified). Further this allows the callback parameters to be easily typeable (see #340)
I tried the above rules on my own rules and found no cases where I did not find it preferrable. What do you think?
Yeah it's a good question. https://github.com/typescript-eslint/typescript-eslint/issues/4065 shows @auvred's really nifty library, magic-query
. So I personally think "whatever is reasonable to parse in the type system" is a good delineation.
Moving discussion from https://github.com/typescript-eslint/typescript-eslint/pull/6444#discussion_r1102035077 here, and quoting @bradzacher:
Is there any consensus/desire here to limit ESQuery node types?
Proposed "bad":
Proposed "good":