11'use strict' ;
22
3- const typedNodeSourceFileTesters = [
3+ const defaultTypedNodeSourceFileTesters = [
44 / @ t y p e s [ / \\ ] e s t r e e [ / \\ ] i n d e x \. d \. t s / ,
55 / @ t y p e s c r i p t - e s l i n t [ / \\ ] t y p e s [ / \\ ] d i s t [ / \\ ] g e n e r a t e d [ / \\ ] a s t - s p e c \. d \. t s / ,
66] ;
@@ -26,9 +26,10 @@ const typedNodeSourceFileTesters = [
2626 * ```
2727 *
2828 * @param {import('typescript').Type } type
29+ * @param {RegExp[] } typedNodeSourceFileTesters
2930 * @returns Whether the type seems to include a known ESTree or TSESTree AST node.
3031 */
31- function isAstNodeType ( type ) {
32+ function isAstNodeType ( type , typedNodeSourceFileTesters ) {
3233 return ( type . types || [ type ] )
3334 . filter ( ( typePart ) => typePart . getProperty ( 'type' ) )
3435 . flatMap (
@@ -55,13 +56,33 @@ module.exports = {
5556 requiresTypeChecking : true ,
5657 url : 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-property-in-node.md' ,
5758 } ,
58- schema : [ ] ,
59+ schema : [
60+ {
61+ type : 'object' ,
62+ properties : {
63+ additionalNodeTypeFiles : {
64+ description :
65+ 'Any additional regular expressions to consider source files defining AST Node types.' ,
66+ elements : { type : 'string' } ,
67+ type : 'array' ,
68+ } ,
69+ } ,
70+ additionalProperties : false ,
71+ } ,
72+ ] ,
5973 messages : {
6074 in : 'Prefer checking specific node properties instead of a broad `in`.' ,
6175 } ,
6276 } ,
6377
6478 create ( context ) {
79+ const typedNodeSourceFileTesters = [
80+ ...defaultTypedNodeSourceFileTesters ,
81+ ...( context . options [ 0 ] ?. additionalNodeTypeFiles ?. map (
82+ ( filePath ) => new RegExp ( filePath ) ,
83+ ) ?? [ ] ) ,
84+ ] ;
85+
6586 return {
6687 'BinaryExpression[operator=in]' ( node ) {
6788 // TODO: Switch this to ESLintUtils.getParserServices with typescript-eslint@>=6
@@ -77,7 +98,7 @@ module.exports = {
7798 const tsNode = services . esTreeNodeToTSNodeMap . get ( node . right ) ;
7899 const type = checker . getTypeAtLocation ( tsNode ) ;
79100
80- if ( isAstNodeType ( type ) ) {
101+ if ( isAstNodeType ( type , typedNodeSourceFileTesters ) ) {
81102 context . report ( { messageId : 'in' , node } ) ;
82103 }
83104 } ,
0 commit comments