diff --git a/package-lock.json b/package-lock.json index 11265b4..ccbc5ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,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", @@ -3278,9 +3278,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001474", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001474.tgz", - "integrity": "sha512-iaIZ8gVrWfemh5DG3T9/YqarVZoYf0r188IjaGwx68j4Pf0SGY6CQkmJUIE+NZHkkecQGohzXmBGEwWDr9aM3Q==", + "version": "1.0.30001482", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001482.tgz", + "integrity": "sha512-F1ZInsg53cegyjroxLNW9DmrEQ1SuGRTO1QlpA0o2/6OpQ0gFeDRoq1yFmnr8Sakn9qwwt9DmbxHB6w167OSuQ==", "funding": [ { "type": "opencollective", @@ -10047,9 +10047,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001474", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001474.tgz", - "integrity": "sha512-iaIZ8gVrWfemh5DG3T9/YqarVZoYf0r188IjaGwx68j4Pf0SGY6CQkmJUIE+NZHkkecQGohzXmBGEwWDr9aM3Q==" + "version": "1.0.30001482", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001482.tgz", + "integrity": "sha512-F1ZInsg53cegyjroxLNW9DmrEQ1SuGRTO1QlpA0o2/6OpQ0gFeDRoq1yFmnr8Sakn9qwwt9DmbxHB6w167OSuQ==" }, "chalk": { "version": "4.1.2", diff --git a/package.json b/package.json index 35b1fa1..54d681d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Language/TypeScript/ASTNode.ts b/src/Language/TypeScript/ASTNode.ts index 75a8d33..c238f25 100644 --- a/src/Language/TypeScript/ASTNode.ts +++ b/src/Language/TypeScript/ASTNode.ts @@ -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 && (this.node).name) { return true; } diff --git a/src/Language/TypeScript/__tests__/ASTNode.test.ts b/src/Language/TypeScript/__tests__/ASTNode.test.ts index 8abfd19..fcb7e1f 100644 --- a/src/Language/TypeScript/__tests__/ASTNode.test.ts +++ b/src/Language/TypeScript/__tests__/ASTNode.test.ts @@ -14,7 +14,7 @@ describe('ASTNode', () => { }); }); - describe('.isFauxFunction()', () => { + describe('.isFauxClass()', () => { it('should checkable FauxClass structure', () => { const sourceFile = ts.createSourceFile( 'dummy.ts', @@ -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( + (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()', () => { diff --git a/src/Reporter/JSON/MetricsCalculator.ts b/src/Reporter/JSON/MetricsCalculator.ts index d7c62d3..34dc3c4 100644 --- a/src/Reporter/JSON/MetricsCalculator.ts +++ b/src/Reporter/JSON/MetricsCalculator.ts @@ -33,28 +33,32 @@ export class MetricsCalculator { .toNumber(); } - max(identity: MetricsValueConstructor): Metrics { + max(identity: MetricsValueConstructor): 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, + null ) ?? null ); } - min(identity: MetricsValueConstructor): Metrics { + min(identity: MetricsValueConstructor): 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, + null ) ?? null ); } diff --git a/src/index.ts b/src/index.ts index 2ee49a6..cfeeeeb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(Types.rootPath).toConstantValue(rootPath); - container.rebind(Types.outputPath).toConstantValue(outputPath); + container.rebind(Types.outputPath).toConstantValue(outputPath ?? ''); container.rebind(Types.fileMatches).toConstantValue(matches); container.rebind(Types.fileExcludes).toConstantValue(excludes);