From 628d38cf8bde2f8270e975a03da4278f7ecb9b44 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 26 May 2023 14:32:29 +0000 Subject: [PATCH 1/4] fix: upgrade caniuse-lite from 1.0.30001474 to 1.0.30001482 Snyk has created this PR to upgrade caniuse-lite from 1.0.30001474 to 1.0.30001482. See this package in npm: https://www.npmjs.com/package/caniuse-lite See this project in Snyk: https://app.snyk.io/org/ytetsuro/project/8de5985d-c086-4d02-a9f1-519237428819?utm_source=github&utm_medium=referral&page=upgrade-pr --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 752ed7f..032df3e 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", @@ -10037,9 +10037,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 f013bd8..bb34b0b 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", From b4eed7767fac03ab581c94fa25ae1dfe98082665 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Sun, 1 Oct 2023 14:30:08 +0000 Subject: [PATCH 2/4] fix: package.json & package-lock.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-POSTCSS-5926692 --- package-lock.json | 40 +++++++++++++++++++++++++--------------- package.json | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 752ed7f..d59a935 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "mithril": "^2.2.0", "pako": "^1.0.0", "php-parser": "^3.1.0", - "postcss": "^8.4.0", + "postcss": "^8.4.31", "postcss-import": "^14.1.0", "reflect-metadata": "^0.1.0", "tslib": "^1.14.0", @@ -6276,9 +6276,15 @@ "dev": true }, "node_modules/nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -6603,9 +6609,9 @@ } }, "node_modules/postcss": { - "version": "8.4.16", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", - "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "funding": [ { "type": "opencollective", @@ -6614,10 +6620,14 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ], "dependencies": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, @@ -12353,9 +12363,9 @@ "dev": true }, "nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==" }, "natural-compare": { "version": "1.4.0", @@ -12595,11 +12605,11 @@ } }, "postcss": { - "version": "8.4.16", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", - "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "requires": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } diff --git a/package.json b/package.json index f013bd8..c0dabf6 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "mithril": "^2.2.0", "pako": "^1.0.0", "php-parser": "^3.1.0", - "postcss": "^8.4.0", + "postcss": "^8.4.31", "postcss-import": "^14.1.0", "reflect-metadata": "^0.1.0", "tslib": "^1.14.0", From 25c5e8424316ca43da1eda4eac18aec4194418f5 Mon Sep 17 00:00:00 2001 From: Tetsuro Yoshikawa Date: Mon, 13 Nov 2023 00:50:51 +0900 Subject: [PATCH 3/4] fix: fail new when arrow function. --- src/Language/TypeScript/ASTNode.ts | 3 +++ .../TypeScript/__tests__/ASTNode.test.ts | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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()', () => { From 1cab5665b2f5bdc2b989cc2de0a5dff2e32bb897 Mon Sep 17 00:00:00 2001 From: Tetsuro Yoshikawa Date: Mon, 13 Nov 2023 00:52:33 +0900 Subject: [PATCH 4/4] fix: fail resolve DIContainer when the value is null. --- src/Reporter/JSON/MetricsCalculator.ts | 28 +++++++++++++++----------- src/index.ts | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) 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);