Skip to content

Commit 414e8a2

Browse files
devillclaude
andcommitted
Fix quality violations by refactoring oversized function and feature envy
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 833b616 commit 414e8a2

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/dev/quality-checks-extractor.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ interface QualityCheck {
55
getGroupDefinition?: (_key: string) => { title: string; description: string } | undefined;
66
}
77

8+
const buildPossibleKeysForCheck = (check: QualityCheck): string[] => {
9+
return [
10+
check.name,
11+
`${check.name}Functions`,
12+
`critical${check.name.charAt(0).toUpperCase() + check.name.slice(1)}`,
13+
`large${check.name.charAt(0).toUpperCase() + check.name.slice(1)}`,
14+
];
15+
};
16+
817
export class QualityChecksExtractor {
918
extractQualityChecksContent(): string {
1019
const qualityChecks = loadQualityChecks();
@@ -34,19 +43,10 @@ export class QualityChecksExtractor {
3443
}
3544

3645
private getValidGroupKeys(check: QualityCheck): string[] {
37-
const possibleKeys = this.buildPossibleKeys(check);
46+
const possibleKeys = buildPossibleKeysForCheck(check);
3847
return possibleKeys.filter(key => this.isValidKey(check, key));
3948
}
4049

41-
private buildPossibleKeys(check: QualityCheck): string[] {
42-
return [
43-
check.name,
44-
`${check.name}Functions`,
45-
`critical${check.name.charAt(0).toUpperCase() + check.name.slice(1)}`,
46-
`large${check.name.charAt(0).toUpperCase() + check.name.slice(1)}`,
47-
];
48-
}
49-
5050
private isValidKey(check: QualityCheck, key: string): boolean {
5151
try {
5252
return Boolean(check.getGroupDefinition?.(key));

src/dev/quality/checks/require-statements-check.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ const isRequireCall = (node: CallExpression): boolean => {
5555
expression.getText() === 'require';
5656
};
5757

58+
const isFunctionLikeSyntaxKind = (kind: SyntaxKind): boolean => {
59+
return kind === SyntaxKind.FunctionDeclaration ||
60+
kind === SyntaxKind.MethodDeclaration ||
61+
kind === SyntaxKind.ArrowFunction ||
62+
kind === SyntaxKind.FunctionExpression;
63+
};
64+
5865
const isImportInsideFunction = (importDecl: ImportDeclaration): boolean => {
5966
let parent: Node | undefined = importDecl.getParent();
6067

6168
while (parent) {
62-
const kind = parent.getKind();
63-
if (kind === SyntaxKind.FunctionDeclaration ||
64-
kind === SyntaxKind.MethodDeclaration ||
65-
kind === SyntaxKind.ArrowFunction ||
66-
kind === SyntaxKind.FunctionExpression) {
69+
if (isFunctionLikeSyntaxKind(parent.getKind())) {
6770
return true;
6871
}
6972
parent = parent.getParent();

0 commit comments

Comments
 (0)