From bf02f21eb9dcd3217382e5986c40a96108384f07 Mon Sep 17 00:00:00 2001 From: alde Date: Mon, 19 Apr 2021 11:51:04 -0400 Subject: [PATCH] Address minor code style comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit move code out of `converter/index.ts`. change Converter to be an interface. remove unused function remove commented out import Signed-off-by: Fredrik Adelöw --- .../src/service/converter/Converter.ts | 20 +++++++++++++++++++ .../src/service/converter/cobertura.ts | 6 +++--- .../src/service/converter/index.ts | 10 +++------- .../src/service/converter/jacoco.ts | 6 +++--- .../components/FileExplorer/FileContent.tsx | 14 +------------ .../components/FileExplorer/Highlighter.ts | 7 +++---- plugins/code-coverage/src/index.ts | 2 -- 7 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 plugins/code-coverage-backend/src/service/converter/Converter.ts diff --git a/plugins/code-coverage-backend/src/service/converter/Converter.ts b/plugins/code-coverage-backend/src/service/converter/Converter.ts new file mode 100644 index 0000000000..20c6920c99 --- /dev/null +++ b/plugins/code-coverage-backend/src/service/converter/Converter.ts @@ -0,0 +1,20 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { FileEntry } from '../jsoncoverage-types'; + +export interface Converter { + convert(xml: unknown, scmFiles: Array): Array; +} diff --git a/plugins/code-coverage-backend/src/service/converter/cobertura.ts b/plugins/code-coverage-backend/src/service/converter/cobertura.ts index 72eeb25b56..fd3cfe9c01 100644 --- a/plugins/code-coverage-backend/src/service/converter/cobertura.ts +++ b/plugins/code-coverage-backend/src/service/converter/cobertura.ts @@ -16,11 +16,11 @@ import { BranchHit, FileEntry } from '../jsoncoverage-types'; import { CoberturaXML, InnerClass, LineHit } from './types'; import { Logger } from 'winston'; -import { Converter } from '.'; +import { Converter } from './Converter'; -export class Cobertura extends Converter { +export class Cobertura implements Converter { constructor(readonly logger: Logger) { - super(logger); + this.logger = logger; } /** diff --git a/plugins/code-coverage-backend/src/service/converter/index.ts b/plugins/code-coverage-backend/src/service/converter/index.ts index 083af10f68..8ea7a41f65 100644 --- a/plugins/code-coverage-backend/src/service/converter/index.ts +++ b/plugins/code-coverage-backend/src/service/converter/index.ts @@ -13,11 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Logger } from 'winston'; -import { FileEntry } from '../jsoncoverage-types'; -export abstract class Converter { - constructor(readonly logger: Logger) {} - - abstract convert(xml: any, scmFiles: Array): Array; -} +export * from './Converter'; +export { Cobertura } from './cobertura'; +export { Jacoco } from './jacoco'; diff --git a/plugins/code-coverage-backend/src/service/converter/jacoco.ts b/plugins/code-coverage-backend/src/service/converter/jacoco.ts index fe60f9378c..8dfcf0cb51 100644 --- a/plugins/code-coverage-backend/src/service/converter/jacoco.ts +++ b/plugins/code-coverage-backend/src/service/converter/jacoco.ts @@ -16,7 +16,7 @@ import { BranchHit, FileEntry } from '../jsoncoverage-types'; import { JacocoSourceFile, JacocoXML } from './types'; import { Logger } from 'winston'; -import { Converter } from '.'; +import { Converter } from './Converter'; type ParsedLine = { number: number; @@ -26,9 +26,9 @@ type ParsedLine = { covered_branches: number; }; -export class Jacoco extends Converter { +export class Jacoco implements Converter { constructor(readonly logger: Logger) { - super(logger); + this.logger = logger; } /** diff --git a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx index 7b1bc2c070..358cd72f24 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import React, { FC, useEffect } from 'react'; +import React, { FC } from 'react'; import { useApi } from '@backstage/core-api'; import { useEntity } from '@backstage/plugin-catalog-react'; import { useAsync } from 'react-use'; @@ -31,14 +31,6 @@ type Props = { coverage: FileCoverage; }; -const getContent = async (value: any) => { - let blob = value; - if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) { - blob = new Blob([value], { type: 'application/octet-stream' }); - } - return value; -}; - const useStyles = makeStyles(theme => ({ paper: { margin: 'auto', @@ -97,10 +89,6 @@ export const FileContent = ({ filename, coverage }: Props) => { ), ); - useEffect(() => { - if (value) getContent(value); - }, [value]); - const classes = useStyles(); if (loading) { diff --git a/plugins/code-coverage/src/components/FileExplorer/Highlighter.ts b/plugins/code-coverage/src/components/FileExplorer/Highlighter.ts index fda1a11f11..39f56200b6 100644 --- a/plugins/code-coverage/src/components/FileExplorer/Highlighter.ts +++ b/plugins/code-coverage/src/components/FileExplorer/Highlighter.ts @@ -20,11 +20,10 @@ import highlight from 'highlight.js'; * Given a file extension, repo name, and array of code lines, return a Promise resolving * to an array of formatted lines with html/css formatting. * - * @param {String} fileExtension The extension of the source file - * @param {String} repo The name of the code repository - * @param {Array} lines The source code lines + * @param fileExtension The extension of the source file + * @param lines The source code lines * - * @returns {Promise>} Promise of formatted lines + * @returns Promise of formatted lines * * @see http://highlightjs.readthedocs.io/en/latest/api.html#highlight-name-value-ignore-illegals-continuation */ diff --git a/plugins/code-coverage/src/index.ts b/plugins/code-coverage/src/index.ts index 84010e64ac..7542f963b5 100644 --- a/plugins/code-coverage/src/index.ts +++ b/plugins/code-coverage/src/index.ts @@ -19,5 +19,3 @@ export { isCodeCoverageAvailable, isCodeCoverageAvailable as isPluginApplicableToEntity, } from './components/Router'; - -// export { createBackendRouter } from './backend/router';