MCPcopy Create free account
hub / github.com/angular/components / visitGetAccessor

Method visitGetAccessor

tools/tslint-rules/noPrivateGettersRule.ts:25–54  ·  view source on GitHub ↗
(getter: ts.GetAccessorDeclaration)

Source from the content-addressed store, hash-verified

23 }
24
25 override visitGetAccessor(getter: ts.GetAccessorDeclaration) {
26 const getterName = getter.name.getText();
27 const matchesPattern = !this._pattern || this._pattern.test(getterName);
28 const isPrivate = getter.modifiers?.some(modifier => {
29 return modifier.kind === ts.SyntaxKind.PrivateKeyword;
30 });
31
32 // Verify that the getter either matches the configured or is private and it's part of a class.
33 if (
34 (!matchesPattern && !isPrivate) ||
35 !getter.parent ||
36 !ts.isClassDeclaration(getter.parent)
37 ) {
38 return super.visitGetAccessor(getter);
39 }
40
41 const setter = getter.parent.members.find(member => {
42 return ts.isSetAccessorDeclaration(member) && member.name.getText() === getterName;
43 }) as ts.SetAccessorDeclaration | undefined;
44
45 // Only log a failure if it doesn't have a corresponding setter.
46 if (!setter) {
47 this.addFailureAtNode(
48 getter.name,
49 'Private getters generate unnecessary ' + 'code. Use a function instead.',
50 );
51 }
52
53 return super.visitGetAccessor(getter);
54 }
55}

Callers

nothing calls this directly

Calls 1

getTextMethod · 0.45

Tested by

no test coverage detected