@archest/vitest 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -764
- package/dist/index.mjs.map +1 -1
- package/dist/matchers/index.d.ts +21 -0
- package/dist/matchers/models.d.ts +201 -0
- package/node_modules/@archest/core/dist/classes/locateClasses.d.ts +5 -0
- package/node_modules/@archest/core/dist/classes/types.d.ts +25 -0
- package/node_modules/@archest/core/dist/dto.d.ts +78 -0
- package/node_modules/@archest/core/dist/files/checkDependOnExternalModule.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/getFileDependencies.d.ts +2 -0
- package/node_modules/@archest/core/dist/files/locateFiles.d.ts +4 -0
- package/node_modules/@archest/core/dist/files/types.d.ts +17 -0
- package/node_modules/@archest/core/dist/functions/locateFunctions.d.ts +5 -0
- package/node_modules/@archest/core/dist/functions/types.d.ts +19 -0
- package/node_modules/@archest/core/dist/index.d.ts +43 -0
- package/node_modules/@archest/core/dist/index.js +14 -0
- package/node_modules/@archest/core/dist/index.js.map +1 -0
- package/node_modules/@archest/core/dist/index.mjs +615 -0
- package/node_modules/@archest/core/dist/index.mjs.map +1 -0
- package/node_modules/@archest/core/dist/layers/createLayeredArchitecture.d.ts +3 -0
- package/node_modules/@archest/core/dist/layers/getLayerDependencies.d.ts +2 -0
- package/node_modules/@archest/core/dist/layers/types.d.ts +8 -0
- package/node_modules/@archest/core/dist/project/parseProject.d.ts +55 -0
- package/node_modules/@archest/core/dist/properties/locateProperties.d.ts +5 -0
- package/node_modules/@archest/core/dist/properties/types.d.ts +17 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveMaxCyclomaticComplexity.d.ts +1 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveMinMaintainabilityIndex.d.ts +1 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveModifier.d.ts +7 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveNameMatchingFileName.d.ts +3 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckMatchNamePattern.d.ts +1 -0
- package/node_modules/@archest/core/dist/slices/locateSlices.d.ts +3 -0
- package/node_modules/@archest/core/dist/slices/types.d.ts +8 -0
- package/node_modules/@archest/core/package.json +49 -0
- package/node_modules/@archest/core-rust/core-rust.darwin-arm64.node +0 -0
- package/node_modules/@archest/core-rust/core-rust.linux-x64-gnu.node +0 -0
- package/node_modules/@archest/core-rust/core-rust.win32-x64-msvc.node +0 -0
- package/node_modules/@archest/core-rust/index.d.ts +16 -0
- package/node_modules/@archest/core-rust/index.js +316 -0
- package/node_modules/@archest/core-rust/package.json +34 -0
- package/package.json +12 -1
- package/dist/src/core/classes/locateClasses.d.ts +0 -3
- package/dist/src/core/classes/types.d.ts +0 -14
- package/dist/src/core/files/getFileDependencies.d.ts +0 -2
- package/dist/src/core/files/locateFiles.d.ts +0 -3
- package/dist/src/core/files/types.d.ts +0 -10
- package/dist/src/core/functions/locateFunctions.d.ts +0 -3
- package/dist/src/core/functions/types.d.ts +0 -11
- package/dist/src/core/layers/createLayeredArchitecture.d.ts +0 -3
- package/dist/src/core/layers/getLayerDependencies.d.ts +0 -2
- package/dist/src/core/layers/types.d.ts +0 -8
- package/dist/src/core/project/parseProject.d.ts +0 -22
- package/dist/src/core/properties/locateProperties.d.ts +0 -3
- package/dist/src/core/properties/types.d.ts +0 -10
- package/dist/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.d.ts +0 -1
- package/dist/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.d.ts +0 -1
- package/dist/src/core/shared/sharedCheckHaveModifier.d.ts +0 -2
- package/dist/src/core/shared/sharedCheckHaveNameMatchingFileName.d.ts +0 -2
- package/dist/src/core/shared/sharedCheckMatchNamePattern.d.ts +0 -1
- package/dist/src/core/slices/locateSlices.d.ts +0 -3
- package/dist/src/core/slices/types.d.ts +0 -8
- package/dist/src/index.d.ts +0 -35
- package/dist/src/matchers/index.d.ts +0 -20
- package/src/core/classes/classCheckExtendClass.test.ts +0 -30
- package/src/core/classes/classCheckExtendClass.ts +0 -41
- package/src/core/classes/classCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
- package/src/core/classes/classCheckHaveMaxCyclomaticComplexity.ts +0 -35
- package/src/core/classes/classCheckHaveModifier.test.ts +0 -30
- package/src/core/classes/classCheckHaveModifier.ts +0 -17
- package/src/core/classes/classCheckHaveNameMatchingFileName.test.ts +0 -30
- package/src/core/classes/classCheckHaveNameMatchingFileName.ts +0 -15
- package/src/core/classes/classCheckImplementInterface.test.ts +0 -30
- package/src/core/classes/classCheckImplementInterface.ts +0 -43
- package/src/core/classes/classCheckMatchNamePattern.test.ts +0 -8
- package/src/core/classes/classCheckMatchNamePattern.ts +0 -17
- package/src/core/classes/classCheckResideInFolder.test.ts +0 -8
- package/src/core/classes/classCheckResideInFolder.ts +0 -31
- package/src/core/classes/locateClasses.test.ts +0 -13
- package/src/core/classes/locateClasses.ts +0 -127
- package/src/core/classes/types.ts +0 -16
- package/src/core/files/checkDependOnFilesInFolder.test.ts +0 -7
- package/src/core/files/checkDependOnFilesInFolder.ts +0 -36
- package/src/core/files/fileCheckBeFreeOfCycles.test.ts +0 -7
- package/src/core/files/fileCheckBeFreeOfCycles.ts +0 -72
- package/src/core/files/fileCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
- package/src/core/files/fileCheckHaveMaxCyclomaticComplexity.ts +0 -35
- package/src/core/files/fileCheckHaveMaxExportedFunctions.test.ts +0 -32
- package/src/core/files/fileCheckHaveMaxExportedFunctions.ts +0 -45
- package/src/core/files/fileCheckHaveMinMaintainabilityIndex.test.ts +0 -8
- package/src/core/files/fileCheckHaveMinMaintainabilityIndex.ts +0 -19
- package/src/core/files/fileCheckMatchNamePattern.test.ts +0 -30
- package/src/core/files/fileCheckMatchNamePattern.ts +0 -17
- package/src/core/files/getFileDependencies.ts +0 -43
- package/src/core/files/locateFiles.test.ts +0 -30
- package/src/core/files/locateFiles.ts +0 -31
- package/src/core/files/types.ts +0 -12
- package/src/core/functions/functionCheckHaveExplicitReturnType.test.ts +0 -30
- package/src/core/functions/functionCheckHaveExplicitReturnType.ts +0 -29
- package/src/core/functions/functionCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
- package/src/core/functions/functionCheckHaveMaxCyclomaticComplexity.ts +0 -20
- package/src/core/functions/functionCheckHaveMinMaintainabilityIndex.test.ts +0 -8
- package/src/core/functions/functionCheckHaveMinMaintainabilityIndex.ts +0 -20
- package/src/core/functions/functionCheckHaveModifier.test.ts +0 -30
- package/src/core/functions/functionCheckHaveModifier.ts +0 -18
- package/src/core/functions/functionCheckHaveNameMatchingFileName.test.ts +0 -30
- package/src/core/functions/functionCheckHaveNameMatchingFileName.ts +0 -16
- package/src/core/functions/functionCheckMatchNamePattern.test.ts +0 -30
- package/src/core/functions/functionCheckMatchNamePattern.ts +0 -18
- package/src/core/functions/locateFunctions.test.ts +0 -16
- package/src/core/functions/locateFunctions.ts +0 -47
- package/src/core/functions/types.ts +0 -13
- package/src/core/layers/checkLayeredArchitecture.test.ts +0 -23
- package/src/core/layers/checkLayeredArchitecture.ts +0 -15
- package/src/core/layers/createLayeredArchitecture.test.ts +0 -13
- package/src/core/layers/createLayeredArchitecture.ts +0 -15
- package/src/core/layers/getLayerDependencies.ts +0 -45
- package/src/core/layers/layer.test.ts +0 -12
- package/src/core/layers/layer.ts +0 -10
- package/src/core/layers/layerShouldNotBeAccessedByAnyLayer.test.ts +0 -14
- package/src/core/layers/layerShouldNotBeAccessedByAnyLayer.ts +0 -40
- package/src/core/layers/layerShouldOnlyBeAccessedBy.test.ts +0 -15
- package/src/core/layers/layerShouldOnlyBeAccessedBy.ts +0 -48
- package/src/core/layers/types.ts +0 -9
- package/src/core/metrics/calculateCyclomaticComplexity.test.ts +0 -23
- package/src/core/metrics/calculateCyclomaticComplexity.ts +0 -36
- package/src/core/metrics/calculateMaintainabilityIndex.test.ts +0 -38
- package/src/core/metrics/calculateMaintainabilityIndex.ts +0 -47
- package/src/core/project/parseProject.test.ts +0 -19
- package/src/core/project/parseProject.ts +0 -216
- package/src/core/properties/locateProperties.test.ts +0 -19
- package/src/core/properties/locateProperties.ts +0 -41
- package/src/core/properties/propertyCheckBeReadonly.test.ts +0 -32
- package/src/core/properties/propertyCheckBeReadonly.ts +0 -27
- package/src/core/properties/types.ts +0 -12
- package/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.test.ts +0 -30
- package/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.ts +0 -23
- package/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.test.ts +0 -30
- package/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.ts +0 -23
- package/src/core/shared/sharedCheckHaveModifier.test.ts +0 -31
- package/src/core/shared/sharedCheckHaveModifier.ts +0 -51
- package/src/core/shared/sharedCheckHaveNameMatchingFileName.test.ts +0 -17
- package/src/core/shared/sharedCheckHaveNameMatchingFileName.ts +0 -36
- package/src/core/shared/sharedCheckMatchNamePattern.test.ts +0 -29
- package/src/core/shared/sharedCheckMatchNamePattern.ts +0 -22
- package/src/core/slices/locateSlices.test.ts +0 -22
- package/src/core/slices/locateSlices.ts +0 -35
- package/src/core/slices/sliceCheckBeFreeOfCycles.test.ts +0 -26
- package/src/core/slices/sliceCheckBeFreeOfCycles.ts +0 -91
- package/src/core/slices/sliceCheckHaveMaxDistanceFromMainSequence.test.ts +0 -27
- package/src/core/slices/sliceCheckHaveMaxDistanceFromMainSequence.ts +0 -110
- package/src/core/slices/types.ts +0 -9
- package/src/core/testUtils.ts +0 -61
- package/src/core/types.ts +0 -19
- package/src/core/utils/ruleBuilder.test.ts +0 -24
- package/src/core/utils/ruleBuilder.ts +0 -28
- package/src/index.ts +0 -35
- package/src/matchers/index.ts +0 -331
- package/test/architecture.test.ts +0 -152
- package/tsconfig.json +0 -18
- package/vite.config.ts +0 -18
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckExtendClass.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveModifier.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveNameMatchingFileName.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckImplementInterface.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckMatchNamePattern.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckResideInFolder.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/checkDependOnFilesInFolder.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckBeFreeOfCycles.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMaxExportedFunctions.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMinMaintainabilityIndex.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckMatchNamePattern.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveExplicitReturnType.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveMinMaintainabilityIndex.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveModifier.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveNameMatchingFileName.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckMatchNamePattern.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/layers/checkLayeredArchitecture.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layer.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layerShouldNotBeAccessedByAnyLayer.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layerShouldOnlyBeAccessedBy.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/metrics/calculateCyclomaticComplexity.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/metrics/calculateMaintainabilityIndex.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/properties/propertyCheckBeReadonly.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/slices/sliceCheckBeFreeOfCycles.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/slices/sliceCheckHaveMaxDistanceFromMainSequence.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/types.d.ts +0 -0
- /package/{dist/src/core → node_modules/@archest/core/dist}/utils/ruleBuilder.d.ts +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import type { RuleResult } from '../types';
|
|
3
|
-
import type { FileLocatorData } from './types';
|
|
4
|
-
|
|
5
|
-
export function fileCheckHaveMaxExportedFunctions(
|
|
6
|
-
locator: FileLocatorData,
|
|
7
|
-
max: number,
|
|
8
|
-
isNot: boolean,
|
|
9
|
-
): RuleResult {
|
|
10
|
-
const violations: string[] = [];
|
|
11
|
-
for (const file of locator.files) {
|
|
12
|
-
let exportedFuncCount = 0;
|
|
13
|
-
|
|
14
|
-
ts.forEachChild(file, (node) => {
|
|
15
|
-
if (ts.isFunctionDeclaration(node)) {
|
|
16
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
17
|
-
? ts.getModifiers(node)
|
|
18
|
-
: undefined;
|
|
19
|
-
if (modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
20
|
-
exportedFuncCount++;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const exceeds = exportedFuncCount > max;
|
|
26
|
-
|
|
27
|
-
if (isNot && exceeds) {
|
|
28
|
-
violations.push(
|
|
29
|
-
`File ${file.fileName} has ${exportedFuncCount} exported functions, which exceeds the maximum of ${max}, but it shouldn't.`,
|
|
30
|
-
);
|
|
31
|
-
} else if (!isNot && exceeds) {
|
|
32
|
-
violations.push(
|
|
33
|
-
`File ${file.fileName} has ${exportedFuncCount} exported functions, which exceeds the maximum of ${max}.`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
pass: isNot ? violations.length > 0 : violations.length === 0,
|
|
39
|
-
message: () =>
|
|
40
|
-
violations.join('\n') ||
|
|
41
|
-
(isNot
|
|
42
|
-
? 'Expected some files to exceed maximum exported functions, but none did.'
|
|
43
|
-
: ''),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { fileCheckHaveMinMaintainabilityIndex } from './fileCheckHaveMinMaintainabilityIndex';
|
|
3
|
-
|
|
4
|
-
describe('fileCheckHaveMinMaintainabilityIndex', () => {
|
|
5
|
-
it('should exist and be callable', () => {
|
|
6
|
-
expect(typeof fileCheckHaveMinMaintainabilityIndex).toBe('function');
|
|
7
|
-
});
|
|
8
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { calculateMaintainabilityIndex } from '../metrics/calculateMaintainabilityIndex';
|
|
2
|
-
import { sharedCheckHaveMinMaintainabilityIndex } from '../shared/sharedCheckHaveMinMaintainabilityIndex';
|
|
3
|
-
import type { RuleResult } from '../types';
|
|
4
|
-
import type { FileLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
export function fileCheckHaveMinMaintainabilityIndex(
|
|
7
|
-
locator: FileLocatorData,
|
|
8
|
-
min: number,
|
|
9
|
-
isNot: boolean,
|
|
10
|
-
): RuleResult {
|
|
11
|
-
return sharedCheckHaveMinMaintainabilityIndex(
|
|
12
|
-
locator.files,
|
|
13
|
-
(f) => f.fileName,
|
|
14
|
-
calculateMaintainabilityIndex,
|
|
15
|
-
'File',
|
|
16
|
-
min,
|
|
17
|
-
isNot,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile } from '../testUtils';
|
|
3
|
-
import { fileCheckMatchNamePattern } from './fileCheckMatchNamePattern';
|
|
4
|
-
import type { FileLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
describe('fileCheckMatchNamePattern', () => {
|
|
7
|
-
it('should pass if filename matches', () => {
|
|
8
|
-
const sourceFile = createSourceFile(`// code`, 'src/core/test.ts');
|
|
9
|
-
const data: FileLocatorData = {
|
|
10
|
-
type: 'FileLocator',
|
|
11
|
-
files: [sourceFile],
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
13
|
-
program: {} as any,
|
|
14
|
-
};
|
|
15
|
-
const result = fileCheckMatchNamePattern(data, /.*\.ts$/, false);
|
|
16
|
-
expect(result.pass).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should fail if filename does not match', () => {
|
|
20
|
-
const sourceFile = createSourceFile(`// code`, 'src/core/test.js');
|
|
21
|
-
const data: FileLocatorData = {
|
|
22
|
-
type: 'FileLocator',
|
|
23
|
-
files: [sourceFile],
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
25
|
-
program: {} as any,
|
|
26
|
-
};
|
|
27
|
-
const result = fileCheckMatchNamePattern(data, /.*\.ts$/, false);
|
|
28
|
-
expect(result.pass).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { sharedCheckMatchNamePattern } from '../shared/sharedCheckMatchNamePattern';
|
|
2
|
-
import type { RuleResult } from '../types';
|
|
3
|
-
import type { FileLocatorData } from './types';
|
|
4
|
-
|
|
5
|
-
export function fileCheckMatchNamePattern(
|
|
6
|
-
locator: FileLocatorData,
|
|
7
|
-
pattern: string | RegExp,
|
|
8
|
-
isNot: boolean,
|
|
9
|
-
): RuleResult {
|
|
10
|
-
return sharedCheckMatchNamePattern(
|
|
11
|
-
locator.files,
|
|
12
|
-
(f) => f.fileName,
|
|
13
|
-
'File',
|
|
14
|
-
pattern,
|
|
15
|
-
isNot,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
export function getFileDependencies(
|
|
4
|
-
sourceFile: ts.SourceFile,
|
|
5
|
-
program: ts.Program,
|
|
6
|
-
): string[] {
|
|
7
|
-
const dependencies: string[] = [];
|
|
8
|
-
const compilerOptions = program.getCompilerOptions();
|
|
9
|
-
|
|
10
|
-
const visit = (node: ts.Node) => {
|
|
11
|
-
if (ts.isImportDeclaration(node)) {
|
|
12
|
-
const moduleSpecifier = (node.moduleSpecifier as ts.StringLiteral).text;
|
|
13
|
-
const resolved = ts.resolveModuleName(
|
|
14
|
-
moduleSpecifier,
|
|
15
|
-
sourceFile.fileName,
|
|
16
|
-
compilerOptions,
|
|
17
|
-
ts.sys,
|
|
18
|
-
);
|
|
19
|
-
if (resolved.resolvedModule?.resolvedFileName) {
|
|
20
|
-
if (!resolved.resolvedModule.isExternalLibraryImport) {
|
|
21
|
-
dependencies.push(resolved.resolvedModule.resolvedFileName);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} else if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
25
|
-
const moduleSpecifier = (node.moduleSpecifier as ts.StringLiteral).text;
|
|
26
|
-
const resolved = ts.resolveModuleName(
|
|
27
|
-
moduleSpecifier,
|
|
28
|
-
sourceFile.fileName,
|
|
29
|
-
compilerOptions,
|
|
30
|
-
ts.sys,
|
|
31
|
-
);
|
|
32
|
-
if (resolved.resolvedModule?.resolvedFileName) {
|
|
33
|
-
if (!resolved.resolvedModule.isExternalLibraryImport) {
|
|
34
|
-
dependencies.push(resolved.resolvedModule.resolvedFileName);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
ts.forEachChild(node, visit);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
visit(sourceFile);
|
|
42
|
-
return dependencies;
|
|
43
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile } from '../testUtils';
|
|
3
|
-
import { locateFiles } from './locateFiles';
|
|
4
|
-
|
|
5
|
-
describe('locateFiles', () => {
|
|
6
|
-
it('should filter files by inFolder query', () => {
|
|
7
|
-
const file1 = createSourceFile('function a() {}', 'src/domain/file1.ts');
|
|
8
|
-
const file2 = createSourceFile('function b() {}', 'src/infra/file2.ts');
|
|
9
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
10
|
-
const result = locateFiles([file1, file2], {} as any, {
|
|
11
|
-
inFolder: 'domain',
|
|
12
|
-
});
|
|
13
|
-
expect(result.files.length).toBe(1);
|
|
14
|
-
expect(result.files[0].fileName).toBe('src/domain/file1.ts');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should filter files by matchNamePattern query', () => {
|
|
18
|
-
const file1 = createSourceFile('function a() {}', 'src/domain/file1.ts');
|
|
19
|
-
const file2 = createSourceFile(
|
|
20
|
-
'function b() {}',
|
|
21
|
-
'src/domain/file2.spec.ts',
|
|
22
|
-
);
|
|
23
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
24
|
-
const result = locateFiles([file1, file2], {} as any, {
|
|
25
|
-
matchNamePattern: /\.spec\.ts$/,
|
|
26
|
-
});
|
|
27
|
-
expect(result.files.length).toBe(1);
|
|
28
|
-
expect(result.files[0].fileName).toBe('src/domain/file2.spec.ts');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
|
-
import type { FileLocatorData, FileQueryOptions } from './types';
|
|
3
|
-
|
|
4
|
-
export function locateFiles(
|
|
5
|
-
sourceFiles: ts.SourceFile[],
|
|
6
|
-
program: ts.Program,
|
|
7
|
-
options?: FileQueryOptions,
|
|
8
|
-
): FileLocatorData {
|
|
9
|
-
let filtered = sourceFiles;
|
|
10
|
-
|
|
11
|
-
if (options?.inFolder) {
|
|
12
|
-
filtered = filtered.filter(
|
|
13
|
-
(file) =>
|
|
14
|
-
file.fileName.includes(`/${options.inFolder}/`) ||
|
|
15
|
-
file.fileName.includes(`\\${options.inFolder}\\`),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
if (options?.matchNamePattern) {
|
|
19
|
-
const regex =
|
|
20
|
-
typeof options.matchNamePattern === 'string'
|
|
21
|
-
? new RegExp(options.matchNamePattern)
|
|
22
|
-
: options.matchNamePattern;
|
|
23
|
-
filtered = filtered.filter((file) => regex.test(file.fileName));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
type: 'FileLocator',
|
|
28
|
-
files: filtered,
|
|
29
|
-
program,
|
|
30
|
-
};
|
|
31
|
-
}
|
package/src/core/files/types.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
export interface FileLocatorData {
|
|
4
|
-
type: 'FileLocator';
|
|
5
|
-
files: ts.SourceFile[];
|
|
6
|
-
program: ts.Program;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface FileQueryOptions {
|
|
10
|
-
inFolder?: string;
|
|
11
|
-
matchNamePattern?: string | RegExp;
|
|
12
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile, getFunctions } from '../testUtils';
|
|
3
|
-
import { functionCheckHaveExplicitReturnType } from './functionCheckHaveExplicitReturnType';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
describe('functionCheckHaveExplicitReturnType', () => {
|
|
7
|
-
it('should pass if function has explicit return type', () => {
|
|
8
|
-
const sourceFile = createSourceFile(`function myFunc(): void {}`);
|
|
9
|
-
const data: FunctionLocatorData = {
|
|
10
|
-
type: 'FunctionLocator',
|
|
11
|
-
functions: getFunctions(sourceFile),
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
13
|
-
program: {} as any,
|
|
14
|
-
};
|
|
15
|
-
const result = functionCheckHaveExplicitReturnType(data, false);
|
|
16
|
-
expect(result.pass).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should fail if function lacks explicit return type', () => {
|
|
20
|
-
const sourceFile = createSourceFile(`function myFunc() {}`);
|
|
21
|
-
const data: FunctionLocatorData = {
|
|
22
|
-
type: 'FunctionLocator',
|
|
23
|
-
functions: getFunctions(sourceFile),
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
25
|
-
program: {} as any,
|
|
26
|
-
};
|
|
27
|
-
const result = functionCheckHaveExplicitReturnType(data, false);
|
|
28
|
-
expect(result.pass).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import type { RuleResult } from '../types';
|
|
3
|
-
import type { FunctionLocatorData } from './types';
|
|
4
|
-
|
|
5
|
-
export function functionCheckHaveExplicitReturnType(
|
|
6
|
-
locator: FunctionLocatorData,
|
|
7
|
-
isNot: boolean,
|
|
8
|
-
): RuleResult {
|
|
9
|
-
const violations: string[] = [];
|
|
10
|
-
for (const f of locator.functions) {
|
|
11
|
-
const name =
|
|
12
|
-
f.name && ts.isIdentifier(f.name) ? f.name.text : 'Anonymous Function';
|
|
13
|
-
const hasType = !!f.type;
|
|
14
|
-
|
|
15
|
-
if (isNot && hasType) {
|
|
16
|
-
violations.push(
|
|
17
|
-
`Function ${name} has an explicit return type, but it shouldn't.`,
|
|
18
|
-
);
|
|
19
|
-
} else if (!isNot && !hasType) {
|
|
20
|
-
violations.push(
|
|
21
|
-
`Function ${name} does not have an explicit return type, but it should.`,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
pass: violations.length === 0,
|
|
27
|
-
message: () => violations.join('\n'),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { functionCheckHaveMaxCyclomaticComplexity } from './functionCheckHaveMaxCyclomaticComplexity';
|
|
3
|
-
|
|
4
|
-
describe('functionCheckHaveMaxCyclomaticComplexity', () => {
|
|
5
|
-
it('should exist and be callable', () => {
|
|
6
|
-
expect(typeof functionCheckHaveMaxCyclomaticComplexity).toBe('function');
|
|
7
|
-
});
|
|
8
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { calculateCyclomaticComplexity } from '../metrics/calculateCyclomaticComplexity';
|
|
3
|
-
import { sharedCheckHaveMaxCyclomaticComplexity } from '../shared/sharedCheckHaveMaxCyclomaticComplexity';
|
|
4
|
-
import type { RuleResult } from '../types';
|
|
5
|
-
import type { FunctionLocatorData } from './types';
|
|
6
|
-
|
|
7
|
-
export function functionCheckHaveMaxCyclomaticComplexity(
|
|
8
|
-
locator: FunctionLocatorData,
|
|
9
|
-
max: number,
|
|
10
|
-
isNot: boolean,
|
|
11
|
-
): RuleResult {
|
|
12
|
-
return sharedCheckHaveMaxCyclomaticComplexity(
|
|
13
|
-
locator.functions,
|
|
14
|
-
(f) => (f.name && ts.isIdentifier(f.name) ? f.name.text : undefined),
|
|
15
|
-
calculateCyclomaticComplexity,
|
|
16
|
-
'Function',
|
|
17
|
-
max,
|
|
18
|
-
isNot,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { functionCheckHaveMinMaintainabilityIndex } from './functionCheckHaveMinMaintainabilityIndex';
|
|
3
|
-
|
|
4
|
-
describe('functionCheckHaveMinMaintainabilityIndex', () => {
|
|
5
|
-
it('should exist and be callable', () => {
|
|
6
|
-
expect(typeof functionCheckHaveMinMaintainabilityIndex).toBe('function');
|
|
7
|
-
});
|
|
8
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { calculateMaintainabilityIndex } from '../metrics/calculateMaintainabilityIndex';
|
|
3
|
-
import { sharedCheckHaveMinMaintainabilityIndex } from '../shared/sharedCheckHaveMinMaintainabilityIndex';
|
|
4
|
-
import type { RuleResult } from '../types';
|
|
5
|
-
import type { FunctionLocatorData } from './types';
|
|
6
|
-
|
|
7
|
-
export function functionCheckHaveMinMaintainabilityIndex(
|
|
8
|
-
locator: FunctionLocatorData,
|
|
9
|
-
min: number,
|
|
10
|
-
isNot: boolean,
|
|
11
|
-
): RuleResult {
|
|
12
|
-
return sharedCheckHaveMinMaintainabilityIndex(
|
|
13
|
-
locator.functions,
|
|
14
|
-
(f) => (f.name && ts.isIdentifier(f.name) ? f.name.text : undefined),
|
|
15
|
-
calculateMaintainabilityIndex,
|
|
16
|
-
'Function',
|
|
17
|
-
min,
|
|
18
|
-
isNot,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile, getFunctions } from '../testUtils';
|
|
3
|
-
import { functionCheckHaveModifier } from './functionCheckHaveModifier';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
describe('functionCheckHaveModifier', () => {
|
|
7
|
-
it('should pass if function has modifier', () => {
|
|
8
|
-
const sourceFile = createSourceFile(`export function myFunc() {}`);
|
|
9
|
-
const data: FunctionLocatorData = {
|
|
10
|
-
type: 'FunctionLocator',
|
|
11
|
-
functions: getFunctions(sourceFile),
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
13
|
-
program: {} as any,
|
|
14
|
-
};
|
|
15
|
-
const result = functionCheckHaveModifier(data, 'export', false);
|
|
16
|
-
expect(result.pass).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should fail if function lacks modifier', () => {
|
|
20
|
-
const sourceFile = createSourceFile(`function myFunc() {}`);
|
|
21
|
-
const data: FunctionLocatorData = {
|
|
22
|
-
type: 'FunctionLocator',
|
|
23
|
-
functions: getFunctions(sourceFile),
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
25
|
-
program: {} as any,
|
|
26
|
-
};
|
|
27
|
-
const result = functionCheckHaveModifier(data, 'export', false);
|
|
28
|
-
expect(result.pass).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { sharedCheckHaveModifier } from '../shared/sharedCheckHaveModifier';
|
|
3
|
-
import type { RuleResult } from '../types';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
export function functionCheckHaveModifier(
|
|
7
|
-
locator: FunctionLocatorData,
|
|
8
|
-
modifierStr: string,
|
|
9
|
-
isNot: boolean,
|
|
10
|
-
): RuleResult {
|
|
11
|
-
return sharedCheckHaveModifier(
|
|
12
|
-
locator.functions,
|
|
13
|
-
(f) => (f.name && ts.isIdentifier(f.name) ? f.name.text : undefined),
|
|
14
|
-
'Function',
|
|
15
|
-
modifierStr,
|
|
16
|
-
isNot,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile, getFunctions } from '../testUtils';
|
|
3
|
-
import { functionCheckHaveNameMatchingFileName } from './functionCheckHaveNameMatchingFileName';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
describe('functionCheckHaveNameMatchingFileName', () => {
|
|
7
|
-
it('should pass if function matches filename', () => {
|
|
8
|
-
const sourceFile = createSourceFile(`function test() {}`, 'test.ts');
|
|
9
|
-
const data: FunctionLocatorData = {
|
|
10
|
-
type: 'FunctionLocator',
|
|
11
|
-
functions: getFunctions(sourceFile),
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
13
|
-
program: {} as any,
|
|
14
|
-
};
|
|
15
|
-
const result = functionCheckHaveNameMatchingFileName(data, false);
|
|
16
|
-
expect(result.pass).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should fail if function does not match filename', () => {
|
|
20
|
-
const sourceFile = createSourceFile(`function test() {}`, 'other.ts');
|
|
21
|
-
const data: FunctionLocatorData = {
|
|
22
|
-
type: 'FunctionLocator',
|
|
23
|
-
functions: getFunctions(sourceFile),
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
25
|
-
program: {} as any,
|
|
26
|
-
};
|
|
27
|
-
const result = functionCheckHaveNameMatchingFileName(data, false);
|
|
28
|
-
expect(result.pass).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { sharedCheckHaveNameMatchingFileName } from '../shared/sharedCheckHaveNameMatchingFileName';
|
|
3
|
-
import type { RuleResult } from '../types';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
export function functionCheckHaveNameMatchingFileName(
|
|
7
|
-
locator: FunctionLocatorData,
|
|
8
|
-
isNot: boolean,
|
|
9
|
-
): RuleResult {
|
|
10
|
-
return sharedCheckHaveNameMatchingFileName(
|
|
11
|
-
locator.functions,
|
|
12
|
-
(f) => (f.name && ts.isIdentifier(f.name) ? f.name.text : undefined),
|
|
13
|
-
'Function',
|
|
14
|
-
isNot,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile, getFunctions } from '../testUtils';
|
|
3
|
-
import { functionCheckMatchNamePattern } from './functionCheckMatchNamePattern';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
describe('functionCheckMatchNamePattern', () => {
|
|
7
|
-
it('should pass if function matches pattern', () => {
|
|
8
|
-
const sourceFile = createSourceFile(`function testFunc() {}`);
|
|
9
|
-
const data: FunctionLocatorData = {
|
|
10
|
-
type: 'FunctionLocator',
|
|
11
|
-
functions: getFunctions(sourceFile),
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
13
|
-
program: {} as any,
|
|
14
|
-
};
|
|
15
|
-
const result = functionCheckMatchNamePattern(data, /^test/, false);
|
|
16
|
-
expect(result.pass).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should fail if function does not match pattern', () => {
|
|
20
|
-
const sourceFile = createSourceFile(`function myFunc() {}`);
|
|
21
|
-
const data: FunctionLocatorData = {
|
|
22
|
-
type: 'FunctionLocator',
|
|
23
|
-
functions: getFunctions(sourceFile),
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
25
|
-
program: {} as any,
|
|
26
|
-
};
|
|
27
|
-
const result = functionCheckMatchNamePattern(data, /^test/, false);
|
|
28
|
-
expect(result.pass).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { sharedCheckMatchNamePattern } from '../shared/sharedCheckMatchNamePattern';
|
|
3
|
-
import type { RuleResult } from '../types';
|
|
4
|
-
import type { FunctionLocatorData } from './types';
|
|
5
|
-
|
|
6
|
-
export function functionCheckMatchNamePattern(
|
|
7
|
-
locator: FunctionLocatorData,
|
|
8
|
-
pattern: string | RegExp,
|
|
9
|
-
isNot: boolean,
|
|
10
|
-
): RuleResult {
|
|
11
|
-
return sharedCheckMatchNamePattern(
|
|
12
|
-
locator.functions,
|
|
13
|
-
(f) => (f.name && ts.isIdentifier(f.name) ? f.name.text : undefined),
|
|
14
|
-
'Function',
|
|
15
|
-
pattern,
|
|
16
|
-
isNot,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createSourceFile, getFunctions } from '../testUtils';
|
|
3
|
-
import { locateFunctions } from './locateFunctions';
|
|
4
|
-
|
|
5
|
-
describe('locateFunctions', () => {
|
|
6
|
-
it('should filter functions by matchNamePattern', () => {
|
|
7
|
-
const file1 = createSourceFile('function a() {}; function b() {}');
|
|
8
|
-
const functions = getFunctions(file1);
|
|
9
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
10
|
-
const result = locateFunctions(functions, {} as any, {
|
|
11
|
-
matchNamePattern: 'a',
|
|
12
|
-
});
|
|
13
|
-
expect(result.functions.length).toBe(1);
|
|
14
|
-
expect(result.functions[0].name?.text).toBe('a');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import type { FunctionLocatorData, FunctionQueryOptions } from './types';
|
|
3
|
-
|
|
4
|
-
export function locateFunctions(
|
|
5
|
-
functions: ts.FunctionLikeDeclaration[],
|
|
6
|
-
program: ts.Program,
|
|
7
|
-
options?: FunctionQueryOptions,
|
|
8
|
-
): FunctionLocatorData {
|
|
9
|
-
let filtered = functions;
|
|
10
|
-
|
|
11
|
-
if (options?.inFolder) {
|
|
12
|
-
filtered = filtered.filter((f) => {
|
|
13
|
-
const sourceFile = f.getSourceFile
|
|
14
|
-
? f.getSourceFile()
|
|
15
|
-
: f.parent
|
|
16
|
-
? ts.getSourceFileOfNode(f)
|
|
17
|
-
: undefined;
|
|
18
|
-
if (!sourceFile) return false;
|
|
19
|
-
return (
|
|
20
|
-
sourceFile.fileName.includes(`/${options.inFolder}/`) ||
|
|
21
|
-
sourceFile.fileName.includes(`\\${options.inFolder}\\`)
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (options?.matchNamePattern) {
|
|
27
|
-
const regex =
|
|
28
|
-
typeof options.matchNamePattern === 'string'
|
|
29
|
-
? new RegExp(options.matchNamePattern)
|
|
30
|
-
: options.matchNamePattern;
|
|
31
|
-
filtered = filtered.filter((f) => {
|
|
32
|
-
return f.name && ts.isIdentifier(f.name) && regex.test(f.name.text);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (options?.isTopLevel) {
|
|
37
|
-
filtered = filtered.filter((f) => {
|
|
38
|
-
return ts.isSourceFile(f.parent);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
type: 'FunctionLocator',
|
|
44
|
-
functions: filtered,
|
|
45
|
-
program,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
export interface FunctionLocatorData {
|
|
4
|
-
type: 'FunctionLocator';
|
|
5
|
-
functions: ts.FunctionLikeDeclaration[];
|
|
6
|
-
program: ts.Program;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface FunctionQueryOptions {
|
|
10
|
-
inFolder?: string;
|
|
11
|
-
matchNamePattern?: string | RegExp;
|
|
12
|
-
isTopLevel?: boolean;
|
|
13
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { checkLayeredArchitecture } from './checkLayeredArchitecture';
|
|
3
|
-
import { createLayeredArchitecture } from './createLayeredArchitecture';
|
|
4
|
-
|
|
5
|
-
describe('checkLayeredArchitecture', () => {
|
|
6
|
-
it('should evaluate all assertions and return true if none fail', () => {
|
|
7
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
8
|
-
const data = createLayeredArchitecture([], {} as any);
|
|
9
|
-
data.assertions.push(() => []); // returns no violations
|
|
10
|
-
const result = checkLayeredArchitecture(data);
|
|
11
|
-
expect(result.pass).toBe(true);
|
|
12
|
-
expect(result.message()).toBe('');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return false if any assertion yields violations', () => {
|
|
16
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
17
|
-
const data = createLayeredArchitecture([], {} as any);
|
|
18
|
-
data.assertions.push(() => ['Layer violation!']);
|
|
19
|
-
const result = checkLayeredArchitecture(data);
|
|
20
|
-
expect(result.pass).toBe(false);
|
|
21
|
-
expect(result.message()).toBe('Layer violation!');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { RuleResult } from '../types';
|
|
2
|
-
import type { LayeredArchitectureData } from './types';
|
|
3
|
-
|
|
4
|
-
export function checkLayeredArchitecture(
|
|
5
|
-
data: LayeredArchitectureData,
|
|
6
|
-
): RuleResult {
|
|
7
|
-
const violations: string[] = [];
|
|
8
|
-
for (const assertion of data.assertions) {
|
|
9
|
-
violations.push(...assertion(data.files));
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
pass: violations.length === 0,
|
|
13
|
-
message: () => violations.join('\n'),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createLayeredArchitecture } from './createLayeredArchitecture';
|
|
3
|
-
|
|
4
|
-
describe('createLayeredArchitecture', () => {
|
|
5
|
-
it('should initialize a LayeredArchitectureData object', () => {
|
|
6
|
-
// biome-ignore lint/suspicious/noExplicitAny: Mocking TS types for tests
|
|
7
|
-
const data = createLayeredArchitecture([], {} as any);
|
|
8
|
-
expect(data.type).toBe('LayeredArchitecture');
|
|
9
|
-
expect(data.files).toEqual([]);
|
|
10
|
-
expect(data.layers.size).toBe(0);
|
|
11
|
-
expect(data.assertions.length).toBe(0);
|
|
12
|
-
});
|
|
13
|
-
});
|