Skip to content

Commit

Permalink
Merge pull request #328 from ytetsuro/develop
Browse files Browse the repository at this point in the history
dev -> master
  • Loading branch information
ytetsuro authored Nov 13, 2023
2 parents 04e0194 + 399dd34 commit 904b100
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/codemirror": "0.0.109",
"autoprefixer": "^10.4.0",
"bulma": "^0.9.0",
"caniuse-lite": "^1.0.0",
"caniuse-lite": "^1.0.30001482",
"codemirror": "^5.65.0",
"commander": "^7.2.0",
"core-js": "^3.29.1",
Expand Down
3 changes: 3 additions & 0 deletions src/Language/TypeScript/ASTNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export class ASTNode implements ASTNodeInterface {
}

private isPossibleFauxClass() {
if (this.node.kind === ts.SyntaxKind.ArrowFunction) {
return false;
}
if (this.node.kind === ts.SyntaxKind.FunctionDeclaration && (<ts.FunctionDeclaration>this.node).name) {
return true;
}
Expand Down
20 changes: 19 additions & 1 deletion src/Language/TypeScript/__tests__/ASTNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ASTNode', () => {
});
});

describe('.isFauxFunction()', () => {
describe('.isFauxClass()', () => {
it('should checkable FauxClass structure', () => {
const sourceFile = ts.createSourceFile(
'dummy.ts',
Expand All @@ -29,6 +29,24 @@ describe('ASTNode', () => {
expect(fauxClassStructure.isFauxClass()).toBe(true);
expect(notFauxClassStructure.isFauxClass()).toBe(false);
});

it('should returns false when arrow function.', () => {
const sourceFile = ts.createSourceFile(
'dummy.ts',
'const main = () => {return {hoge: () => {}}}; class A {}',
ts.ScriptTarget.ES2016,
true
);

const fauxClassStructure = new ASTNode(
(<ts.VariableStatement>sourceFile.statements[0]).declarationList.declarations[0].initializer!,
sourceFile
);
const notFauxClassStructure = new ASTNode(sourceFile.statements[1], sourceFile);

expect(fauxClassStructure.isFauxClass()).toBe(false);
expect(notFauxClassStructure.isFauxClass()).toBe(false);
});
});

describe('.isFunction()', () => {
Expand Down
28 changes: 16 additions & 12 deletions src/Reporter/JSON/MetricsCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,32 @@ export class MetricsCalculator {
.toNumber();
}

max<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics {
max<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics | null {
return (
this.metrics
.filter((metrics) => metrics.hasMetricsValue(identity))
.reduce((max, metrics) =>
Number(max?.getMetricsByMetricsValue(identity) ?? -Infinity) >
Number(metrics.getMetricsByMetricsValue(identity))
? max
: metrics
.reduce(
(max, metrics) =>
Number(max?.getMetricsByMetricsValue(identity) ?? -Infinity) >
Number(metrics.getMetricsByMetricsValue(identity))
? max
: metrics,
<Metrics | null>null
) ?? null
);
}

min<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics {
min<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics | null {
return (
this.metrics
.filter((metrics) => metrics.hasMetricsValue(identity))
.reduce((min, metrics) =>
Number(min?.getMetricsByMetricsValue(identity) ?? Infinity) <
Number(metrics.getMetricsByMetricsValue(identity))
? min
: metrics
.reduce(
(min, metrics) =>
Number(min?.getMetricsByMetricsValue(identity) ?? Infinity) <
Number(metrics.getMetricsByMetricsValue(identity))
? min
: metrics,
<Metrics | null>null
) ?? null
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Fo r HTML or CSV, specify the directory, and for JSON, specify the file.`

const rootPath = fs.statSync(analyzedTarget).isDirectory() ? analyzedTarget : dirname(analyzedTarget);
container.rebind<string>(Types.rootPath).toConstantValue(rootPath);
container.rebind<string | null>(Types.outputPath).toConstantValue(outputPath);
container.rebind<string | null>(Types.outputPath).toConstantValue(outputPath ?? '');
container.rebind<RegExp>(Types.fileMatches).toConstantValue(matches);
container.rebind<RegExp[]>(Types.fileExcludes).toConstantValue(excludes);

Expand Down

0 comments on commit 904b100

Please sign in to comment.