11import { Rule } from "eslint" ;
22import { JSXOpeningElement , JSXAttribute } from "estree-jsx" ;
3- import { getFromPackage , checkMatchingJSXOpeningElement } from "../../helpers" ;
3+ import { getFromPackage , checkMatchingJSXOpeningElement , getNodeName } from "../../helpers" ;
44import { getAttribute , getAttributeValue } from "../../helpers/JSXAttributes" ;
55
66// Rule to add hasAnimations prop to components that support animations
@@ -40,12 +40,10 @@ module.exports = {
4040 targetComponents . includes ( specifier . imported . name )
4141 ) ;
4242
43- // Only include Table if option is set
44- const targetTableImports = includeTable
45- ? tableImports . filter ( ( specifier ) =>
46- tableComponents . includes ( specifier . imported . name )
47- )
48- : [ ] ;
43+ // Always include Table imports for detection, but only add hasAnimations if includeTable is true
44+ const targetTableImports = tableImports . filter ( ( specifier ) =>
45+ tableComponents . includes ( specifier . imported . name )
46+ ) ;
4947
5048 const allTargetImports = [ ...targetCoreImports , ...targetTableImports ] ;
5149
@@ -77,20 +75,14 @@ module.exports = {
7775 return true ;
7876 }
7977
80- // Helper function to get component name from node
81- function getComponentName ( node : JSXOpeningElement ) : string | null {
82- if ( node . name . type === "JSXIdentifier" ) {
83- return node . name . name ;
84- }
85- return null ;
86- }
78+
8779
8880 return allTargetImports . length === 0
8981 ? { }
9082 : {
9183 JSXOpeningElement ( node : JSXOpeningElement ) {
9284 if ( checkMatchingJSXOpeningElement ( node , allTargetImports ) ) {
93- const componentName = getComponentName ( node ) ;
85+ const componentName = getNodeName ( node ) ;
9486
9587 // Special handling for DualListSelector - only add hasAnimations if isTree is true
9688 if ( componentName === "DualListSelector" && ! hasValidIsTreeProp ( node ) ) {
@@ -107,10 +99,13 @@ module.exports = {
10799
108100 // Only add prop if it doesn't already exist
109101 if ( ! hasAnimationsAttribute ) {
102+ // For Table, only apply the fix if includeTable is true
103+ const shouldApplyFix = componentName !== "Table" || includeTable ;
104+
110105 context . report ( {
111106 node,
112107 message,
113- fix ( fixer ) {
108+ fix : shouldApplyFix ? ( fixer ) => {
114109 // Insert hasAnimations at the end of existing attributes
115110 if ( node . attributes . length > 0 ) {
116111 const lastAttribute = node . attributes [ node . attributes . length - 1 ] ;
@@ -119,7 +114,7 @@ module.exports = {
119114 // No existing attributes, insert after component name
120115 return fixer . insertTextAfter ( node . name , " hasAnimations" ) ;
121116 }
122- } ,
117+ } : undefined ,
123118 } ) ;
124119 }
125120 }
0 commit comments