Skip to content
Open

Tsx #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 135 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
"terminal-link": "^2.1.1",
"ts-morph": "^8.2.0",
"ts-node": "^9.1.1"
},
"devDependencies": {
"@types/react": "^17.0.39",
"react": "^17.0.2"
}
}
1 change: 1 addition & 0 deletions src/core/enum/syntax-kind.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export enum SyntaxKind {
JsxAttributes = 'JsxAttributes',
JsxClosingElement = 'JsxClosingElement',
JsxClosingFragment = 'JsxClosingFragment',
JsxComponent = 'JsxComponent',
JsxElement = 'JsxElement',
JsxExpression = 'JsxExpression',
JsxFragment = 'JsxFragment',
Expand Down
10 changes: 10 additions & 0 deletions src/core/mocks/tsx/tsx.mock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

const component = () => {
console.log('TSX MOCKKKK');
return (
<div>
<p>Some text</p>
</div>
)
}
2 changes: 1 addition & 1 deletion src/index-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ENABLE_CONSOLE_REPORT = ARGS[3] === 'true';
let FRAMEWORK = ARGS[5] ?? undefined;

export async function startDebug(): Promise<number> {
const pathToAnalyse = `${process.cwd()}/src/core/mocks`;
const pathToAnalyse = `${process.cwd()}/src/core/mocks/tsx`;
FRAMEWORK = 'react';
Options.setOptions(process.cwd(), pathToAnalyse, __dirname);
if (!ENABLE_CONSOLE_REPORT) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ENABLE_MARKDOWN_REPORT = ARGS[2] === 'true';
const ENABLE_CONSOLE_REPORT = ARGS[3] === 'true';
const ENABLE_REFACTORING = ARGS[4] === 'true';
let FRAMEWORK = ARGS[5] ?? undefined;
const DEBUG = false;
const DEBUG = true;

let pathToAnalyse: string;
if (path.isAbsolute(PATH_TO_ANALYSE)) {
Expand Down
2 changes: 1 addition & 1 deletion src/json-ast-to-reports/interfaces/evaluate.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CpxFactors } from '../../core/models/cpx-factor/cpx-factors.model';
export interface Evaluate {

cpxFactors: CpxFactors; // The complexity factors of the object
cyclomaticCpx: number; // The cyclomatic complexity of the object
cyclomaticCpx?: number; // The cyclomatic complexity of the object
evaluate:() => void; // The evaluation method

}
18 changes: 18 additions & 0 deletions src/json-ast-to-reports/models/ast/ast-file.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import { DepthCpx } from '../../../core/models/cpx-factor/depth-cpx.model';
import { addObjects } from '../../../core/services/tools.service';
import { AstMethodOrOutsideNode, isAstMethod } from '../../types/ast-method-or-outside-node.type';
import { CpxLevel } from '../../enums/cpx-level.enum';
import { AstJsxComponent } from './ast-jsx.model';

export class AstFile implements AstFileInterface, Evaluate, Logg {

private _astFolder?: AstFolder = undefined; // The AstFolder which includes this AstFile
private _astJsxComponents: AstJsxComponent[];
private _astMethods?: AstMethod[] = []; // The AstMethods included in this AstFile
private _astNode?: AstNode = undefined; // The AstNode corresponding to the file itself
private _astNodes?: AstNode[] = undefined; // Array of all the AstNodes which are children of this.AstNode (including itself)
Expand Down Expand Up @@ -181,6 +183,16 @@ export class AstFile implements AstFileInterface, Evaluate, Logg {
}


get astJsxComponents(): AstJsxComponent[] {
return this._astJsxComponents;
}


set astJsxComponents(astJsxComponents: AstJsxComponent[]) {
this._astJsxComponents = astJsxComponents;
}


get name(): string {
return this._name;
}
Expand Down Expand Up @@ -226,6 +238,7 @@ export class AstFile implements AstFileInterface, Evaluate, Logg {
for (const methodOrOutsideNode of methodsAndOutsideNodes) {
this.evaluateMethodOrOutsideNode(methodOrOutsideNode);
}
this.getJsx();
}


Expand All @@ -236,6 +249,11 @@ export class AstFile implements AstFileInterface, Evaluate, Logg {
}


private getJsx(): any[] {
return [];
}


private evaluateMethodOrOutsideNode(methodOrOutsideNode: AstMethodOrOutsideNode): void {
methodOrOutsideNode.evaluate();
this.cpxFactors = this.cpxFactors.add(methodOrOutsideNode.cpxFactors);
Expand Down
Loading