From f7a7fdc2afcf16541036b92e88d00d85d66406ba Mon Sep 17 00:00:00 2001 From: Jeremy Guarini Date: Thu, 21 Oct 2021 12:28:43 -0700 Subject: [PATCH] fixed prettier issues with FileExplorer files Signed-off-by: Jeremy Guarini --- .../FileExplorer/FileExplorer.test.tsx | 33 ++++++++++++++----- .../components/FileExplorer/FileExplorer.tsx | 13 ++++---- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.test.tsx b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.test.tsx index 2162c25139..ff5845edfe 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.test.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.test.tsx @@ -1,3 +1,18 @@ +/* + * Copyright 2021 The Backstage Authors + * + * 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 { groupByPath } from './FileExplorer'; const dummyFiles = [ @@ -23,8 +38,8 @@ const dummyFiles = [ coverage: 1, missing: 1, tracked: 1, - path: '' - } + path: '', + }, ]; const dummyDataGroupedByPath = { @@ -35,7 +50,7 @@ const dummyDataGroupedByPath = { coverage: 1, missing: 1, tracked: 1, - path: '' + path: '', }, { filename: 'dir1/file2', @@ -43,8 +58,8 @@ const dummyDataGroupedByPath = { coverage: 1, missing: 1, tracked: 1, - path: '' - } + path: '', + }, ], dir2: [ { @@ -53,13 +68,13 @@ const dummyDataGroupedByPath = { coverage: 1, missing: 1, tracked: 1, - path: '' - } - ] + path: '', + }, + ], }; describe('groupByPath function', () => { it('should group files by their root directory,as per their filename', () => { expect(groupByPath(dummyFiles)).toBe(dummyDataGroupedByPath); }); -}); \ No newline at end of file +}); diff --git a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx index bc36af265d..fbe74ff7e5 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx @@ -53,12 +53,10 @@ type CoverageTableRow = { export const groupByPath = (files: CoverageTableRow[]) => { const acc: FileStructureObject = {}; - files.forEach (file => { + files.forEach(file => { const filename = file.filename; if (!file.filename) return; - const pathArray = filename?.split('/').filter( - el => el !== '' - ); + const pathArray = filename?.split('/').filter(el => el !== ''); if (pathArray) { if (!acc.hasOwnProperty(pathArray[0])) { acc[pathArray[0]] = []; @@ -69,11 +67,14 @@ export const groupByPath = (files: CoverageTableRow[]) => { return acc; }; -const removeVisitedPathGroup = (files: CoverageTableRow[], pathGroup: string) => { +const removeVisitedPathGroup = ( + files: CoverageTableRow[], + pathGroup: string, +) => { return files.map(file => { return { ...file, - filename: file.filename + filename: file.filename ? file.filename.substring( file.filename?.indexOf(pathGroup) + pathGroup.length + 1, )