@@ -27,39 +27,55 @@ const noRepeatedMemberAccess = createRule({
27
27
defaultOptions : [ { minOccurrences : 3 } ] ,
28
28
29
29
create ( context , [ options ] ) {
30
+ // consider:
31
+ // 1. a map to store [[scope, memberExpression[]], { count: number, modified: boolean }]
32
+ // 2. process every statement we have
33
+ // if it is a memberExpression, go through all its nodes and increase their count in the map
34
+ // in case of assignment, update the modified flag for all nodes in the chain
35
+ // 3. at the end of the scope, check if any of the chains have count >= minOccurrences
36
+ // if so, report the issue and provide a fix to extract the chain into a variable
30
37
const sourceCode = context . sourceCode ;
31
38
const minOccurrences = options . minOccurrences ;
32
39
33
- type scopeKey = [ Scope . Scope , TSESTree . MemberExpression [ ] ] ;
40
+ // type scopeKey = [Scope.Scope, TSESTree.MemberExpression[]];
34
41
type scopeValue = { count : number ; modified : boolean } ;
35
- const scopeMap = new WeakMap < scopeKey , scopeValue > ( ) ;
42
+ const scopeMap = new WeakMap < TSESTree . MemberExpression [ ] , scopeValue > ( ) ;
43
+
44
+ function trackModification ( node : TSESTree . MemberExpression ) {
45
+ scopeMap [ node ] . modified = true ;
46
+ }
47
+ function processMemberExpression ( node : TSESTree . MemberExpression ) { }
48
+
36
49
// ======================
37
50
// Rule Listeners
38
51
// ======================
39
52
// These event handlers process different AST node types and track chain usage
40
53
//
41
54
// Examples of what each listener detects:
42
- // - MemberExpression: obj.prop.val
43
55
// - AssignmentExpression: obj.prop.val = 5
44
56
// - UpdateExpression: obj.prop.val++
45
57
// - CallExpression: obj.prop.method()
58
+ // - MemberExpression: obj.prop.val
46
59
return {
47
60
// Track assignment expression
48
61
// Example: obj.prop.val = 5
49
62
AssignmentExpression : ( node ) => {
50
- // track left expression and mark all of them to be modified
63
+ if ( node . left . type === AST_NODE_TYPES . MemberExpression ) {
64
+ }
51
65
} ,
52
66
53
67
// Track increment/decrement operations
54
68
// Example: obj.prop.counter++ modifies "obj.prop.counter"
55
69
UpdateExpression : ( node ) => {
56
- // track expression and mark all of them to be modified
70
+ if ( node . argument . type === AST_NODE_TYPES . MemberExpression ) {
71
+ }
57
72
} ,
58
73
59
74
// Track function calls that might modify their arguments
60
75
// Example: obj.methods.update() might modify the "obj.methods" chain
61
76
CallExpression : ( node ) => {
62
- // track expression and mark all of them to be modified
77
+ if ( node . callee . type === AST_NODE_TYPES . MemberExpression ) {
78
+ }
63
79
} ,
64
80
65
81
// Process member expressions to identify repeated patterns
0 commit comments