@@ -133,50 +133,6 @@ func hasDecorators(node *ast.Node) bool {
133
133
return ast .GetCombinedModifierFlags (node )& ast .ModifierFlagsDecorator != 0
134
134
}
135
135
136
- func findPublicKeywordRange (ctx rule.RuleContext , node * ast.Node ) (core.TextRange , core.TextRange ) {
137
- var modifiers * ast.ModifierList
138
- switch kind := node .Kind ; kind {
139
- case ast .KindMethodDeclaration :
140
- modifiers = node .AsMethodDeclaration ().Modifiers ()
141
- case ast .KindPropertyDeclaration :
142
- modifiers = node .AsPropertyDeclaration ().Modifiers ()
143
- case ast .KindGetAccessor :
144
- modifiers = node .AsGetAccessorDeclaration ().Modifiers ()
145
- case ast .KindSetAccessor :
146
- modifiers = node .AsSetAccessorDeclaration ().Modifiers ()
147
- case ast .KindConstructor :
148
- modifiers = node .AsConstructorDeclaration ().Modifiers ()
149
- case ast .KindParameter :
150
- modifiers = node .AsParameterDeclaration ().Modifiers ()
151
- }
152
-
153
- if modifiers == nil {
154
- return core .NewTextRange (0 , 0 ), core .NewTextRange (0 , 0 )
155
- }
156
-
157
- for i , mod := range modifiers .Nodes {
158
- if mod .Kind == ast .KindPublicKeyword {
159
- keywordRange := core .NewTextRange (mod .Pos (), mod .End ())
160
-
161
- // Calculate range to remove (including following whitespace)
162
- removeEnd := mod .End ()
163
- if i + 1 < len (modifiers .Nodes ) {
164
- removeEnd = modifiers .Nodes [i + 1 ].Pos ()
165
- } else {
166
- // Find next token after public keyword
167
- text := ctx .SourceFile .Text ()
168
- for removeEnd < len (text ) && (text [removeEnd ] == ' ' || text [removeEnd ] == '\t' ) {
169
- removeEnd ++
170
- }
171
- }
172
-
173
- removeRange := core .NewTextRange (mod .Pos (), removeEnd )
174
- return keywordRange , removeRange
175
- }
176
- }
177
-
178
- return core .NewTextRange (0 , 0 ), core .NewTextRange (0 , 0 )
179
- }
180
136
181
137
func getMemberName (node * ast.Node , ctx rule.RuleContext ) string {
182
138
var nameNode * ast.Node
@@ -550,135 +506,4 @@ var ExplicitMemberAccessibilityRule = rule.Rule{
550
506
},
551
507
}
552
508
553
- func getMissingAccessibilitySuggestions (node * ast.Node , ctx rule.RuleContext ) []rule.RuleSuggestion {
554
- suggestions := []rule.RuleSuggestion {}
555
- accessibilities := []string {"public" , "private" , "protected" }
556
-
557
- for _ , accessibility := range accessibilities {
558
- insertPos := node .Pos ()
559
- insertText := accessibility + " "
560
-
561
- // If node has decorators, insert after the last decorator
562
- if hasDecorators (node ) {
563
- // Get the modifiers list to find decorator positions
564
- var modifiers * ast.ModifierList
565
- switch node .Kind {
566
- case ast .KindMethodDeclaration :
567
- modifiers = node .AsMethodDeclaration ().Modifiers ()
568
- case ast .KindPropertyDeclaration :
569
- modifiers = node .AsPropertyDeclaration ().Modifiers ()
570
- case ast .KindGetAccessor :
571
- modifiers = node .AsGetAccessorDeclaration ().Modifiers ()
572
- case ast .KindSetAccessor :
573
- modifiers = node .AsSetAccessorDeclaration ().Modifiers ()
574
- }
575
509
576
- if modifiers != nil {
577
- // Find the last decorator
578
- var lastDecoratorEnd = - 1
579
- for _ , mod := range modifiers .Nodes {
580
- if mod .Kind == ast .KindDecorator && mod .End () > lastDecoratorEnd {
581
- lastDecoratorEnd = mod .End ()
582
- }
583
- }
584
-
585
- if lastDecoratorEnd > 0 {
586
- // Insert after the last decorator
587
- insertPos = lastDecoratorEnd
588
- // Add space after decorator if not already present
589
- text := string (ctx .SourceFile .Text ())
590
- if insertPos < len (text ) && text [insertPos ] != ' ' && text [insertPos ] != '\n' {
591
- insertText = " " + insertText
592
- }
593
- }
594
- }
595
- }
596
-
597
- // For abstract members, insert after "abstract" keyword
598
- if isAbstract (node ) {
599
- var modifiers * ast.ModifierList
600
- switch node .Kind {
601
- case ast .KindMethodDeclaration :
602
- modifiers = node .AsMethodDeclaration ().Modifiers ()
603
- case ast .KindPropertyDeclaration :
604
- modifiers = node .AsPropertyDeclaration ().Modifiers ()
605
- }
606
-
607
- if modifiers != nil {
608
- for _ , mod := range modifiers .Nodes {
609
- if mod .Kind == ast .KindAbstractKeyword {
610
- insertPos = mod .Pos ()
611
- insertText = accessibility + " abstract "
612
- break
613
- }
614
- }
615
- }
616
- }
617
-
618
- // For accessor properties, insert before "accessor" keyword
619
- if isAccessorProperty (node ) {
620
- prop := node .AsPropertyDeclaration ()
621
- if prop .Modifiers () != nil {
622
- for _ , mod := range prop .Modifiers ().Nodes {
623
- if mod .Kind == ast .KindAccessorKeyword {
624
- insertPos = mod .Pos ()
625
- break
626
- }
627
- }
628
- }
629
- }
630
-
631
- suggestions = append (suggestions , rule.RuleSuggestion {
632
- Message : rule.RuleMessage {
633
- Id : "addExplicitAccessibility" ,
634
- Description : fmt .Sprintf ("Add '%s' accessibility modifier" , accessibility ),
635
- },
636
- FixesArr : []rule.RuleFix {
637
- {
638
- Range : core .NewTextRange (insertPos , insertPos ),
639
- Text : insertText ,
640
- },
641
- },
642
- })
643
- }
644
-
645
- return suggestions
646
- }
647
-
648
- func getParameterPropertyAccessibilitySuggestions (node * ast.Node , ctx rule.RuleContext ) []rule.RuleSuggestion {
649
- suggestions := []rule.RuleSuggestion {}
650
- accessibilities := []string {"public" , "private" , "protected" }
651
-
652
- param := node .AsParameterDeclaration ()
653
- if param == nil || param .Modifiers () == nil {
654
- return suggestions
655
- }
656
-
657
- for _ , accessibility := range accessibilities {
658
- insertPos := param .Pos ()
659
- insertText := accessibility + " "
660
-
661
- // If parameter has readonly, insert before readonly
662
- for _ , mod := range param .Modifiers ().Nodes {
663
- if mod .Kind == ast .KindReadonlyKeyword {
664
- insertPos = mod .Pos ()
665
- break
666
- }
667
- }
668
-
669
- suggestions = append (suggestions , rule.RuleSuggestion {
670
- Message : rule.RuleMessage {
671
- Id : "addExplicitAccessibility" ,
672
- Description : fmt .Sprintf ("Add '%s' accessibility modifier" , accessibility ),
673
- },
674
- FixesArr : []rule.RuleFix {
675
- {
676
- Range : core .NewTextRange (insertPos , insertPos ),
677
- Text : insertText ,
678
- },
679
- },
680
- })
681
- }
682
-
683
- return suggestions
684
- }
0 commit comments