Skip to content

Commit 8374d66

Browse files
authored
Split standardize path into two functions (#2627)
1 parent 7779b45 commit 8374d66

File tree

8 files changed

+25
-23
lines changed

8 files changed

+25
-23
lines changed

extension/src/cli/git/executor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('GitExecutor', () => {
3939
} as unknown as EventEmitter<CliStarted>
4040
})
4141

42-
const cwd = standardizePath(__dirname) as string
42+
const cwd = standardizePath(__dirname)
4343

4444
describe('pushBranch', () => {
4545
it('should call createProcess with the correct parameters to push a branch', async () => {

extension/src/cli/git/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export class GitCli extends Cli {
77
public async getGitRepositoryRoot(cwd: string) {
88
const options = getOptions(cwd, Command.REV_PARSE, Flag.SHOW_TOPLEVEL)
99

10-
return standardizePath(await this.executeProcess(options)) as string
10+
return standardizePath(await this.executeProcess(options))
1111
}
1212
}

extension/src/experiments/columns/collect/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ export const collectParamsFiles = (
7777
): Set<string> => {
7878
const files = Object.keys(data.workspace.baseline.data?.params || {})
7979
.filter(Boolean)
80-
.map(file => standardizePath(join(dvcRoot, file))) as string[]
80+
.map(file => standardizePath(join(dvcRoot, file)))
8181
return new Set(files)
8282
}

extension/src/experiments/context.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { Event, EventEmitter, window } from 'vscode'
22
import { Disposable, Disposer } from '@hediet/std/disposable'
33
import { setContextValue } from '../vscode/context'
4-
import { standardizePath } from '../fileSystem/path'
4+
import { standardizePossiblePath } from '../fileSystem/path'
55

66
const setContextOnDidChangeParamsFiles = (
77
setActiveEditorContext: (paramsFileActive: boolean) => void,
88
onDidChangeColumns: Event<void>,
99
getParamsFiles: () => Set<string>
1010
): Disposable =>
1111
onDidChangeColumns(() => {
12-
const path = standardizePath(window.activeTextEditor?.document.fileName)
12+
const path = standardizePossiblePath(
13+
window.activeTextEditor?.document.fileName
14+
)
1315
if (!path) {
1416
return
1517
}
@@ -26,7 +28,7 @@ const setContextOnDidChangeActiveEditor = (
2628
getParamsFiles: () => Set<string>
2729
): Disposable =>
2830
window.onDidChangeActiveTextEditor(event => {
29-
const path = standardizePath(event?.document.fileName)
31+
const path = standardizePossiblePath(event?.document.fileName)
3032
if (!path) {
3133
setActiveEditorContext(false)
3234
return

extension/src/fileSystem/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const findDvcSubRootPaths = async (
3838

3939
return children
4040
.filter(child => isDirectory(join(cwd, child, '.dvc')))
41-
.map(child => standardizePath(join(cwd, child)) as string)
41+
.map(child => standardizePath(join(cwd, child)))
4242
}
4343

4444
export const findDvcRootPaths = async (cwd: string): Promise<string[]> => {
@@ -59,7 +59,7 @@ export const findAbsoluteDvcRootPath = async (
5959
return []
6060
}
6161

62-
const absoluteRoot = standardizePath(resolve(cwd, relativePath)) as string
62+
const absoluteRoot = standardizePath(resolve(cwd, relativePath))
6363

6464
return [absoluteRoot]
6565
}

extension/src/fileSystem/path.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Uri } from 'vscode'
22

3-
export const standardizePath = (path?: string): string | undefined => {
3+
export const standardizePath = (path: string): string => Uri.file(path).fsPath
4+
5+
export const standardizePossiblePath = (path?: string): string | undefined => {
46
if (!path) {
57
return
68
}
7-
return Uri.file(path).fsPath
9+
return standardizePath(path)
810
}

extension/src/repository/sourceControlManagement/decorationProvider.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ beforeEach(() => {
2525

2626
describe('DecorationProvider', () => {
2727
const dvcRoot = __dirname
28-
const model = standardizePath(join(dvcRoot, 'model.pt')) as string
29-
const dataDir = standardizePath(join(dvcRoot, 'data')) as string
30-
const features = standardizePath(join(dataDir, 'features')) as string
31-
const logDir = standardizePath(join(dvcRoot, 'logs')) as string
32-
const logAcc = standardizePath(join(logDir, 'acc.tsv')) as string
33-
const logLoss = standardizePath(join(logDir, 'loss.tsv')) as string
34-
const dataXml = standardizePath(join(dataDir, 'data.xml')) as string
35-
const dataCsv = standardizePath(join(dataDir, 'data.csv')) as string
36-
const prepared = standardizePath(join(dataDir, 'prepared')) as string
28+
const model = standardizePath(join(dvcRoot, 'model.pt'))
29+
const dataDir = standardizePath(join(dvcRoot, 'data'))
30+
const features = standardizePath(join(dataDir, 'features'))
31+
const logDir = standardizePath(join(dvcRoot, 'logs'))
32+
const logAcc = standardizePath(join(logDir, 'acc.tsv'))
33+
const logLoss = standardizePath(join(logDir, 'loss.tsv'))
34+
const dataXml = standardizePath(join(dataDir, 'data.xml'))
35+
const dataCsv = standardizePath(join(dataDir, 'data.csv'))
36+
const prepared = standardizePath(join(dataDir, 'prepared'))
3737

3838
const emptySet = new Set<string>()
3939

extension/src/test/suite/fileSystem/index.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite('File System Test Suite', () => {
2727
const root = await reader.getGitRepositoryRoot(__dirname)
2828
const submoduleDotGit = standardizePath(
2929
resolve(root, gitPath.DOT_GIT, 'modules', 'demo')
30-
) as string
30+
)
3131

3232
const dotGitPath = getGitPath(dvcDemoPath, gitPath.DOT_GIT)
3333
expect(dotGitPath).to.equal(submoduleDotGit)
@@ -39,9 +39,7 @@ suite('File System Test Suite', () => {
3939
it('should get the expected paths for this project', async () => {
4040
const reader = disposable.track(new GitReader())
4141
const root = await reader.getGitRepositoryRoot(__dirname)
42-
const rootDotGit = standardizePath(
43-
resolve(root, gitPath.DOT_GIT)
44-
) as string
42+
const rootDotGit = standardizePath(resolve(root, gitPath.DOT_GIT))
4543

4644
const dotGitPath = getGitPath(root, gitPath.DOT_GIT)
4745
expect(dotGitPath).to.equal(rootDotGit)

0 commit comments

Comments
 (0)