| 49 | } |
| 50 | |
| 51 | export class AngularAnalyzer implements FrameworkAnalyzer { |
| 52 | readonly name = 'angular'; |
| 53 | readonly version = '1.0.0'; |
| 54 | readonly supportedExtensions = ['.ts', '.js', '.html', '.scss', '.css', '.sass', '.less']; |
| 55 | readonly priority = 100; // Highest priority for Angular files |
| 56 | |
| 57 | constructor() { |
| 58 | // Self-register Angular-specific complementary patterns. |
| 59 | // computed + effect are complementary, not conflicting. |
| 60 | registerComplementaryPatterns('reactivity', ['Computed', 'Effect']); |
| 61 | } |
| 62 | |
| 63 | private angularPatterns = { |
| 64 | component: /@Component\s*\(/, |
| 65 | service: /@Injectable\s*\(/, |
| 66 | directive: /@Directive\s*\(/, |
| 67 | pipe: /@Pipe\s*\(/, |
| 68 | module: /@NgModule\s*\(/, |
| 69 | // Guards: Check for interface implementation OR method signature OR functional guard |
| 70 | guard: |
| 71 | /(?:implements\s+(?:CanActivate|CanDeactivate|CanLoad|CanMatch)|canActivate\s*\(|canDeactivate\s*\(|canLoad\s*\(|canMatch\s*\(|CanActivateFn|CanDeactivateFn|CanMatchFn)/, |
| 72 | interceptor: /(?:implements\s+HttpInterceptor|intercept\s*\(|HttpInterceptorFn)/, |
| 73 | resolver: /(?:implements\s+Resolve|resolve\s*\(|ResolveFn)/, |
| 74 | validator: /(?:implements\s+(?:Validator|AsyncValidator)|validate\s*\()/ |
| 75 | }; |
| 76 | |
| 77 | private stateManagementPatterns = { |
| 78 | ngrx: /@ngrx\/store|createAction|createReducer|createSelector/, |
| 79 | akita: /@datorama\/akita|Query|Store\.update/, |
| 80 | elf: /@ngneat\/elf|createStore|withEntities/, |
| 81 | signals: /\bsignal\s*[<(]|\bcomputed\s*[<(]|\beffect\s*\(|\blinkedSignal\s*[<(]/, |
| 82 | rxjsState: /BehaviorSubject|ReplaySubject|shareReplay/ |
| 83 | }; |
| 84 | |
| 85 | private modernAngularPatterns = { |
| 86 | signalInput: /\binput\s*[<(]|\binput\.required\s*[<(]/, |
| 87 | signalOutput: /\boutput\s*[<(]/, |
| 88 | signalModel: /\bmodel\s*[<(]|\bmodel\.required\s*[<(]/, |
| 89 | signalViewChild: /\bviewChild\s*[<(]|\bviewChild\.required\s*[<(]/, |
| 90 | signalViewChildren: /\bviewChildren\s*[<(]/, |
| 91 | signalContentChild: /\bcontentChild\s*[<(]|\bcontentChild\.required\s*[<(]/, |
| 92 | signalContentChildren: /\bcontentChildren\s*[<(]/, |
| 93 | controlFlowIf: /@if\s*\(/, |
| 94 | controlFlowFor: /@for\s*\(/, |
| 95 | controlFlowSwitch: /@switch\s*\(/, |
| 96 | controlFlowDefer: /@defer\s*[({]/, |
| 97 | injectFunction: /\binject\s*[<(]/ |
| 98 | }; |
| 99 | |
| 100 | canAnalyze(filePath: string, content?: string): boolean { |
| 101 | const ext = path.extname(filePath).toLowerCase(); |
| 102 | if (!this.supportedExtensions.includes(ext)) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | // For TypeScript files, check if it contains Angular decorators |
| 107 | if (ext === '.ts' && content) { |
| 108 | return Object.values(this.angularPatterns).some((pattern) => pattern.test(content)); |
nothing calls this directly
no outgoing calls
no test coverage detected